|
| 1 | +name: Check Actions Runner Updates |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + # Run every Monday at 9 AM UTC |
| 6 | + - cron: "0 9 * * 1" |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +env: |
| 10 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 11 | + |
| 12 | +jobs: |
| 13 | + check-updates: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + permissions: |
| 16 | + contents: write |
| 17 | + pull-requests: write |
| 18 | + issues: write |
| 19 | + env: |
| 20 | + SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} |
| 21 | + |
| 22 | + steps: |
| 23 | + - name: Checkout repository |
| 24 | + uses: actions/checkout@v4 |
| 25 | + with: |
| 26 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 27 | + ref: ${{ github.ref }} |
| 28 | + |
| 29 | + - name: Get current runner version from Dockerfile |
| 30 | + id: current-version |
| 31 | + run: | |
| 32 | + CURRENT_VERSION=$(grep -o 'ghcr.io/actions/actions-runner:[0-9]\+\.[0-9]\+\.[0-9]\+' Dockerfile | sed 's/ghcr.io\/actions\/actions-runner://') |
| 33 | + echo "current=$CURRENT_VERSION" >> $GITHUB_OUTPUT |
| 34 | + echo "Current version: $CURRENT_VERSION" |
| 35 | +
|
| 36 | + - name: Get latest runner version from GitHub API |
| 37 | + id: latest-version |
| 38 | + run: | |
| 39 | + # Get the latest version from GitHub Container Registry API |
| 40 | + LATEST_VERSION=$(curl -H "Authorization: token $GITHUB_TOKEN" "https://api.github.com/orgs/actions/packages/container/actions-runner/versions" \ |
| 41 | + | grep -o '"[0-9]\+\.[0-9]\+\.[0-9]\+"' | tr -d '"' | sort -r | head -n 1) |
| 42 | +
|
| 43 | + echo "latest=$LATEST_VERSION" >> $GITHUB_OUTPUT |
| 44 | + echo "Latest version: $LATEST_VERSION" |
| 45 | +
|
| 46 | + - name: Compare versions |
| 47 | + id: compare-versions |
| 48 | + run: | |
| 49 | + CURRENT="${{ steps.current-version.outputs.current }}" |
| 50 | + LATEST="${{ steps.latest-version.outputs.latest }}" |
| 51 | +
|
| 52 | + echo "Comparing: $CURRENT vs $LATEST" |
| 53 | +
|
| 54 | + # Use sort -V for version comparison |
| 55 | + if [ "$(printf '%s\n' "$CURRENT" "$LATEST" | sort -V | head -1)" != "$LATEST" ]; then |
| 56 | + echo "update_needed=true" >> $GITHUB_OUTPUT |
| 57 | + echo "Update needed: $CURRENT -> $LATEST" |
| 58 | + else |
| 59 | + echo "update_needed=false" >> $GITHUB_OUTPUT |
| 60 | + echo "No update needed. Current version is up to date." |
| 61 | + fi |
| 62 | +
|
| 63 | + - name: Update Dockerfile |
| 64 | + if: steps.compare-versions.outputs.update_needed == 'true' |
| 65 | + run: | |
| 66 | + # Update the Dockerfile with the new version |
| 67 | + sed -i "s/ghcr.io\/actions\/actions-runner:[0-9]\+\.[0-9]\+\.[0-9]\+/ghcr.io\/actions\/actions-runner:${{ steps.latest-version.outputs.latest }}/" Dockerfile |
| 68 | + echo "Updated Dockerfile with new version: ${{ steps.latest-version.outputs.latest }}" |
| 69 | +
|
| 70 | + - name: Create Pull Request |
| 71 | + if: steps.compare-versions.outputs.update_needed == 'true' |
| 72 | + id: create-pr |
| 73 | + uses: peter-evans/create-pull-request@v5 |
| 74 | + with: |
| 75 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 76 | + commit-message: "chore: update actions-runner to ${{ steps.latest-version.outputs.latest }}" |
| 77 | + title: "Update Actions Runner to ${{ steps.latest-version.outputs.latest }}" |
| 78 | + base: "master" |
| 79 | + body: | |
| 80 | + ## 🚀 Actions Runner Update |
| 81 | +
|
| 82 | + This PR updates the GitHub Actions runner from `${{ steps.current-version.outputs.current }}` to `${{ steps.latest-version.outputs.latest }}`. |
| 83 | +
|
| 84 | + ### Changes |
| 85 | + - Updated Dockerfile base image from `ghcr.io/actions/actions-runner:${{ steps.current-version.outputs.current }}` to `ghcr.io/actions/actions-runner:${{ steps.latest-version.outputs.latest }}` |
| 86 | +
|
| 87 | + --- |
| 88 | + *This PR was automatically created by the [Check Actions Runner Updates](.github/workflows/check-runner-updates.yml) workflow.* |
| 89 | + branch: update-actions-runner-${{ steps.latest-version.outputs.latest }} |
| 90 | + delete-branch: true |
| 91 | + |
| 92 | + - name: Send Slack Notification |
| 93 | + if: steps.compare-versions.outputs.update_needed == 'true' && env.SLACK_BOT_TOKEN != '' |
| 94 | + uses: slackapi/slack-github-action@v2.1.1 |
| 95 | + with: |
| 96 | + errors: true |
| 97 | + method: chat.postMessage |
| 98 | + token: ${{ secrets.SLACK_BOT_TOKEN }} |
| 99 | + payload: | |
| 100 | + { |
| 101 | + "channel": "C036AH93SPL", |
| 102 | + "text": "🚀 *Actions Runner Update Available*\n\nA new GitHub Actions runner version has been detected and a PR has been created:\n\n• *Current Version:* `${{ steps.current-version.outputs.current }}`\n• *Latest Version:* `${{ steps.latest-version.outputs.latest }}`\n• *Pull Request:* <https://github.com/${{ github.repository }}/pull/${{ steps.create-pr.outputs.pull-request-number }}|View PR>\n\nPlease review and merge the PR when ready." |
| 103 | + } |
| 104 | +
|
| 105 | + - name: Send Slack Notification (No Updates) |
| 106 | + if: steps.compare-versions.outputs.update_needed == 'false' && env.SLACK_BOT_TOKEN != '' |
| 107 | + uses: slackapi/slack-github-action@v2.1.1 |
| 108 | + with: |
| 109 | + errors: true |
| 110 | + method: chat.postMessage |
| 111 | + token: ${{ secrets.SLACK_BOT_TOKEN }} |
| 112 | + payload: | |
| 113 | + { |
| 114 | + "channel": "C036AH93SPL", |
| 115 | + "text": "✅ *Actions Runner Check Complete*\n\nNo updates needed. Current version `${{ steps.current-version.outputs.current }}` is up to date." |
| 116 | + } |
0 commit comments