diff --git a/.github/workflows/autobump.yml b/.github/workflows/autobump.yml index 5e3ebed..7d5f2fa 100644 --- a/.github/workflows/autobump.yml +++ b/.github/workflows/autobump.yml @@ -8,7 +8,10 @@ on: - .github/workflows/autobump.yml workflow_dispatch: schedule: - - cron: "0 0,12 * * *" + # Hourly: look for new Ruby releases (the check job needs no checkout). + - cron: "17 * * * *" + # Weekly: also look for new bundled gem versions. + - cron: "47 4 * * 1" permissions: contents: write @@ -18,8 +21,68 @@ concurrency: cancel-in-progress: false jobs: + # Cheap pre-filter: compares upstream's tags with recipes/rubies.yml using + # `git ls-remote` (no API calls) and a raw file fetch, so the common + # nothing-new run needs no checkout, Ruby setup or token. + check: + runs-on: ubuntu-latest + timeout-minutes: 5 + permissions: {} + outputs: + needs_bump: ${{ steps.compare.outputs.needs_bump }} + steps: + - name: Compare upstream tags with the recipes + id: compare + env: + RECIPES_URL: https://raw.githubusercontent.com/${{ github.repository }}/${{ github.sha }}/recipes/rubies.yml + run: | + set -euo pipefail + # Every release has a tag, so the tag list is a superset of the + # release list the bump job reads: this can only over-report. + all_tags=$(git ls-remote --tags https://github.com/ruby/ruby.git \ + | sed -n 's|.*refs/tags/||p' | grep -v '\^{}$') + recipes=$(curl -fsSL --retry 3 "$RECIPES_URL" | yq '.rubies | keys | .[]') + + has_recipe() { grep -qxF -- "$1" <<< "$recipes"; } + needs_bump=false + + stable=$(grep -viE '(preview|rc)' <<< "$all_tags" | sed 's/^v//; s/_/./g' | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' || true) + series=$(grep -oE '^[0-9]+\.[0-9]+' <<< "$stable" | sort -V -u | awk -F. '$1 > 3 || ($1 == 3 && $2 >= 2)') + for minor in $series; do + latest=$(grep -E "^${minor//./\\.}\.[0-9]+$" <<< "$stable" | sort -V | tail -1) + if ! has_recipe "$latest"; then + echo "New stable Ruby: $latest" + needs_bump=true + fi + done + + while read -r tag; do + [ -n "$tag" ] || continue + if grep -q '\.' <<< "$tag"; then + version=${tag#v} + else + version=$(sed 's/^v//; s/_/./g' <<< "$tag" | sed 's/\.\(preview\)/-\1/i; s/\.\(rc\)/-\1/i') + fi + minor=$(grep -oE '^[0-9]+\.[0-9]+' <<< "$version" || true) + [ -n "$minor" ] || continue + awk -F. '$1 > 3 || ($1 == 3 && $2 >= 2) { ok = 1 } END { exit !ok }' <<< "$minor" || continue + if grep -qxE "v${minor//./_}_[0-9]+|v${minor//./\\.}\.[0-9]+" <<< "$all_tags"; then + continue + fi + if ! has_recipe "$version"; then + echo "New prerelease Ruby: $version" + needs_bump=true + fi + done < <(grep -iE '(preview|rc)' <<< "$all_tags" || true) + + echo "needs_bump=$needs_bump" >> "$GITHUB_OUTPUT" + echo "needs_bump=$needs_bump" + autobump: + needs: check + if: needs.check.outputs.needs_bump == 'true' runs-on: ubuntu-latest + timeout-minutes: 30 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: @@ -139,6 +202,24 @@ jobs: echo "No recipe changes to push" fi + bundled-gems: + # Not on the hourly schedule: gem releases are slow, and the script queries rubygems. + if: github.event.schedule != '17 * * * *' + runs-on: ubuntu-latest + timeout-minutes: 15 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + token: ${{ secrets.RELEASE_TOKEN }} + - uses: ruby/setup-ruby@v1 + with: + ruby-version: .ruby-version + + - name: Configure Git + run: | + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + - name: Bump bundled gems env: GH_TOKEN: ${{ secrets.RELEASE_TOKEN }} @@ -176,7 +257,7 @@ jobs: --body-file "$body" notify-failure: - needs: autobump + needs: [check, autobump, bundled-gems] if: ${{ failure() }} runs-on: ubuntu-latest timeout-minutes: 5 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 05f2bba..a2ba8a1 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -23,6 +23,8 @@ jobs: ruby-version: .ruby-version - name: Validate recipes run: bin/validate-recipes + - name: Test the autobump check + run: test/autobump_check_test.sh - name: Check Ruby syntax run: | ruby -c libexec/package.rb diff --git a/test/autobump_check_test.sh b/test/autobump_check_test.sh new file mode 100755 index 0000000..a139694 --- /dev/null +++ b/test/autobump_check_test.sh @@ -0,0 +1,90 @@ +#!/usr/bin/env bash +# Exercises the `check` job of .github/workflows/autobump.yml against fixtures. +# +# The job's script is extracted from the workflow, so this tests the code that +# runs in CI. `git ls-remote` and `curl` are stubbed with fixture files; `yq` +# is the real one (preinstalled on GitHub runners). The stub also emits a peeled +# (^{}) entry for every tag, as ls-remote does for annotated tags. +set -euo pipefail + +root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) +work=$(mktemp -d) +trap 'rm -rf "$work"' EXIT + +ruby -ryaml -e ' + steps = YAML.load_file(ARGV.fetch(0)).fetch("jobs").fetch("check").fetch("steps") + puts steps.find { |s| s["id"] == "compare" }.fetch("run") +' "$root/.github/workflows/autobump.yml" > "$work/check.sh" + +mkdir "$work/bin" +cat > "$work/bin/git" <<'STUB' +#!/usr/bin/env bash +[ "$1" = ls-remote ] || { echo "unexpected git $*" >&2; exit 1; } +while read -r tag; do + printf '0000000000000000000000000000000000000000\trefs/tags/%s\n' "$tag" + printf '1111111111111111111111111111111111111111\trefs/tags/%s^{}\n' "$tag" +done < "$FIXTURE_TAGS" +STUB +cat > "$work/bin/curl" <<'STUB' +#!/usr/bin/env bash +cat "$FIXTURE_RECIPES" +STUB +chmod +x "$work/bin/git" "$work/bin/curl" + +failures=0 + +# run_check NAME EXPECTED "TAGS (space separated)" "RECIPE VERSIONS (space separated)" +run_check() { + local name=$1 expected=$2 tags=$3 recipes=$4 + # shellcheck disable=SC2086 + printf '%s\n' $tags > "$work/tags" + { + echo "schema: 1" + echo "rubies:" + for v in $recipes; do echo " $v:"; echo " series: x"; done + } > "$work/recipes.yml" + : > "$work/output" + FIXTURE_TAGS="$work/tags" FIXTURE_RECIPES="$work/recipes.yml" GITHUB_OUTPUT="$work/output" \ + PATH="$work/bin:$PATH" RECIPES_URL=unused \ + bash -eo pipefail "$work/check.sh" > "$work/log" 2>&1 || { cat "$work/log"; echo "FAIL $name: script errored"; failures=$((failures + 1)); return; } + local got + got=$(sed -n 's/^needs_bump=//p' "$work/output") + if [ "$got" = "$expected" ]; then + echo "ok $name" + else + cat "$work/log" + echo "FAIL $name: expected needs_bump=$expected, got '$got'" + failures=$((failures + 1)) + fi +} + +old="v1_9_3_551 v2_7_8 v3_1_6 v3_2_0_rc1 v3_3_0_preview1" +both="v3_2_11 v3_3_13 v3_4_12 v4.0.9" + +run_check "recipes are current" false \ + "$old $both" "3.2.11 3.3.13 3.4.12 4.0.9" +run_check "new stable, underscore tag" true \ + "$old $both v3_4_13" "3.2.11 3.3.13 3.4.12 4.0.9" +run_check "new stable, dotted tag" true \ + "$old $both v4.0.10" "3.2.11 3.3.13 3.4.12 4.0.9" +run_check "only the newest stable per series is required" false \ + "$old $both" "3.2.11 3.3.13 3.4.12 4.0.9" +run_check "older patch missing, newest present" false \ + "v3_4_11 v3_4_12" "3.4.12" +run_check "series older than 3.2 are ignored" false \ + "$old v3_1_7 $both" "3.2.11 3.3.13 3.4.12 4.0.9" +run_check "new prerelease, underscore tag" true \ + "$both v4_2_0_preview1" "3.2.11 3.3.13 3.4.12 4.0.9" +run_check "new prerelease, dotted tag" true \ + "$both v4.2.0-preview1" "3.2.11 3.3.13 3.4.12 4.0.9" +run_check "new rc, underscore tag" true \ + "$both v4_2_0_rc1" "3.2.11 3.3.13 3.4.12 4.0.9" +run_check "recorded prerelease" false \ + "$both v4_2_0_preview1 v4.3.0-preview2" "3.2.11 3.3.13 3.4.12 4.0.9 4.2.0-preview1 4.3.0-preview2" +run_check "prerelease in a series that has a stable release" false \ + "$both v3_4_0_rc1 v3_4_0_preview1 v4.0.0-preview3" "3.2.11 3.3.13 3.4.12 4.0.9" + +if [ "$failures" -ne 0 ]; then + echo "$failures check(s) failed" + exit 1 +fi