From 3f35b153c6961d37cdfd30ffa0808ff0ce58d991 Mon Sep 17 00:00:00 2001 From: Gary Holtz Date: Thu, 6 Mar 2025 12:08:27 -0600 Subject: [PATCH 1/7] chore: Trying to normalize go version --- .gitlab-ci.yml | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6e5ad026b..8441a842f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,5 +1,5 @@ variables: - GO_VERSION: "1.24.0" + # GOLANGCI_LINT_VERSION and other variables GOLANGCI_LINT_VERSION: 'v1.64.5' GITLAB_ADVANCED_SAST_ENABLED: 'true' @@ -10,14 +10,24 @@ workflow: - if: $CI_COMMIT_TAG - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH +# extracts golang version from go.mod +.setup: + before_script: + - export GO_VERSION_FROM_MOD=$(grep -E "^go [0-9]+\.[0-9]+(\.[0-9]+)?" go.mod | awk '{print $2}') + - echo "GO_VERSION_FROM_MOD=${GO_VERSION_FROM_MOD}" >> variables.env + artifacts: + reports: + dotenv: variables.env + default: - image: golang:${GO_VERSION} + image: golang:${GO_VERSION_FROM_MOD} 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' stages: + - setup - documentation - test - release @@ -33,8 +43,13 @@ include: - component: ${CI_SERVER_FQDN}/gitlab-org/components/danger-review/danger-review@2.0.0 - component: ${CI_SERVER_FQDN}/components/code-intelligence/golang-code-intel@v0.0.3 inputs: - golang_version: ${GO_VERSION} + golang_version: ${GO_VERSION_FROM_MOD} +extract_go_version: + stage: setup + extends: .setup + script: + - echo "Extracted Go version ${GO_VERSION_FROM_MOD} from go.mod" # From: https://docs.gitlab.com/ee/ci/caching/#cache-go-dependencies .go-cache: @@ -110,6 +125,7 @@ lint: run_tests: stage: test extends: .go-cache + needs: [extract_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. @@ -142,7 +158,7 @@ run_tests: # Disable shallow cloning so that goreleaser can diff between tags to # generate a changelog. GIT_DEPTH: 0 - needs: [windows_installer] + needs: [windows_installer, extract_go_version] dependencies: [windows_installer] release_test: @@ -158,7 +174,7 @@ release_test: script: | docker run --rm --privileged \ -v $PWD:/go/src/gitlab.com/gitlab-org/cli \ - -e GO_VERSION="$GO_VERSION" \ + -e GO_VERSION="$GO_VERSION_FROM_MOD" \ -w /go/src/gitlab.com/gitlab-org/cli \ -v /var/run/docker.sock:/var/run/docker.sock \ goreleaser/goreleaser:nightly release --snapshot @@ -177,7 +193,7 @@ release: -v $PWD:/go/src/gitlab.com/gitlab-org/cli \ -w /go/src/gitlab.com/gitlab-org/cli \ -v /var/run/docker.sock:/var/run/docker.sock \ - -e GO_VERSION="$GO_VERSION" \ + -e GO_VERSION="$GO_VERSION_FROM_MOD" \ -e GITLAB_TOKEN=$GITLAB_TOKEN_RELEASE \ --entrypoint "" \ goreleaser/goreleaser:nightly \ @@ -219,11 +235,11 @@ windows_installer: - "bin/*" expire_in: "30 days" dependencies: [build_windows] - needs: [build_windows] + needs: [build_windows, extract_go_version] build_windows: stage: release - needs: [] + needs: [extract_go_version] extends: .go-cache rules: - if: $CI_COMMIT_TAG -- GitLab From bb8e4a86ad9eb5fbc62103c6c685a7b35a36453c Mon Sep 17 00:00:00 2001 From: Gary Holtz Date: Thu, 6 Mar 2025 12:15:16 -0600 Subject: [PATCH 2/7] Trying some fixes --- .gitlab-ci.yml | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8441a842f..f48b59d71 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,5 +1,4 @@ variables: - # GOLANGCI_LINT_VERSION and other variables GOLANGCI_LINT_VERSION: 'v1.64.5' GITLAB_ADVANCED_SAST_ENABLED: 'true' @@ -10,24 +9,28 @@ workflow: - if: $CI_COMMIT_TAG - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH -# extracts golang version from go.mod -.setup: - before_script: - - export GO_VERSION_FROM_MOD=$(grep -E "^go [0-9]+\.[0-9]+(\.[0-9]+)?" go.mod | awk '{print $2}') - - echo "GO_VERSION_FROM_MOD=${GO_VERSION_FROM_MOD}" >> variables.env +extract_go_version: + stage: .pre + image: alpine:latest + script: + - apk add --no-cache grep + - GO_VERSION=$(grep -E "^go [0-9]+\.[0-9]+(\.[0-9]+)?" go.mod | awk '{print $2}') + - echo "GO_VERSION=${GO_VERSION}" >> build.env artifacts: reports: - dotenv: variables.env + dotenv: build.env default: - image: golang:${GO_VERSION_FROM_MOD} + # All jobs will use this image definition after the variables are set + image: golang:${GO_VERSION} 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' + needs: + - job: extract_go_version stages: - - setup - documentation - test - release @@ -43,13 +46,7 @@ include: - component: ${CI_SERVER_FQDN}/gitlab-org/components/danger-review/danger-review@2.0.0 - component: ${CI_SERVER_FQDN}/components/code-intelligence/golang-code-intel@v0.0.3 inputs: - golang_version: ${GO_VERSION_FROM_MOD} - -extract_go_version: - stage: setup - extends: .setup - script: - - echo "Extracted Go version ${GO_VERSION_FROM_MOD} from go.mod" + golang_version: ${GO_VERSION} # From: https://docs.gitlab.com/ee/ci/caching/#cache-go-dependencies .go-cache: @@ -125,7 +122,6 @@ lint: run_tests: stage: test extends: .go-cache - needs: [extract_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. @@ -158,7 +154,7 @@ run_tests: # Disable shallow cloning so that goreleaser can diff between tags to # generate a changelog. GIT_DEPTH: 0 - needs: [windows_installer, extract_go_version] + needs: [windows_installer] dependencies: [windows_installer] release_test: @@ -174,7 +170,7 @@ release_test: script: | docker run --rm --privileged \ -v $PWD:/go/src/gitlab.com/gitlab-org/cli \ - -e GO_VERSION="$GO_VERSION_FROM_MOD" \ + -e GO_VERSION="$GO_VERSION" \ -w /go/src/gitlab.com/gitlab-org/cli \ -v /var/run/docker.sock:/var/run/docker.sock \ goreleaser/goreleaser:nightly release --snapshot @@ -193,7 +189,7 @@ release: -v $PWD:/go/src/gitlab.com/gitlab-org/cli \ -w /go/src/gitlab.com/gitlab-org/cli \ -v /var/run/docker.sock:/var/run/docker.sock \ - -e GO_VERSION="$GO_VERSION_FROM_MOD" \ + -e GO_VERSION="$GO_VERSION" \ -e GITLAB_TOKEN=$GITLAB_TOKEN_RELEASE \ --entrypoint "" \ goreleaser/goreleaser:nightly \ @@ -235,11 +231,10 @@ windows_installer: - "bin/*" expire_in: "30 days" dependencies: [build_windows] - needs: [build_windows, extract_go_version] + needs: [build_windows] build_windows: stage: release - needs: [extract_go_version] extends: .go-cache rules: - if: $CI_COMMIT_TAG -- GitLab From 2912527f316cb1a7f78b8e493685320bb8ba0702 Mon Sep 17 00:00:00 2001 From: Gary Holtz Date: Thu, 6 Mar 2025 12:25:35 -0600 Subject: [PATCH 3/7] Gitlabci fixes --- .gitlab-ci.yml | 57 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f48b59d71..7d88744b6 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -9,26 +9,20 @@ workflow: - if: $CI_COMMIT_TAG - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH -extract_go_version: - stage: .pre - image: alpine:latest - script: - - apk add --no-cache grep - - GO_VERSION=$(grep -E "^go [0-9]+\.[0-9]+(\.[0-9]+)?" go.mod | awk '{print $2}') - - echo "GO_VERSION=${GO_VERSION}" >> build.env - artifacts: - reports: - dotenv: build.env +.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 -default: - # All jobs will use this image definition after the variables are set - image: golang:${GO_VERSION} +# This is the base job template that all other jobs will extend +.go_job: + image: golang:$GO_VERSIO + # 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' - needs: - - job: extract_go_version + before_script: + - *get_go_version stages: - documentation @@ -54,6 +48,7 @@ include: 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: @@ -61,6 +56,7 @@ include: - .golangci-lint/ .documentation: + extends: .go_job stage: documentation rules: - if: $CI_PIPELINE_SOURCE == "merge_request_event" @@ -84,7 +80,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 @@ -96,8 +94,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 @@ -108,6 +108,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 @@ -121,7 +123,7 @@ lint: run_tests: stage: test - extends: .go-cache + extends: .go_job # 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. @@ -150,6 +152,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. @@ -203,6 +207,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: @@ -217,6 +224,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" @@ -230,12 +241,10 @@ windows_installer: paths: - "bin/*" expire_in: "30 days" - dependencies: [build_windows] - needs: [build_windows] build_windows: + extends: .go_job stage: release - extends: .go-cache rules: - if: $CI_COMMIT_TAG - if: $CI_MERGE_REQUEST_EVENT_TYPE == "merge_train" @@ -251,4 +260,6 @@ build_windows: expire_in: "30 days" secret_detection: + before_script: + - *get_go_version dependencies: [] # Don't download artifacts, especially `./public/` -- GitLab From b26a2109f1e8b8375185f5308f2fc1b355dbc185 Mon Sep 17 00:00:00 2001 From: Gary Holtz Date: Thu, 6 Mar 2025 12:28:17 -0600 Subject: [PATCH 4/7] Adding to check_docs --- .gitlab-ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7d88744b6..84d4e1936 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -63,6 +63,8 @@ include: check_docs_update: extends: .documentation + 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 -- GitLab From f5ec496143e4b103f2e690f0063aa4e82f709c21 Mon Sep 17 00:00:00 2001 From: Gary Holtz Date: Thu, 6 Mar 2025 13:41:30 -0600 Subject: [PATCH 5/7] Fixing typo --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 84d4e1936..2b27ed4e2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -16,7 +16,6 @@ workflow: # This is the base job template that all other jobs will extend .go_job: - image: golang:$GO_VERSIO # 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: @@ -63,6 +62,7 @@ include: check_docs_update: extends: .documentation + image: golang:latest before_script: - *get_go_version script: -- GitLab From 925de9bab8dd8a8b29e5f256b9f8991ecb434b27 Mon Sep 17 00:00:00 2001 From: Gary Holtz Date: Thu, 6 Mar 2025 13:47:47 -0600 Subject: [PATCH 6/7] Adding check to tests --- .gitlab-ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2b27ed4e2..5137d32e2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -125,7 +125,8 @@ lint: run_tests: stage: test - extends: .go_job + before_script: + - *get_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. -- GitLab From 2468cad40e311ecbc8bbc6e3b24cfddc3d490d31 Mon Sep 17 00:00:00 2001 From: Gary Holtz Date: Thu, 6 Mar 2025 13:55:26 -0600 Subject: [PATCH 7/7] Adding some debugs --- .gitlab-ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5137d32e2..0af2cd9f9 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -127,6 +127,9 @@ run_tests: stage: test 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. -- GitLab