|
| 1 | +name: Upgrade Go Version |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + schedule: |
| 6 | + - cron: "0 8 * * 1" |
| 7 | + |
| 8 | +jobs: |
| 9 | + upgrade-go: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + permissions: |
| 12 | + contents: write |
| 13 | + pull-requests: write |
| 14 | + steps: |
| 15 | + - uses: actions/checkout@v6 |
| 16 | + |
| 17 | + - name: Create token |
| 18 | + id: app-token |
| 19 | + uses: actions/create-github-app-token@v2 |
| 20 | + with: |
| 21 | + app-id: ${{ vars.APP_ID }} |
| 22 | + private-key: ${{ secrets.APP_PRIVATE_KEY }} |
| 23 | + owner: ${{ github.repository_owner }} |
| 24 | + |
| 25 | + - name: Check for Go updates |
| 26 | + id: check |
| 27 | + run: | |
| 28 | + CURRENT=$(grep "^go " go.mod | awk '{print $2}') |
| 29 | + LATEST=$(go list -m -f '{{.Version}}' go@latest) |
| 30 | + { |
| 31 | + echo "latest=$LATEST" |
| 32 | + echo "needs_update=false" |
| 33 | + [ "$CURRENT" != "$LATEST" ] && echo "needs_update=true" || true |
| 34 | + } >> $GITHUB_OUTPUT |
| 35 | +
|
| 36 | + - name: Update Go version |
| 37 | + if: steps.check.outputs.needs_update == 'true' |
| 38 | + env: |
| 39 | + GO_VERSION: ${{ steps.check.outputs.latest }} |
| 40 | + run: | |
| 41 | + go mod edit -go=$GO_VERSION |
| 42 | + go mod tidy |
| 43 | + { |
| 44 | + grep -v "^golang " .tool-versions || true |
| 45 | + echo "golang $GO_VERSION" |
| 46 | + } > .tool-versions.tmp |
| 47 | + mv .tool-versions.tmp .tool-versions |
| 48 | +
|
| 49 | + - name: Create Pull Request |
| 50 | + if: steps.check.outputs.needs_update == 'true' |
| 51 | + uses: peter-evans/create-pull-request@v8 |
| 52 | + with: |
| 53 | + author: crd-automation[bot] <crd-automation[bot]@users.noreply.github.com> |
| 54 | + title: "chore: upgrade Go to ${{ steps.check.outputs.latest }}" |
| 55 | + commit-message: "chore: upgrade Go to ${{ steps.check.outputs.latest }}" |
| 56 | + branch: chore/upgrade-go-${{ steps.check.outputs.latest }} |
| 57 | + add-paths: | |
| 58 | + .tool-versions |
| 59 | + go.mod |
| 60 | + go.sum |
| 61 | + labels: go |
| 62 | + token: ${{ steps.app-token.outputs.token }} |
0 commit comments