.gitbay/ci.yml

a32f7f2001c1c0bf38ba8c3360e6bc7ca3982fee
gitbay/.gitbay/ci.yml history · blame · raw

92 lines · 4673 bytes

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