From 7f368a7592022ab1856a3d4f831b3a832ab0b5bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 15 Jul 2021 20:57:14 +0200 Subject: [PATCH] Update ruby-build download mirror in GitHub Actions --- .github/workflows/ci.yml | 11 ++++++++--- .github/workflows/mirror.yml | 18 ++++++++++++++++++ script/mirror | 17 ++++++++++++----- script/test | 12 ++---------- 4 files changed, 40 insertions(+), 18 deletions(-) create mode 100644 .github/workflows/mirror.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1cd3fd4b..3a8b2b79 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 }}.. diff --git a/.github/workflows/mirror.yml b/.github/workflows/mirror.yml new file mode 100644 index 00000000..4fd75cfe --- /dev/null +++ b/.github/workflows/mirror.yml @@ -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 }} diff --git a/script/mirror b/script/mirror index cf38d251..65f5419a 100755 --- a/script/mirror +++ b/script/mirror @@ -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 diff --git a/script/test b/script/test index 8d3ff9d5..54813921 100755 --- a/script/test +++ b/script/test @@ -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