Starter workflows for Go projects are compact, with just a few steps to check out code, set up Go for a specific version, and then run commonly used go commands to build the project and run tests.
But you can tune up the suggested workflow by customizing setup steps and adding additional CI capabilities.
| Reference | Description |
|---|---|
| actions/setup-go on GitHub Marketplace | GitHub Action for setting up Go environments |
| Revive linter for Go on GitHub Marketplace | GitHub Action for running the Revive linter for Go code |
| actions/checkout on GitHub Marketplace | GitHub Action for checking out repository code |
| Documentation for the Go project used for this lesson | Documentation for the Go project used in this lesson |
| The updated workflow for this lesson | The complete workflow file for this lesson |
In this lab, you’ll create and run a starter GitHub Actions workflow for a Go project. You’ll diagnose a workflow failure caused by a Go version mismatch, update the workflow to use the project’s go.mod file, and extend the pipeline by adding a Go linter.
By the end of this lab, you’ll understand how starter workflows work, how Go versions are configured in GitHub Actions, and how to make your workflow more resilient and maintainable.
Before starting this lab, make sure you have:
- A new GitHub repository
- The Go project files from this lesson committed to the repository
- Open your repository in GitHub.
- Select the Actions tab.
- Review the suggested workflows.
- Locate the starter workflow "Go by GitHub Actions.".
- Select Configure.
GitHub creates a starter workflow that includes steps to:
- Check out the repository
- Set up Go
- Run
go build ... - Run
go test ...
Note how the workflow uses a hard-coded Go version.
- Select Commit changes.
- Commit the workflow to the
mainbranch.
Because the workflow is configured to run on pushes to main, committing the file automatically starts a workflow run.
- Return to the Actions tab.
- Select the last workflow run.
- Wait for the job to complete.
- Notice that the workflow fails.
- Open the failed job and review the logs.
You’ll see an error indicating that a Go package is not available in the configured Go version. A follow-up log entry explains the real issue: a dependency requires Go 1.25, but the workflow is using Go 1.20.
This mismatch causes the build to fail.
Tip
As the starter workflow changes over time, different versions may be used or the workflow may run successfully. In either case, please continue with the lab as the remaining steps still apply.
Configure the workflow to read the Go version directly from the project’s go.mod file.
-
Open the workflow file for editing.
-
While you're updating the workflow file, update the action versions:
- Change
actions/checkoutto the latest major version. - Change
actions/setup-goto the latest major version.
- Change
-
In the Set up Go step:
- Replace
go-versionwithgo-version-file. - Replace the hard-coded version value with
go.mod.
- Replace
Using go-version-file ensures the workflow always uses the Go version required by the project, even if that version changes later.
Next, you’ll extend the workflow with a linter.
-
Locate the search bar labeled Search Marketplace for Actions.
-
Search for Revive.
-
Select the Revive action from the results.
-
Copy the installation snippet.
-
Paste the step into your workflow after the Set up Go step.
-
Clean up the pasted code:
- Fix formatting
- Remove optional parameters
- Remove the entire
with:block
This adds automated linting for Go code to your CI pipeline.
- Select Commit changes.
- Commit the updated workflow to the
mainbranch. - Return to the Actions tab.
- Wait for the workflow run to complete.
Wait for the workflow to complete.
- Open the successful workflow run.
- Review the summary page.
- Notice the Revive linting summary.
- Open the build job.
- Expand the Set up Go step.
You should see that the Go version was automatically set to 1.25, pulled directly from the go.mod file.
This confirms that the workflow is now aligned with the project’s dependencies and can adapt to future version changes.
This approach keeps your CI pipeline reliable, future-proof, and easier to maintain as your Go projects evolve.
← 01_03 Set Up CI for Python | 01_05 Challenge: Build a CI Workflow for a Python Project →