Auto-patch upstream runner tags #3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Auto-patch upstream runner tags | |
| on: | |
| schedule: | |
| - cron: '0 6 * * *' # daily at 06:00 UTC | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| jobs: | |
| patch-and-tag: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repo with full history and tags | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| fetch-tags: true | |
| - name: Sync upstream tags | |
| run: | | |
| git remote add upstream https://github.com/actions/runner.git | |
| git fetch upstream 'refs/tags/*:refs/tags/upstream/*' | |
| - name: Find and patch new tags | |
| run: | | |
| git config user.name "bitrise-bot" | |
| git config user.email "[email protected]" | |
| # Save patch file outside the working tree so it survives detached checkouts | |
| PATCH_FILE="${RUNNER_TEMP}/bitrise-cache.patch" | |
| cp "${{ github.workspace }}/bitrise-cache.patch" "${PATCH_FILE}" | |
| # Collect all upstream v* tags | |
| UPSTREAM_TAGS=$(git tag -l 'upstream/v*' | sed 's|^upstream/||' | sort -V) | |
| PATCHED=0 | |
| FAILED=0 | |
| SKIPPED=0 | |
| for TAG in $UPSTREAM_TAGS; do | |
| PATCHED_TAG="${TAG}-bitrise" | |
| # Check if we already have this patched tag | |
| if git rev-parse "refs/tags/${PATCHED_TAG}" >/dev/null 2>&1; then | |
| SKIPPED=$((SKIPPED + 1)) | |
| continue | |
| fi | |
| echo "::group::Patching ${TAG} -> ${PATCHED_TAG}" | |
| # Checkout the upstream tag in a detached HEAD | |
| git checkout "upstream/${TAG}" --detach 2>&1 | |
| # Apply the Bitrise cache patch | |
| if git am --3way "${PATCH_FILE}"; then | |
| git tag "${PATCHED_TAG}" | |
| if git push origin "${PATCHED_TAG}"; then | |
| echo "Successfully tagged and pushed ${PATCHED_TAG}" | |
| PATCHED=$((PATCHED + 1)) | |
| else | |
| echo "::warning::Push failed for ${PATCHED_TAG}" | |
| FAILED=$((FAILED + 1)) | |
| fi | |
| else | |
| echo "::warning::Patch failed to apply on ${TAG} — manual intervention required" | |
| git am --abort || true | |
| FAILED=$((FAILED + 1)) | |
| fi | |
| echo "::endgroup::" | |
| done | |
| echo "" | |
| echo "=== Summary ===" | |
| echo "Patched: ${PATCHED}" | |
| echo "Skipped (already exist): ${SKIPPED}" | |
| echo "Failed: ${FAILED}" | |
| if [ "${FAILED}" -gt 0 ]; then | |
| echo "::warning::${FAILED} tag(s) failed to patch. Check the log above for details." | |
| fi |