2023-02-07 07:12:50 +00:00
variables :
2024-01-08 14:52:40 +00:00
GO_VERSION : "1.21"
2023-02-07 07:12:50 +00:00
2022-10-21 17:21:38 +00:00
# run the pipeline only on MRs, tags, and default branch
2020-10-25 17:10:44 +00:00
workflow :
rules :
2022-10-21 17:21:38 +00:00
- if : $CI_PIPELINE_SOURCE == "merge_request_event"
- if : $CI_COMMIT_TAG
- if : $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
2020-10-25 17:10:44 +00:00
default :
2023-02-07 07:12:50 +00:00
image : golang:${GO_VERSION}
2020-10-25 17:10:44 +00:00
2022-07-13 17:06:30 +00:00
stages :
2022-10-28 19:55:09 +00:00
- documentation
2022-07-13 17:06:30 +00:00
- test
- release
2020-10-25 17:10:44 +00:00
include :
2022-11-28 12:25:35 +00:00
# remove the `.latest` from the following templates after 16.0 GitLab release
# the `.latest` indicates the "nightly" version of the job definition
# when we remove the `.latest`, we'll be using the stable job definition
# https://gitlab.com/gitlab-org/cli/-/merge_requests/1100#note_1186302003
- template : Jobs/SAST.latest.gitlab-ci.yml
- template : Jobs/Dependency-Scanning.latest.gitlab-ci.yml
- template : Jobs/Secret-Detection.latest.gitlab-ci.yml
2022-11-22 19:51:28 +00:00
- project : 'gitlab-org/quality/pipeline-common'
file : '/ci/danger-review.yml' # danger-review job below
2022-10-04 19:30:12 +00:00
2023-10-11 22:41:10 +00:00
2022-10-04 19:30:12 +00:00
# From: https://docs.gitlab.com/ee/ci/caching/#cache-go-dependencies
.go-cache :
variables :
GOPATH : $CI_PROJECT_DIR/.go
2022-11-17 18:36:09 +00:00
GOLANGCI_LINT_CACHE : $CI_PROJECT_DIR/.golangci-lint
2022-10-04 19:30:12 +00:00
before_script :
2022-11-17 18:36:09 +00:00
- mkdir -p .go .golangci-lint
2022-10-04 19:30:12 +00:00
cache :
paths :
- .go/pkg/mod/
2022-11-17 18:36:09 +00:00
- .golangci-lint/
2022-10-28 18:13:35 +00:00
2022-10-28 19:55:09 +00:00
.documentation :
stage : documentation
2022-10-28 19:47:50 +00:00
rules :
- if : $CI_PIPELINE_SOURCE == "merge_request_event"
2022-10-28 19:55:09 +00:00
check_docs_update :
extends : .documentation
2022-10-28 18:13:35 +00:00
script :
- git fetch origin $CI_MERGE_REQUEST_TARGET_BRANCH_NAME && git checkout $CI_MERGE_REQUEST_TARGET_BRANCH_NAME && git checkout $CI_COMMIT_SHA
2023-02-07 08:22:45 +00:00
- make gen-docs
2022-10-28 18:13:35 +00:00
- |-
2022-11-09 17:09:14 +00:00
git status
2022-10-28 18:13:35 +00:00
if [[ $(git add -A --dry-run) ]]; then
echo '✖ ERROR : Documentation changes detected!';
echo '✖ These changes require a documentation update. To regenerate the docs, read https://gitlab.com/gitlab-org/cli/-/tree/main/docs#generating-the-docs.';
exit 1;
else
echo '✔ No documentation updates detected.';
exit 0;
fi
2022-10-21 14:38:48 +00:00
check_docs_markdown :
2024-02-09 01:25:20 +00:00
image : registry.gitlab.com/gitlab-org/gitlab-docs/lint-markdown:alpine-3.19-vale-3.0.7-markdownlint-0.39.0-markdownlint2-0.12.1
2022-10-28 19:55:09 +00:00
extends : .documentation
2022-10-21 14:38:48 +00:00
script :
# Lint prose
2023-09-18 18:42:54 +00:00
- vale --minAlertLevel error docs *.md
2022-10-21 14:38:48 +00:00
# Lint Markdown
2024-02-09 01:25:20 +00:00
- markdownlint-cli2 'docs/**/*.md' *.md
2022-10-04 19:30:12 +00:00
2022-10-21 20:02:28 +00:00
lint_commit :
stage : test
2024-04-22 16:06:02 +00:00
image : node:18-slim
2023-01-30 22:47:43 +00:00
script :
2022-10-21 20:02:28 +00:00
- apt-get update && apt-get install -y git
- 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
rules :
- if : '$CI_MERGE_REQUEST_IID && $CI_PROJECT_VISIBILITY == "public"' # lint.js script makes an API call without authentication
when : always
2022-11-17 20:24:48 +00:00
lint :
extends : .go-cache
2023-08-28 04:16:46 +00:00
image : registry.gitlab.com/gitlab-org/gitlab-build-images:golangci-lint-1.52-alpine
2022-11-17 20:24:48 +00:00
stage : test
script :
- golangci-lint --version
# Use default .golangci.yml file from the image if one is not present in the project root.
- '[ -e .golangci.yml ] || cp /golangci/.golangci.yml .'
# Write the code coverage report to gl-code-quality-report.json
# remove `--issues-exit-code 0` or set to non-zero to fail the job if linting issues are detected
- golangci-lint run --out-format colored-line-number:stdout,code-climate:gl-code-quality-report.json
artifacts :
reports :
codequality : gl-code-quality-report.json
paths :
- gl-code-quality-report.json
2020-10-25 17:10:44 +00:00
code_navigation :
2022-07-13 17:06:30 +00:00
stage : test
2024-02-08 02:28:35 +00:00
image : golang:${GO_VERSION}
2020-10-25 17:10:44 +00:00
allow_failure : true
script :
2022-08-01 18:17:12 +00:00
- go install github.com/sourcegraph/lsif-go/cmd/lsif-go@latest
2020-10-25 17:10:44 +00:00
- lsif-go
artifacts :
reports :
lsif : dump.lsif
2022-06-09 08:16:10 +00:00
run_tests :
2022-07-13 17:06:30 +00:00
stage : test
2022-10-04 19:30:12 +00:00
extends : .go-cache
2023-02-07 07:12:50 +00:00
parallel :
matrix :
2024-04-22 14:21:06 +00:00
- GO_VERSION : [ "1.21" , "1.22" ]
2022-06-09 08:16:10 +00:00
script :
2022-07-13 17:06:30 +00:00
# `goreleaser` also uses GITLAB_TOKEN and so we need to distinguish between
# the GITLAB_TOKEN_TEST with less privilege used for testing and the GITLAB_TOKEN_RELEASE token
2023-03-07 13:28:38 +00:00
# GITLAB_TEST_HOST is the GitLab instance used for the integration tests
- GITLAB_TOKEN=$GITLAB_TOKEN_TEST GITLAB_TEST_HOST=$GITLAB_TEST_HOST make test
2023-02-08 18:14:06 +00:00
after_script :
- echo -e "\e[0Ksection_start:`date +%s`:coverage[collapsed=true]\r\e[0KRunning coverage report"
- make coverage
- echo -e "\e[0Ksection_end:`date +%s`:coverage\r\e[0K"
coverage : /^total:\t+\(statements\)\t+\d+\.\d+%$/
2022-10-04 19:30:12 +00:00
artifacts :
2023-07-13 23:29:22 +00:00
when : always
2023-07-11 06:20:39 +00:00
paths :
- test-output.log
2022-10-21 20:02:28 +00:00
reports :
junit : coverage.xml
2022-07-13 17:06:30 +00:00
.release :
stage : release
image : docker:stable
services :
- docker:dind
variables :
# Disable shallow cloning so that goreleaser can diff between tags to
# generate a changelog.
GIT_DEPTH : 0
2022-12-01 23:54:33 +00:00
needs : [ windows_installer]
dependencies : [ windows_installer]
2022-07-13 17:06:30 +00:00
release_test :
extends : .release
2022-10-28 18:13:35 +00:00
rules :
- if : $CI_COMMIT_TAG
when : never
- if : $CI_PIPELINE_SOURCE == "merge_request_event"
- if : $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
2022-07-13 17:06:30 +00:00
script : |
docker run --rm --privileged \
-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 \
2023-01-30 22:47:43 +00:00
goreleaser/goreleaser release --snapshot
2022-12-01 23:54:33 +00:00
build_windows :
stage : test
extends : .go-cache
script :
- GOOS=windows GOARCH=amd64 make build
- mv bin/glab bin/glab.exe
artifacts :
paths :
- "bin/glab.exe"
expire_in : "30 days"
windows_installer :
stage : release
image :
name : amake/innosetup
entrypoint : [ "" ]
script :
- mv scripts/setup_windows.iss .
- iscc "setup_windows.iss" -DVersion=${CI_COMMIT_TAG//v}
artifacts :
paths :
- "bin/*"
expire_in : "30 days"
dependencies : [ build_windows]
needs : [ build_windows]
2022-07-13 17:06:30 +00:00
release :
extends : .release
2022-10-28 18:13:35 +00:00
rules :
- if : $CI_COMMIT_TAG
2022-07-13 17:06:30 +00:00
script : |
docker run --rm --privileged \
-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 GITLAB_TOKEN=$GITLAB_TOKEN_RELEASE \
2022-12-02 12:08:45 +00:00
--entrypoint "" \
goreleaser/goreleaser \
bash -c "
docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
docker login -u $DOCKER_IO_USER -p $DOCKER_IO_PASSWORD
goreleaser release
"
2022-11-28 12:25:35 +00:00
2023-01-30 22:47:43 +00:00
homebrew-release :
image : homebrew/ubuntu22.04:latest
stage : release
rules :
- if : $CI_COMMIT_TAG
script :
2023-02-06 22:59:46 +00:00
- touch ~/.gitconfig
2023-02-06 23:01:02 +00:00
- git config --global user.email "$GITHUB_EMAIL"
- git config --global user.name "$GITHUB_NAME"
2023-02-06 21:50:03 +00:00
- curl "$CI_PROJECT_URL/-/archive/$CI_COMMIT_TAG/$CI_PROJECT_NAME-$CI_COMMIT_TAG.tar.gz" --output "$CI_PROJECT_NAME-$CI_COMMIT_TAG.tar.gz"
2023-02-06 23:52:49 +00:00
- brew bump-formula-pr glab --no-browse --url="$CI_PROJECT_URL/-/archive/$CI_COMMIT_TAG/$CI_PROJECT_NAME-$CI_COMMIT_TAG.tar.gz" --sha256="$(sha256sum $CI_PROJECT_NAME-$CI_COMMIT_TAG.tar.gz | cut -d ' ' -f 1)"
2023-01-30 22:47:43 +00:00
2022-11-28 12:25:35 +00:00
secret_detection :
dependencies : [ ] # Don't download artifacts, especially `./public/`