Create a Post
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: 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: "* " VERSION_PACKAGE_PREFIX: " " .gitlab_login: &gitlab_login |- git config --global url." https://gitlab-ci-token:${CI_JOB_TOKEN}".insteadOf "ssh: // " git config --global url." https://gitlab-ci-token:${CI_JOB_TOKEN}".insteadOf " " .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" 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 - 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 echo "${TRUNK_CACHE}" pwd ls -la du --max-depth=2 git config --global url." https://gitlab-ci-token:${CI_JOB_TOKEN}".insteadOf " " git fetch origin "${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}" DON'T go install curl -fsSL | bash -s -- -y trunk check --all trunk check --ci --upstream "${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}" ----------------------------------------------------
Load More