|
| 1 | +name: Bump Go toolchain |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + # Run daily at 05:00 UTC. |
| 6 | + - cron: "0 5 * * *" |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + version: |
| 10 | + description: > |
| 11 | + Go toolchain version to use (e.g. "go1.25.9"). |
| 12 | + If empty, the latest patch release is detected automatically. |
| 13 | + required: false |
| 14 | + |
| 15 | +permissions: |
| 16 | + contents: write |
| 17 | + pull-requests: write |
| 18 | + |
| 19 | +jobs: |
| 20 | + bump-go-toolchain: |
| 21 | + runs-on: |
| 22 | + group: databricks-protected-runner-group-large |
| 23 | + labels: linux-ubuntu-latest-large |
| 24 | + |
| 25 | + steps: |
| 26 | + - name: Checkout |
| 27 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 28 | + |
| 29 | + - name: Determine current toolchain version |
| 30 | + id: current |
| 31 | + run: | |
| 32 | + toolchain=$(grep '^toolchain' go.mod | awk '{print $2}') |
| 33 | + minor=$(echo "$toolchain" | sed 's/^go//' | cut -d. -f1,2) |
| 34 | + echo "toolchain=$toolchain" >> "$GITHUB_OUTPUT" |
| 35 | + echo "minor=$minor" >> "$GITHUB_OUTPUT" |
| 36 | +
|
| 37 | + - name: Determine latest patch release |
| 38 | + id: latest |
| 39 | + env: |
| 40 | + INPUT_VERSION: ${{ inputs.version }} |
| 41 | + run: | |
| 42 | + if [ -n "$INPUT_VERSION" ]; then |
| 43 | + if ! echo "$INPUT_VERSION" | grep -qE '^go[0-9]+\.[0-9]+\.[0-9]+$'; then |
| 44 | + echo "Invalid version format: $INPUT_VERSION" |
| 45 | + exit 1 |
| 46 | + fi |
| 47 | + toolchain="$INPUT_VERSION" |
| 48 | + else |
| 49 | + minor=${{ steps.current.outputs.minor }} |
| 50 | + toolchain=$( |
| 51 | + curl -fsSL 'https://go.dev/dl/?mode=json' | |
| 52 | + jq -r --arg minor "go${minor}." '[.[] | select(.version | startswith($minor))][0].version // empty' |
| 53 | + ) |
| 54 | + if [ -z "$toolchain" ]; then |
| 55 | + echo "No release found for go${minor}.x" |
| 56 | + exit 1 |
| 57 | + fi |
| 58 | + fi |
| 59 | + echo "toolchain=$toolchain" >> "$GITHUB_OUTPUT" |
| 60 | +
|
| 61 | + - name: Check if update is needed |
| 62 | + id: check |
| 63 | + run: | |
| 64 | + if [ "${{ steps.current.outputs.toolchain }}" = "${{ steps.latest.outputs.toolchain }}" ]; then |
| 65 | + echo "Up to date: ${{ steps.current.outputs.toolchain }}" |
| 66 | + echo "needed=false" >> "$GITHUB_OUTPUT" |
| 67 | + else |
| 68 | + echo "Update available: ${{ steps.current.outputs.toolchain }} -> ${{ steps.latest.outputs.toolchain }}" |
| 69 | + echo "needed=true" >> "$GITHUB_OUTPUT" |
| 70 | + fi |
| 71 | +
|
| 72 | + - name: Setup Go |
| 73 | + if: steps.check.outputs.needed == 'true' |
| 74 | + uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0 |
| 75 | + with: |
| 76 | + go-version-file: go.mod |
| 77 | + |
| 78 | + - name: Update go.mod files |
| 79 | + if: steps.check.outputs.needed == 'true' |
| 80 | + env: |
| 81 | + TOOLCHAIN: ${{ steps.latest.outputs.toolchain }} |
| 82 | + run: | |
| 83 | + while IFS= read -r modfile; do |
| 84 | + dir=$(dirname "$modfile") |
| 85 | + if grep -q '^toolchain' "$modfile"; then |
| 86 | + (cd "$dir" && go mod edit -toolchain="$TOOLCHAIN") |
| 87 | + fi |
| 88 | + done < <(git ls-files '**/go.mod' 'go.mod') |
| 89 | +
|
| 90 | + - name: Show diff |
| 91 | + if: steps.check.outputs.needed == 'true' |
| 92 | + run: git diff |
| 93 | + |
| 94 | + - name: Create pull request |
| 95 | + if: steps.check.outputs.needed == 'true' && inputs.version == '' |
| 96 | + uses: peter-evans/create-pull-request@c0f553fe549906ede9cf27b5156039d195d2ece0 # v8.1.0 |
| 97 | + with: |
| 98 | + branch: auto/bump-go-toolchain |
| 99 | + commit-message: "Bump Go toolchain to ${{ steps.latest.outputs.toolchain }}" |
| 100 | + title: "Bump Go toolchain to ${{ steps.latest.outputs.toolchain }}" |
| 101 | + body: | |
| 102 | + Bump Go toolchain from `${{ steps.current.outputs.toolchain }}` to `${{ steps.latest.outputs.toolchain }}`. |
| 103 | +
|
| 104 | + Release notes: https://go.dev/doc/devel/release#${{ steps.latest.outputs.toolchain }} |
| 105 | + reviewers: simonfaltum,andrewnester,anton-107,denik,janniklasrose,pietern,shreyas-goenka |
| 106 | + labels: dependencies |
0 commit comments