Update ruby-build download mirror in GitHub Actions

This commit is contained in:
Mislav Marohnić 2021-07-15 20:57:14 +02:00
parent 45b3f7f7e2
commit 7f368a7592
4 changed files with 40 additions and 18 deletions

View file

@ -13,7 +13,12 @@ jobs:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- run: git clone --depth 1 https://github.com/sstephenson/bats.git
- run: PATH="./bats/bin:$PATH" script/test
- name: Install bats
run: git clone --depth 1 https://github.com/sstephenson/bats.git
- name: Run tests
run: PATH="./bats/bin:$PATH" script/test
- name: Verify download URL checksums
if: github.event_name == 'pull_request'
run: ./script/mirror verify "$COMMIT_RANGE"
env:
COMMIT_RANGE: ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }}
COMMIT_RANGE: ${{ github.event.pull_request.base.sha }}..

18
.github/workflows/mirror.yml vendored Normal file
View file

@ -0,0 +1,18 @@
name: Mirror
on: push
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Update download mirror
run: script/mirror update "${BEFORE_REF}.."
env:
BEFORE_REF: ${{ github.event.push.before }}
AMAZON_S3_BUCKET: ruby-build-mirror
AWS_ACCESS_KEY_ID: AKIAJKAUQVHU6X4CODDQ
AWS_SECRET_ACCESS_KEY: ${{ secrets.MIRROR_UPLOAD_SECRET }}

View file

@ -53,31 +53,38 @@ update() {
local url
local checksum
local file
local tmp_path
for url in $(potentially_new_packages "$1"); do
checksum="${url#*#}"
url="${url%#*}"
if test_mirrored "$checksum"; then
echo "Already mirrored: $url"
else
echo "Mirroring: $url"
file="${TMPDIR:-/tmp}/$checksum"
echo "Will mirror: $url"
[ -n "$tmp_path" ] || tmp_path="$(mktemp -d "${TMPDIR:-/tmp}/s3-sync.XXXXX")"
file="$tmp_path/$checksum"
download_and_verify "$url" "$file" "$checksum"
./script/s3-put "$file" "${AMAZON_S3_BUCKET?}"
fi
done
if [ -n "$tmp_path" ]; then
echo "Uploading..."
aws s3 sync --acl=public-read --size-only "$tmp_path" "s3://${AMAZON_S3_BUCKET?}"
fi
}
verify() {
local url
local checksum
local file
local status=0
for url in $(potentially_new_packages "$1"); do
checksum="${url#*#}"
url="${url%#*}"
echo "Verifying checksum for $url"
file="${TMPDIR:-/tmp}/$checksum"
download_and_verify "$url" "$file" "$checksum"
download_and_verify "$url" "$file" "$checksum" || status=$?
done
return $status
}
stats() {
@ -88,7 +95,7 @@ stats() {
for url in "${packages[@]}"; do
checksum="${url#*#}"
if test_mirrored "$checksum"; then
confirmed="$((confirmed + 1))"
: $((confirmed++))
else
echo "failed: $url" >&2
fi

View file

@ -1,12 +1,4 @@
#!/usr/bin/env bash
#!/bin/bash
set -e
set -x
STATUS=0
bats ${CI:+--tap} test || STATUS="$?"
if [ "$GITHUB_EVENT_NAME" = "pull_request" ]; then
./script/mirror verify "$COMMIT_RANGE"
fi
exit "$STATUS"
bats ${CI:+--tap} test