jobs: # Fast feedback: this finishes in seconds, so it is not held behind the # suite. build: image: localhost/gitbay-ci:1 steps: - go build ./... - go vet ./... # The suite drives real git, ssh, sshd and gpg. Several tests skip # themselves when a tool is absent, so the prerequisites are asserted # first, all of them in one step so one run names everything to install. # A green check that quietly tested less is worse than a red one. # The 20m is under the runner's own 30m limit, so go times out first and # says which test hung instead of the runner killing it blind. test: image: localhost/gitbay-ci:1 steps: - missing=""; for t in git git-lfs gpg; do command -v "$t" >/dev/null || missing="$missing $t"; done; test -x /usr/sbin/sshd || missing="$missing sshd"; test -z "$missing" || { echo "runner is missing:$missing"; exit 1; } - go test ./... -count=1 -timeout 20m paths-ignore: - .gitbay/wiki/** # Vulnerability scanning, separate from test so a newly published advisory # against unchanged code does not mask a real test failure. It fails the # build on purpose: an advisory that only lands in a report nobody reads is # the state this replaced. @latest matches deploy/audit.sh, so a run scans # against the database as it is today, not as it was at commit time. # # Nightly rather than per-push, because that last sentence is the whole # job: the trigger is the advisory database, not the code. An advisory # published against code nobody touched was invisible until someone # happened to push, while a rebase that changed nothing re-scanned it. # A schedule asks the question on the cadence the answer changes. # `build trigger krz/gitbay vuln` runs it on demand before a release # (#177). vuln: image: localhost/gitbay-ci:1 schedule: "0 3 * * *" steps: - go run golang.org/x/vuln/cmd/govulncheck@latest ./... # SonarCloud static analysis. Report-only: unlike vuln this does not # gate, so a first scan of an existing codebase does not turn every # build red before anyone has read what it says. Flip the trailing # `|| true` off to make the quality gate binding. # # Also nightly (#177). Report-only means it cannot fail a build, so # analysing every push of a branch that is about to be squashed away # informs nobody, and a stack being rebased analysed the same tree four # times. A scheduled job is registered by a default-branch push, so # this now tracks main — which is what the per-branch handling in the # step below was protecting in the first place (#154). It still works # on a branch when triggered by hand. # # One step, because each step runs in its own `sh -c` and an export # would not survive to the next. The scanner is cached under the # runner's home rather than re-downloading ~50MB per build, and the # linux-x64 bundle carries its own JRE, which is why the host needs no # Java. sonar: image: localhost/gitbay-ci:1 schedule: "30 3 * * *" steps: - | set -eu if [ -z "${SONAR_TOKEN:-}" ]; then echo "no SONAR_TOKEN in this build's environment; skipping." echo "A merge request from a fork is built without secrets on purpose," echo "so this is expected there and is not a failure." exit 0 fi VERSION=8.1.0.6389 HOME_DIR="${HOME:-/var/lib/gitbay-runner}" SCANNER="$HOME_DIR/.sonar/sonar-scanner-$VERSION-linux-x64" if [ ! -x "$SCANNER/bin/sonar-scanner" ]; then echo "installing sonar-scanner $VERSION" curl --create-dirs -fsSLo "$HOME_DIR/.sonar/sonar-scanner.zip" \ "https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$VERSION-linux-x64.zip" unzip -q -o "$HOME_DIR/.sonar/sonar-scanner.zip" -d "$HOME_DIR/.sonar/" rm -f "$HOME_DIR/.sonar/sonar-scanner.zip" fi # Analyse each branch as itself. Without this every branch is # recorded against the project's main branch, so a feature branch # replaces main's results — a branch that removes findings makes # main look clean before its fix is merged, and one that adds # findings makes main look broken when it is not (#154). BRANCH="${GITBAY_REF:-}" BRANCH="${BRANCH#refs/heads/}" BRANCH_ARG="" if [ -n "$BRANCH" ] && [ "$BRANCH" != "main" ]; then BRANCH_ARG="-Dsonar.branch.name=$BRANCH" fi SONAR_HOST_URL=https://sonarcloud.io \ "$SCANNER/bin/sonar-scanner" -Dsonar.scm.revision="${GITBAY_SHA:-}" $BRANCH_ARG || true