Skip to content
Snippets Groups Projects
Unverified Commit 5f205c7d authored by Andrew Newdigate's avatar Andrew Newdigate
Browse files

feat: add goreleaser support

parent 547540fe
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -74,3 +74,84 @@ include:
- project: 'gitlab-com/gl-infra/common-ci-tasks'
file: 'semantic-release.yml'
```
### `goreleaser`
* Default Stages: `validate`, `release`
Including this template will build a binary release of the project using [GoReleaser](https://goreleaser.com/).
It runs on tag pipelines.
It requires a `.goreleaser.yml` file in the root of the project, which looks something like this:
```
before:
hooks:
- go mod tidy
builds:
- id: "<binaryname>"
binary: "<binaryname>"
env:
- CGO_ENABLED=0
goos:
- linux
- darwin
goarch:
- amd64
- arm64
ldflags:
- -s -w -X '{{.ModulePath}}/cmd.version={{.Version}}' -X '{{.ModulePath}}/cmd.commit={{.Commit}}' -X '{{.ModulePath}}/cmd.date={{.Date}}'
archives:
- replacements:
darwin: Darwin
linux: Linux
amd64: x86_64
dockers:
- image_templates:
- "{{ .Env.CI_REGISTRY_IMAGE }}:latest"
- "{{ .Env.CI_REGISTRY_IMAGE }}:{{ .Tag }}"
- "{{ .Env.CI_REGISTRY_IMAGE }}:v{{ .Major }}"
goos: linux
goarch: amd64
release:
gitlab:
owner: gitlab-com/gl-infra # GitLab Group
name: <projectname> # GitLab Project
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ .Tag }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
gitlab_urls:
api: '{{ .Env.CI_SERVER_URL }}'
download: '{{ .Env.CI_SERVER_URL }}'
```
Next, create a [Project Access Token](https://docs.gitlab.com/ee/user/project/settings/project_access_tokens.html) with `api` and make it available in your CI environment via the `GITLAB_TOKEN` environment variable through the CI/CD Variables settings.
```yaml
stages:
- validate
- release
variables:
GL_ASDF_GORELEASER_VERSION: ...
include:
# build binary release artifacts with goreleaser
- project: 'gitlab-com/gl-infra/common-ci-tasks'
file: goreleaser.yml
```
# Requires: variable GL_ASDF_GORELEASER_VERSION
# Requires .goreleaser.yml file
# Requires stages: validate, release
goreleaser_validate:
stage: validate
needs: []
image:
name: goreleaser/goreleaser:v${GL_ASDF_GORELEASER_VERSION}
entrypoint: [""]
script: goreleaser check
goreleaser:
stage: release
image: docker:stable
services:
- docker:dind
variables:
DOCKER_REGISTRY: $CI_REGISTRY
DOCKER_USERNAME: $CI_REGISTRY_USER
DOCKER_PASSWORD: $CI_REGISTRY_PASSWORD
GIT_DEPTH: 0
rules:
# Only run this release job for tags, not every commit
- if: '$CI_COMMIT_TAG != null'
script: |
docker run --rm --privileged \
-v $PWD:$PWD \
-w $PWD \
-v /var/run/docker.sock:/var/run/docker.sock \
-e DOCKER_USERNAME -e DOCKER_PASSWORD -e DOCKER_REGISTRY \
-e GITLAB_TOKEN -e CI_REGISTRY_IMAGE \
-e CI_SERVER_URL \
goreleaser/goreleaser:v${GL_ASDF_GORELEASER_VERSION} release --rm-dist
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment