1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
workflow:
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_PIPELINE_SOURCE == "schedule"
- if: $CI_COMMIT_TAG
- if: $CI_COMMIT_REF_PROTECTED == "true"
include:
- component: ${CI_SERVER_FQDN}/gitlab-org/components/danger-review/danger-review@2.0.0
inputs:
job_stage: lint
job_allow_failure: true
stages:
- lint
- test
- deploy
.go:versions:
parallel:
matrix:
- GOLANG_IMAGE_VERSION:
- '1.22'
- '1.23'
- '1.24'
.go:base:
# From: https://docs.gitlab.com/ee/ci/caching/#cache-go-dependencies
variables:
GOPATH: $CI_PROJECT_DIR/.go
GOLANGCI_LINT_CACHE: $CI_PROJECT_DIR/.golangci-lint
before_script:
- mkdir -p "${GOPATH}" "${GOLANGCI_LINT_CACHE}"
cache:
paths:
- $GOPATH/pkg/mod/
- $GOLANGCI_LINT_CACHE/
key:
files:
- go.sum
# We want to speed up CI a bit.
# Community contributors are recommended to use the Community fork
# which has access to this runners.
# For other forks to free tier namespaces this might fail,
# which is a good reminder to use the Community fork and not
# to accidentally burn to personal compute minutes.
tags:
- saas-linux-large-amd64
# We only need to run Go-related jobs when actual Go files changed
# or when running either on the default branch or for a tag.
rules:
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
- if: $CI_COMMIT_TAG
- changes:
- '**/*.go'
- testdata/**
- go.mod
- go.sum
- .gitlab-ci.yml
golangci-lint:
extends:
- .go:base
stage: lint
needs: []
variables:
REPORT_FILENAME: 'gl-code-quality-report.json'
image: golangci/golangci-lint:v1.64.5
script:
- golangci-lint run --print-issued-lines=false --out-format code-climate:$REPORT_FILENAME,line-number
artifacts:
reports:
codequality: $REPORT_FILENAME
paths: [$REPORT_FILENAME]
when: always
tests:unit:
extends:
- .go:base
- .go:versions
stage: test
needs: []
image: golang:$GOLANG_IMAGE_VERSION
variables:
# configure tooling versions
GOTESTSUM_VERSION: 'v1.12.0'
GOCOVER_COBERTURA_VERSION: 'v1.2.1-0.20240107185409-0818f3538137'
# configure artifact files
JUNIT_FILENAME: tests.xml
COVERPROFILE_FILENAME: coverage.out
COVERPROFILE_XML_FILENAME: coverage.xml
script:
- go run gotest.tools/gotestsum@${GOTESTSUM_VERSION} --format=standard-quiet --junitfile=$JUNIT_FILENAME -- -race -coverprofile=$COVERPROFILE_FILENAME -covermode=atomic ./...
- go run github.com/boumenot/gocover-cobertura@${GOCOVER_COBERTURA_VERSION} < $COVERPROFILE_FILENAME > $COVERPROFILE_XML_FILENAME
- go tool cover -func $COVERPROFILE_FILENAME
coverage: '/total:.+\(statements\).+\d+\.\d+/'
artifacts:
paths:
- $JUNIT_FILENAME
- $COVERPROFILE_XML_FILENAME
reports:
junit: $JUNIT_FILENAME
coverage_report:
path: $COVERPROFILE_XML_FILENAME
coverage_format: cobertura
when: always
generate-release-notes:
stage: deploy
needs: []
image: alpine:3.21.2
before_script:
- apk add --update jq curl git
script:
- |
if [ -z "$CI_COMMIT_TAG" ]; then
last_stable_version_sha="$(git tag | grep -E '^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$' | sort -Vr | head -n1)"
version="${last_stable_version_sha}+${CI_COMMIT_SHA}"
else
version="$CI_COMMIT_TAG"
fi
urlencoded_version="$(jq -rn --arg x "${version}" '$x|@uri')"
- echo "Generating release notes for ${version} (urlencoded=${urlencoded_version}) ..."
- 'curl --fail-with-body --header "JOB-TOKEN: $CI_JOB_TOKEN" "$CI_API_V4_URL/projects/$CI_PROJECT_ID/repository/changelog?version=${urlencoded_version}" | jq -r .notes > release-notes.md'
- cat release-notes.md
artifacts:
paths:
- release-notes.md
release:
stage: deploy
rules:
- if: $CI_COMMIT_TAG
needs:
- golangci-lint
- tests:unit
- job: generate-release-notes
artifacts: true
image: registry.gitlab.com/gitlab-org/release-cli:latest
script:
- echo "Create release for $CI_COMMIT_TAG"
release:
tag_name: '$CI_COMMIT_TAG'
tag_message: 'Version $CI_COMMIT_TAG'
name: '$CI_COMMIT_TAG'
description: release-notes.md
|