|
| 1 | +name: update-cloudflared-version |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: '17 */6 * * *' |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + pull-requests: write |
| 11 | + |
| 12 | +jobs: |
| 13 | + update-version: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + steps: |
| 16 | + - name: Checkout |
| 17 | + uses: actions/checkout@v4 |
| 18 | + |
| 19 | + - name: Resolve latest cloudflared release tag |
| 20 | + id: release |
| 21 | + uses: actions/github-script@v7 |
| 22 | + with: |
| 23 | + script: | |
| 24 | + const release = await github.rest.repos.getLatestRelease({ |
| 25 | + owner: 'cloudflare', |
| 26 | + repo: 'cloudflared' |
| 27 | + }); |
| 28 | +
|
| 29 | + if (!release?.data?.tag_name) { |
| 30 | + core.setFailed('Failed to resolve cloudflared release tag'); |
| 31 | + return; |
| 32 | + } |
| 33 | +
|
| 34 | + core.setOutput('latest_tag', release.data.tag_name); |
| 35 | +
|
| 36 | + - name: Update CLOUDFLARED_VERSION in docker-bake.hcl |
| 37 | + id: update |
| 38 | + env: |
| 39 | + LATEST_TAG: ${{ steps.release.outputs.latest_tag }} |
| 40 | + run: | |
| 41 | + set -euo pipefail |
| 42 | + current_version="$(awk ' |
| 43 | + BEGIN { in_block = 0 } |
| 44 | + /^variable "CLOUDFLARED_VERSION" \{/ { in_block = 1; next } |
| 45 | + in_block && /^[[:space:]]*default = "/ { |
| 46 | + gsub(/^[[:space:]]*default = "/, "") |
| 47 | + gsub(/"$/, "") |
| 48 | + print |
| 49 | + exit |
| 50 | + } |
| 51 | + ' docker-bake.hcl)" |
| 52 | +
|
| 53 | + if [ -z "$current_version" ]; then |
| 54 | + echo "Unable to parse current CLOUDFLARED_VERSION from docker-bake.hcl" |
| 55 | + exit 1 |
| 56 | + fi |
| 57 | +
|
| 58 | + if [ "$current_version" = "$LATEST_TAG" ]; then |
| 59 | + echo "No update needed. Already at $current_version" |
| 60 | + echo "changed=false" >> "$GITHUB_OUTPUT" |
| 61 | + exit 0 |
| 62 | + fi |
| 63 | +
|
| 64 | + awk -v latest="$LATEST_TAG" ' |
| 65 | + BEGIN { in_block = 0 } |
| 66 | + /^variable "CLOUDFLARED_VERSION" \{/ { in_block = 1 } |
| 67 | + in_block && /^[[:space:]]*default = "/ { |
| 68 | + sub(/"[^"]+"/, "\"" latest "\"") |
| 69 | + in_block = 0 |
| 70 | + } |
| 71 | + { print } |
| 72 | + ' docker-bake.hcl > docker-bake.hcl.tmp |
| 73 | +
|
| 74 | + mv docker-bake.hcl.tmp docker-bake.hcl |
| 75 | +
|
| 76 | + echo "changed=true" >> "$GITHUB_OUTPUT" |
| 77 | + echo "current_version=$current_version" >> "$GITHUB_OUTPUT" |
| 78 | + echo "new_version=$LATEST_TAG" >> "$GITHUB_OUTPUT" |
| 79 | +
|
| 80 | + - name: Create pull request |
| 81 | + if: steps.update.outputs.changed == 'true' |
| 82 | + uses: peter-evans/create-pull-request@v6 |
| 83 | + with: |
| 84 | + branch: chore/update-cloudflared-${{ steps.update.outputs.new_version }} |
| 85 | + commit-message: "chore: update cloudflared to ${{ steps.update.outputs.new_version }}" |
| 86 | + title: "chore: update cloudflared to ${{ steps.update.outputs.new_version }}" |
| 87 | + body: | |
| 88 | + Automated update of `CLOUDFLARED_VERSION` in `docker-bake.hcl`. |
| 89 | +
|
| 90 | + - Previous version: `${{ steps.update.outputs.current_version }}` |
| 91 | + - New version: `${{ steps.update.outputs.new_version }}` |
| 92 | +
|
| 93 | + Source: `cloudflare/cloudflared` latest GitHub release tag. |
0 commit comments