ci: read Go version from go.mod instead of hardcoding it - #48
Conversation
Replace go-version: '1.25' with go-version-file: 'go.mod' in all GitHub Actions workflows. This ensures the CI always uses the exact Go version declared in go.mod, eliminating version mismatches that cause compilation errors when go.mod is updated. https://claude.ai/code/session_01MJYZTEboQKuBBTGN79ev56
Add .github/actions/setup-and-build as a local composite action that encapsulates the three repeated steps present in every workflow: checkout, setup-go (from go.mod), and go build ./... All four workflows now reference it with a single `uses` line instead of duplicating these steps. The dependabot workflow's now-redundant manual exit-code check is also removed since `go build` already fails the step on a non-zero exit. https://claude.ai/code/session_01MJYZTEboQKuBBTGN79ev56
There was a problem hiding this comment.
Pull request overview
This PR updates GitHub Actions CI to derive the Go toolchain version from go.mod (via actions/setup-go’s go-version-file) instead of hardcoding a Go version in each workflow, reducing CI breakage when go.mod is updated.
Changes:
- Introduces a reusable composite action to checkout, set up Go from
go.mod, and rungo build ./.... - Updates multiple workflows to use the new composite action instead of duplicating checkout/setup/build steps.
- Removes the previously hardcoded Go version from those workflows.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| .github/workflows/sync-build-deploy.yml | Switches workflow to the shared setup/build composite action. |
| .github/workflows/newsletter.yml | Switches workflow to the shared setup/build composite action. |
| .github/workflows/go-build-deploy.yml | Switches workflow to the shared setup/build composite action. |
| .github/workflows/dependabot-build-check.yml | Simplifies Dependabot build check by using the shared setup/build composite action. |
| .github/actions/setup-and-build/action.yml | Adds composite action that reads Go version from go.mod and runs a build. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| steps: | ||
| - uses: actions/checkout@v6 | ||
|
|
||
| - uses: actions/setup-go@v6 | ||
| with: | ||
| go-version: '1.25' | ||
|
|
||
| - name: Build | ||
| run: go build ./... | ||
| - uses: ./.github/actions/setup-and-build | ||
|
|
There was a problem hiding this comment.
The steps list item (- uses: ./.github/actions/setup-and-build) is not indented under steps:. GitHub Actions requires the list items to be more indented than the steps: key; otherwise the workflow YAML is invalid / the job will have no steps.
| - uses: actions/setup-go@v6 | ||
| with: | ||
| go-version-file: 'go.mod' | ||
| cache: true | ||
|
|
There was a problem hiding this comment.
This composite action enables cache: true for actions/setup-go. Some workflows in this PR set job-level permissions: (e.g., contents: read/write), which can implicitly drop the actions scope; that can prevent the cache from being saved/restored and cause the job to fail with permission errors. Consider either (a) making caching configurable via an input (default off), or (b) updating the affected workflows’ permissions to include the minimum required actions: read/actions: write for caching.
| steps: | ||
| - uses: actions/checkout@v6 | ||
|
|
||
| - uses: actions/setup-go@v6 | ||
| with: | ||
| go-version: '1.25' | ||
| cache: true | ||
|
|
||
| - name: Build | ||
| run: go build ./... | ||
| - uses: ./.github/actions/setup-and-build | ||
|
|
There was a problem hiding this comment.
In GitHub Actions YAML, list items under steps: must be indented more than the steps: key. Here - uses: ./.github/actions/setup-and-build is aligned with steps:, which makes the workflow invalid YAML (the step won’t be part of steps). Indent the - uses line (and the rest of the steps list, if needed) under steps:.
| steps: | ||
| - uses: actions/checkout@v6 | ||
|
|
||
| - uses: actions/setup-go@v6 | ||
| with: | ||
| go-version: '1.25' | ||
|
|
||
| - name: Build | ||
| run: go build ./... | ||
| - uses: ./.github/actions/setup-and-build | ||
|
|
There was a problem hiding this comment.
The - uses: ./.github/actions/setup-and-build line needs to be indented under steps: (list items must be more indented than their parent key). As written, it’s aligned with steps:, which makes the workflow YAML invalid / the step not included in the job’s steps.
Replace go-version: '1.25' with go-version-file: 'go.mod' in all
GitHub Actions workflows. This ensures the CI always uses the exact
Go version declared in go.mod, eliminating version mismatches that
cause compilation errors when go.mod is updated.
https://claude.ai/code/session_01MJYZTEboQKuBBTGN79ev56