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"
VERSION_PACKAGE_PREFIX: "gitlab.com/private/go/common.git"
.gitlab_login: &gitlab_login |-
.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 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 fetch origin "${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}"
curl https://get.trunk.io -fsSL | bash -s -- -y
trunk check --all
trunk check --ci --upstream "${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}"
----------------------------------------------------