Create a Post
3
Trunk via gitlab CI/CD
Creating a tracking note for how to get Trunk working in gitlab CI/CD pipeline Did manage to get trunk running using: trunk check --all However it was very slow. Not sure if this is because of some error in our configuration. See also slack thread: https://trunkcommunity.slack.com/archives/C0205B2FPE3/p1667854046200879 Our pipelines use: Common go.private-ci.yml template Per project .gitlab-ci.yml, which imports from the template Per project Makefile go.private-ci.yml ---------------------------------------------------- stages: - init - test - build - publish variables: GOPATH: "${CI_PROJECT_DIR}/.go" GOVER: "1.19" GOPRIVATE: " gitlab.com/private/* " VERSION_PACKAGE_PREFIX: " gitlab.com/private/go/common.git " .gitlab_login: &gitlab_login |- git config --global url." https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.com/".insteadOf "ssh: //git@gitlab.com/ " git config --global url." https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.com/".insteadOf " https://gitlab.com/ " .docker_folder: &docker_folder |- if [[ -d .docker ]]; then cp -rav .docker ${HOME} else echo "[I] No .docker folder found, so creating it" mkdir -p .docker fi default: before_script: - *gitlab_login - *docker_folder artifacts: paths: - ".docker" https://docs.gitlab.com/ee/ci/caching/#cache-go-dependencies Please note that GOPATH is set up the top in the variables section .godefault: image: golang:${GOVER} before_script: - *gitlab_login - *docker_folder - export PATH="${PATH}:${GOPATH}/bin" - mkdir --parents .go - mkdir --parents .trunk_cache - export TRUNK_CACHE= pwd /.trunk_cache - echo "TRUNK_CACHE=${TRUNK_CACHE}" - pwd artifacts: paths: - ".docker" cache: paths: - .go/pkg/mod/ - .trunk_cache/ .trunk: variables: GIT_STRATEGY: none stage: test extends: - .godefault script: Makefile installs and runs https://docs.trunk.io/docs - make trunk allow_failure: true ---------------------------------------------------- Project .gitlab-ci.yml ---------------------------------------------------- include: - project: "sidenio/ci/templates" file: "/templates/go.private-ci.yml" ref: c523b324c8323639db330264e1845c554e341bc2 stages: - init - deps - test trunk: needs: - dependency cache extends: - .trunk allow_failure: false ---------------------------------------------------- Project Makefile ---------------------------------------------------- trunk: @echo Installing and executing Trunk lint https://docs.trunk.io/docs echo "${TRUNK_CACHE}" pwd ls -la du --max-depth=2 git config --global url." https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.com/".insteadOf " https://gitlab.com/ " git fetch origin "${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}" DON'T go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.50.1 curl https://get.trunk.io -fsSL | bash -s -- -y trunk check --all trunk check --ci --upstream "${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}" ----------------------------------------------------
0
Load More