1+ name : Update Go version
2+
3+ on :
4+ schedule :
5+ - cron : ' 48 4 * * MON' # every monday at 4:48 UTC
6+ workflow_dispatch :
7+
8+ concurrency : update-go
9+
10+ jobs :
11+ update-go :
12+ name : Update go toolchain in go.mod
13+ runs-on : ubuntu-latest
14+ steps :
15+ - name : Check out code
16+ uses : actions/checkout@v4
17+ - name : Checkout PR Branch
18+ uses : initializ-buildpacks/github-config/actions/pull-request/checkout-branch@main
19+ with :
20+ branch : automations/go-mod-update/update-main
21+ - name : Setup Go
22+ id : setup-go
23+ uses : actions/setup-go@v5
24+ with :
25+ go-version : ' stable'
26+ - name : Get current go toolchain version
27+ id : current-go-version
28+ uses : initializ-buildpacks/github-config/actions/update-go-mod-version@main
29+ with :
30+ go-version : ${{ steps.setup-go.outputs.go-version }}
31+ - name : Go mod tidy
32+ run : |
33+ #!/usr/bin/env bash
34+ set -euo pipefail
35+ shopt -s inherit_errexit
36+
37+ echo "Before running go mod tidy"
38+ echo "head -n10 go.mod "
39+ head -n10 go.mod
40+
41+ echo "git diff"
42+ git diff
43+
44+ echo "Running go mod tidy"
45+ go mod tidy
46+
47+ echo "After running go mod tidy"
48+ echo "head -n10 go.mod "
49+ head -n10 go.mod
50+
51+ echo "git diff"
52+ git diff
53+ - name : Commit
54+ id : commit
55+ uses : initializ-buildpacks/github-config/actions/pull-request/create-commit@main
56+ with :
57+ message : " Updates go mod version to ${{ steps.setup-go.outputs.go-version }}"
58+ pathspec : " ."
59+ keyid : ${{ secrets.INITIALIZ_BOT_GPG_SIGNING_KEY_ID }}
60+ key : ${{ secrets.INITIALIZ_BOT_GPG_SIGNING_KEY }}
61+
62+ - name : Push Branch
63+ if : ${{ steps.commit.outputs.commit_sha != '' }}
64+ uses : initializ-buildpacks/github-config/actions/pull-request/push-branch@main
65+ with :
66+ branch : automations/go-mod-update/update-main
67+
68+ - name : Open Pull Request
69+ if : ${{ steps.commit.outputs.commit_sha != '' }}
70+ uses : initializ-buildpacks/github-config/actions/pull-request/open@main
71+ with :
72+ token : ${{ secrets.PAT }}
73+ title : " Updates go mod version to ${{ steps.setup-go.outputs.go-version }}"
74+ branch : automations/go-mod-update/update-main
75+
76+ failure :
77+ name : Alert on Failure
78+ runs-on : ubuntu-22.04
79+ needs : [update-go]
80+ if : ${{ always() && needs.update-go.result == 'failure' }}
81+ steps :
82+ - name : File Failure Alert Issue
83+ uses : initializ-buildpacks/github-config/actions/issue/file@main
84+ with :
85+ token : ${{ secrets.GITHUB_TOKEN }}
86+ repo : ${{ github.repository }}
87+ label : " failure:update-go-version"
88+ comment_if_exists : true
89+ issue_title : " Failure: Update Go Mod Version workflow"
90+ issue_body : |
91+ Update Go Mod Version workflow [failed](https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}).
92+ comment_body : |
93+ Another failure occurred: https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}
0 commit comments