Skip to content

jandelgado/golang-ci-template-github-actions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

golang ci template using github actions

Build Status Coverage Status Go Report Card

Info

This repository serves as a template for github-actions integrated go projects. It consists of a hello, world! like example in source file main.go which gets compiled into the binary my-app using goreleaser. The CI is configured to run golangci-linter on the code, before the unit tests are executed. Test coverage is uploaded to coveralls.io.

goreleaser is used to create the final multi-plattform assets, which are automatically uploaded to the release. The release-process is triggered by pushing a git tag to the repository.

Finally, a docker image is built, which gets published to ghcr.io. Run it with

$ docker run --rm  ghcr.io/jandelgado/my-app:latest
hello, world!

Go-Version

The go version to use is configured in go.mod with the toolchain directive. When building locally, set GOTOOLCHAIN to auto to automatically install the configured toolchain (introduced with go 1.21).

Dependabot

We use dependabot to both keep the go dependencies as well as the used github action up-to-date. The configuration can be found here.

Creating a release

A new release is created by creating a git tag and pushing it, e.g.:

$ git tag -a "v1.2.3" -m "this is release v1.2.3"
$ git push origin v1.2.3

The push of the new tag triggers the CI, which uses goreleaser with this configuration to

  • build multi-platform release artifacts
  • create a new release
  • upload the artifacts, which are then available on the releases page.

Finally, a docker image is built using the previously built artefacts. The image is published to ghcr.io.

To run goreleaser locally, start the tool with gorelaser build --snapshot --clean.

Linting & Test

Linter

golangci-linter is configured for code-linting. The report is uploaded so that linting results are visible in the MR:

pr screenshot

Test

We use the coveralls-github-action to upload the golang coverage to coveralls.

Don't forget to enable Leave comments (x) in coveralls, under repo settings > pull request alerts, so that the coveralls-action posts a comment with the test coverage to affected pull requests:

pr screenshot

Author

(c) copyright 2021-2025 by Jan Delgado, License MIT