diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6e5ad026b1d2dca8b97be63c5c0abc3a35ca6eed..0af2cd9f9f10298c02d30924d2491d885fbda1bb 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,5 +1,4 @@ variables: - GO_VERSION: "1.24.0" GOLANGCI_LINT_VERSION: 'v1.64.5' GITLAB_ADVANCED_SAST_ENABLED: 'true' @@ -10,12 +9,19 @@ workflow: - if: $CI_COMMIT_TAG - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH -default: - image: golang:${GO_VERSION} +.get_go_version: &get_go_version | + GO_VERSION=$(grep -E "^go [0-9]+\.[0-9]+(\.[0-9]+)?" go.mod | awk '{print $2}') + echo "GO_VERSION=${GO_VERSION}" + export GO_VERSION + +# This is the base job template that all other jobs will extend +.go_job: + # NOTE: largest linux-based hosted runner available in Free tier. + # see https://docs.gitlab.com/ee/ci/runners/hosted_runners/linux.html#machine-types-available-for-linux---x86-64N tags: - # NOTE: largest linux-based hosted runner available in Free tier. - # see https://docs.gitlab.com/ee/ci/runners/hosted_runners/linux.html#machine-types-available-for-linux---x86-64 - 'saas-linux-medium-amd64' + before_script: + - *get_go_version stages: - documentation @@ -35,13 +41,13 @@ include: inputs: golang_version: ${GO_VERSION} - # From: https://docs.gitlab.com/ee/ci/caching/#cache-go-dependencies .go-cache: variables: GOPATH: $CI_PROJECT_DIR/.go GOLANGCI_LINT_CACHE: $CI_PROJECT_DIR/.golangci-lint before_script: + - *get_go_version - mkdir -p .go .golangci-lint cache: paths: @@ -49,12 +55,16 @@ include: - .golangci-lint/ .documentation: + extends: .go_job stage: documentation rules: - if: $CI_PIPELINE_SOURCE == "merge_request_event" check_docs_update: extends: .documentation + image: golang:latest + before_script: + - *get_go_version script: - git fetch origin $CI_MERGE_REQUEST_TARGET_BRANCH_NAME && git checkout $CI_MERGE_REQUEST_TARGET_BRANCH_NAME && git checkout $CI_COMMIT_SHA - make gen-docs @@ -72,7 +82,9 @@ check_docs_update: check_docs_markdown: image: registry.gitlab.com/gitlab-org/technical-writing/docs-gitlab-com/lint-markdown:alpine-3.21-vale-3.9.3-markdownlint2-0.17.1-lychee-0.18.0 - extends: .documentation + stage: documentation + before_script: + - *get_go_version script: # Lint prose - vale --minAlertLevel error docs @@ -84,8 +96,10 @@ check_docs_markdown: lint_commit: stage: test image: node:18-slim - script: + before_script: + - *get_go_version - apt-get update && apt-get install -y git + script: - git fetch origin $CI_MERGE_REQUEST_TARGET_BRANCH_NAME && git checkout $CI_MERGE_REQUEST_TARGET_BRANCH_NAME && git checkout $CI_COMMIT_SHA - cd scripts/commit-lint && npm ci - node lint.js @@ -96,6 +110,8 @@ lint_commit: lint: image: golangci/golangci-lint:$GOLANGCI_LINT_VERSION stage: test + before_script: + - *get_go_version script: # Write the code coverage report to gl-code-quality-report.json # and print linting issues to stdout in the format: path/to/file:line description @@ -109,7 +125,11 @@ lint: run_tests: stage: test - extends: .go-cache + before_script: + - *get_go_version + - which go || echo "Go executable not found" + - echo $PATH + - go version # We currently only test on the lastest versino of Go which we also build against. # If we need to introduce testing for future versions of compatibility reasons # uncomment the below lines and adjust the `GO_VERSION` to included versions to test. @@ -138,6 +158,8 @@ run_tests: image: docker:stable services: - docker:dind + before_script: + - *get_go_version variables: # Disable shallow cloning so that goreleaser can diff between tags to # generate a changelog. @@ -191,6 +213,9 @@ homebrew-release: image: homebrew/ubuntu22.04:latest stage: release needs: [release] + dependencies: [release] + before_script: + - *get_go_version rules: - if: $CI_COMMIT_TAG script: @@ -205,6 +230,10 @@ windows_installer: image: name: amake/innosetup entrypoint: [""] + before_script: + - *get_go_version + dependencies: [build_windows] + needs: [build_windows] rules: - if: $CI_COMMIT_TAG - if: $CI_MERGE_REQUEST_EVENT_TYPE == "merge_train" @@ -218,13 +247,10 @@ windows_installer: paths: - "bin/*" expire_in: "30 days" - dependencies: [build_windows] - needs: [build_windows] build_windows: + extends: .go_job stage: release - needs: [] - extends: .go-cache rules: - if: $CI_COMMIT_TAG - if: $CI_MERGE_REQUEST_EVENT_TYPE == "merge_train" @@ -240,4 +266,6 @@ build_windows: expire_in: "30 days" secret_detection: + before_script: + - *get_go_version dependencies: [] # Don't download artifacts, especially `./public/`