.gitbay/ci.yml
74 lines · 3652 bytes
1jobs:
2 # Fast feedback: this finishes in seconds, so it is not held behind the
3 # suite.
4 build:
5 steps:
6 - go build ./...
7 - go vet ./...
8 # The suite drives real git, ssh, sshd and gpg. Several tests skip
9 # themselves when a tool is absent, so the prerequisites are asserted
10 # first, all of them in one step so one run names everything to install.
11 # A green check that quietly tested less is worse than a red one.
12 # The 20m is under the runner's own 30m limit, so go times out first and
13 # says which test hung instead of the runner killing it blind.
14 test:
15 steps:
16 - 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; }
17 - go test ./... -count=1 -timeout 20m
18 paths-ignore:
19 - .gitbay/wiki/**
20 # Vulnerability scanning, separate from test so a newly published advisory
21 # against unchanged code does not mask a real test failure. It fails the
22 # build on purpose: an advisory that only lands in a report nobody reads is
23 # the state this replaced. @latest matches deploy/audit.sh, so a run scans
24 # against the database as it is today, not as it was at commit time.
25 vuln:
26 steps:
27 - go run golang.org/x/vuln/cmd/govulncheck@latest ./...
28 paths-ignore:
29 - .gitbay/wiki/**
30 # SonarCloud static analysis. Report-only: unlike vuln this does not
31 # gate, so a first scan of an existing codebase does not turn every
32 # build red before anyone has read what it says. Flip the trailing
33 # `|| true` off to make the quality gate binding.
34 #
35 # One step, because each step runs in its own `sh -c` and an export
36 # would not survive to the next. The scanner is cached under the
37 # runner's home rather than re-downloading ~50MB per build, and the
38 # linux-x64 bundle carries its own JRE, which is why the host needs no
39 # Java.
40 sonar:
41 steps:
42 - |
43 set -eu
44 if [ -z "${SONAR_TOKEN:-}" ]; then
45 echo "no SONAR_TOKEN in this build's environment; skipping."
46 echo "A merge request from a fork is built without secrets on purpose,"
47 echo "so this is expected there and is not a failure."
48 exit 0
49 fi
50 VERSION=8.1.0.6389
51 HOME_DIR="${HOME:-/var/lib/gitbay-runner}"
52 SCANNER="$HOME_DIR/.sonar/sonar-scanner-$VERSION-linux-x64"
53 if [ ! -x "$SCANNER/bin/sonar-scanner" ]; then
54 echo "installing sonar-scanner $VERSION"
55 curl --create-dirs -fsSLo "$HOME_DIR/.sonar/sonar-scanner.zip" \
56 "https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$VERSION-linux-x64.zip"
57 unzip -q -o "$HOME_DIR/.sonar/sonar-scanner.zip" -d "$HOME_DIR/.sonar/"
58 rm -f "$HOME_DIR/.sonar/sonar-scanner.zip"
59 fi
60 # Analyse each branch as itself. Without this every branch is
61 # recorded against the project's main branch, so a feature branch
62 # replaces main's results — a branch that removes findings makes
63 # main look clean before its fix is merged, and one that adds
64 # findings makes main look broken when it is not (#154).
65 BRANCH="${GITBAY_REF:-}"
66 BRANCH="${BRANCH#refs/heads/}"
67 BRANCH_ARG=""
68 if [ -n "$BRANCH" ] && [ "$BRANCH" != "main" ]; then
69 BRANCH_ARG="-Dsonar.branch.name=$BRANCH"
70 fi
71 SONAR_HOST_URL=https://sonarcloud.io \
72 "$SCANNER/bin/sonar-scanner" -Dsonar.scm.revision="${GITBAY_SHA:-}" $BRANCH_ARG || true
73 paths-ignore:
74 - .gitbay/wiki/**