|
| 1 | +# Copyright Crunchy Data Solutions, Inc. All rights reserved. |
| 2 | +# |
| 3 | +# schema-documentation: https://docs.gitlab.com/ci/yaml |
| 4 | +# yaml-language-server: $schema=https://gitlab.com/gitlab-org/gitlab/-/raw/master/app/assets/javascripts/editor/schema/ci.json |
| 5 | + |
| 6 | +spec: |
| 7 | + inputs: |
| 8 | + |
| 9 | + # https://go.dev/doc/install/source#environment |
| 10 | + architectures: |
| 11 | + type: array |
| 12 | + default: ['amd64','arm64'] |
| 13 | + description: > |
| 14 | + The CPU architectures on which to run tests |
| 15 | +
|
| 16 | + # TODO(retention): We can increase the retention on scheduled pipelines after |
| 17 | + # https://gitlab.com/groups/gitlab-org/-/epics/16321 |
| 18 | + retention: |
| 19 | + type: string |
| 20 | + default: 2d # Enough time to find and address MR failures the following day |
| 21 | + description: > |
| 22 | + How long to keep reports; see https://docs.gitlab.com/ci/yaml#artifactsexpire_in |
| 23 | +--- |
| 24 | + |
| 25 | +# https://docs.gitlab.com/ci/yaml/workflow |
| 26 | +workflow: |
| 27 | + rules: |
| 28 | + - if: >- |
| 29 | + ($CI_PIPELINE_SOURCE == "merge_request_event") || |
| 30 | + ($CI_PIPELINE_SOURCE == "schedule") || |
| 31 | + ($CI_PIPELINE_SOURCE == "web") |
| 32 | +
|
| 33 | +variables: |
| 34 | + # https://docs.gitlab.com/runner/configuration/feature-flags |
| 35 | + # Show the duration of individual script items in the job log. |
| 36 | + FF_SCRIPT_SECTIONS: 'true' |
| 37 | + |
| 38 | +# See: [.github/workflows/lint.yaml] |
| 39 | +# This uses a specific minor version of golangci-lint to ensure new code conforms |
| 40 | +# to the rules we set when this release branch was cut. We do not want new rules |
| 41 | +# suggesting sweeping changes to our release branches. |
| 42 | +# |
| 43 | +# NOTE(2025-04): Some versions of golangci-lint eat memory until they are killed by Linux. |
| 44 | +# > Ops Team: |
| 45 | +# > this container was hanging around even after the ci job died |
| 46 | +# > `golangci-lint run` was using ~240GB of RAM and caused the system to swap |
| 47 | +# |
| 48 | +# | | go1.21.13 | go1.22.12 | go1.23.8 | go1.24.2 | |
| 49 | +# | [email protected] | typecheck | typecheck | panic | typecheck | |
| 50 | +# | [email protected] | typecheck | typecheck | panic | typecheck | |
| 51 | +# | [email protected] | killed | killed | panic | typecheck | |
| 52 | +# | [email protected] | killed | killed | panic | typecheck | |
| 53 | +# | [email protected] | killed | killed | panic | typecheck | |
| 54 | +# | [email protected] | killed | killed | panic | typecheck | |
| 55 | +# | [email protected] | go1.22.1 | go1.23.0 | pass | typecheck | |
| 56 | +# | [email protected] | go1.22.1 | go1.23.0 | pass | typecheck | |
| 57 | +# | [email protected] | go1.22.1 | go1.23.0 | pass | recvcheck | |
| 58 | +# | [email protected] | go1.22.1 | go1.23.0 | pass | recvcheck | |
| 59 | +# | [email protected] | go1.23.0 | go1.23.0 | pass | recvcheck | |
| 60 | +golang-lint: |
| 61 | + stage: build |
| 62 | + needs: [] |
| 63 | + tags: ['image=container'] |
| 64 | + image: '${CI_REGISTRY}/containers/gitlab/go-toolset-ubi8' |
| 65 | + script: |
| 66 | + # Help Git understand the file permissions here. |
| 67 | + # > fatal: detected dubious ownership in repository |
| 68 | + - git config --global --add safe.directory "$(pwd)" |
| 69 | + |
| 70 | + # Download golangci-lint and log its version. |
| 71 | + - |- |
| 72 | + TOOL='github.com/golangci/golangci-lint/cmd/[email protected]' |
| 73 | + go run "${TOOL}" version |
| 74 | +
|
| 75 | + # Produce a report for the GitLab UI. This only fails when the tool crashes. |
| 76 | + - >- |
| 77 | + go run "${TOOL}" run --disable recvcheck |
| 78 | + --concurrency 2 |
| 79 | + --timeout 5m |
| 80 | + --issues-exit-code 0 |
| 81 | + --max-issues-per-linter 0 |
| 82 | + --max-same-issues 0 |
| 83 | + --out-format junit-xml-extended > golangci-lint.junit.xml |
| 84 | +
|
| 85 | + # Fail the job if there are any issues found and print a handful to the log. |
| 86 | + - >- |
| 87 | + go run "${TOOL}" run --disable recvcheck |
| 88 | + --concurrency 2 |
| 89 | + --timeout 5m |
| 90 | + --verbose |
| 91 | +
|
| 92 | + # Send the report to GitLab. |
| 93 | + artifacts: |
| 94 | + expire_in: '$[[ inputs.retention ]]' |
| 95 | + reports: |
| 96 | + junit: golangci-lint.junit.xml |
| 97 | + |
| 98 | +# See: [.github/workflows/test.yaml] |
| 99 | +# This uses an old version of Go because the generation tools require it. |
| 100 | +must-commit-generated: |
| 101 | + stage: build |
| 102 | + needs: [] |
| 103 | + tags: ['image=container'] |
| 104 | + image: '${CI_REGISTRY}/containers/gitlab/go-toolset-ubi8' |
| 105 | + variables: |
| 106 | + GOTOOLCHAIN: go1.23.8+auto |
| 107 | + script: |
| 108 | + # Help Git understand the file permissions here. |
| 109 | + # > fatal: detected dubious ownership in repository |
| 110 | + - git config --global --add safe.directory "$(pwd)" |
| 111 | + - make check-generate |
| 112 | + |
| 113 | +# See: [.github/workflows/test.yaml] |
| 114 | +# This uses the latest version of Go we have internally. |
| 115 | +go-test: |
| 116 | + stage: test |
| 117 | + needs: |
| 118 | + - job: must-commit-generated |
| 119 | + tags: ['image=container','cpu=${TARGET_ARCHITECTURE}'] |
| 120 | + image: '${CI_REGISTRY}/containers/gitlab/go-toolset-ubi8' |
| 121 | + parallel: |
| 122 | + matrix: |
| 123 | + - TARGET_ARCHITECTURE: $[[ inputs.architectures ]] |
| 124 | + script: |
| 125 | + # Help Git understand the file permissions here. |
| 126 | + # > fatal: detected dubious ownership in repository |
| 127 | + - git config --global --add safe.directory "$(pwd)" |
| 128 | + |
| 129 | + # Tidy the file and fail if it changed. |
| 130 | + - go mod tidy && git diff --exit-code -- go.mod |
| 131 | + - go mod download |
| 132 | + |
| 133 | + # Run the fast/unit tests first. Failure here fails the job. |
| 134 | + - >- |
| 135 | + make check |
| 136 | + GO_TEST='go run gotest.tools/gotestsum@latest --' |
| 137 | + GOTESTSUM_JUNITFILE="make-check-${TARGET_ARCHITECTURE}.junit.xml" |
| 138 | +
|
| 139 | + # Run the entire test suite using a local Kubernetes API. |
| 140 | + - >- |
| 141 | + make check-envtest |
| 142 | + ENVTEST_K8S_VERSION='1.32' |
| 143 | + GO_TEST='go run gotest.tools/gotestsum@latest --' |
| 144 | + GOTESTSUM_JUNITFILE="make-check-envtest-${TARGET_ARCHITECTURE}.junit.xml" |
| 145 | +
|
| 146 | + # Send the reports to GitLab. |
| 147 | + artifacts: |
| 148 | + expire_in: '$[[ inputs.retention ]]' |
| 149 | + reports: |
| 150 | + junit: '*.junit.xml' |
0 commit comments