.gitbay/ci.yml

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

68 lines · 3526 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  # Vulnerability scanning, separate from test so a newly published advisory
19  # against unchanged code does not mask a real test failure. It fails the
20  # build on purpose: an advisory that only lands in a report nobody reads is
21  # the state this replaced. @latest matches deploy/audit.sh, so a run scans
22  # against the database as it is today, not as it was at commit time.
23  vuln:
24    steps:
25      - go run golang.org/x/vuln/cmd/govulncheck@latest ./...
26  # SonarCloud static analysis. Report-only: unlike vuln this does not
27  # gate, so a first scan of an existing codebase does not turn every
28  # build red before anyone has read what it says. Flip the trailing
29  # `|| true` off to make the quality gate binding.
30  #
31  # One step, because each step runs in its own `sh -c` and an export
32  # would not survive to the next. The scanner is cached under the
33  # runner's home rather than re-downloading ~50MB per build, and the
34  # linux-x64 bundle carries its own JRE, which is why the host needs no
35  # Java.
36  sonar:
37    steps:
38      - |
39        set -eu
40        if [ -z "${SONAR_TOKEN:-}" ]; then
41          echo "no SONAR_TOKEN in this build's environment; skipping."
42          echo "A merge request from a fork is built without secrets on purpose,"
43          echo "so this is expected there and is not a failure."
44          exit 0
45        fi
46        VERSION=8.1.0.6389
47        HOME_DIR="${HOME:-/var/lib/gitbay-runner}"
48        SCANNER="$HOME_DIR/.sonar/sonar-scanner-$VERSION-linux-x64"
49        if [ ! -x "$SCANNER/bin/sonar-scanner" ]; then
50          echo "installing sonar-scanner $VERSION"
51          curl --create-dirs -fsSLo "$HOME_DIR/.sonar/sonar-scanner.zip" \
52            "https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$VERSION-linux-x64.zip"
53          unzip -q -o "$HOME_DIR/.sonar/sonar-scanner.zip" -d "$HOME_DIR/.sonar/"
54          rm -f "$HOME_DIR/.sonar/sonar-scanner.zip"
55        fi
56        # Analyse each branch as itself. Without this every branch is
57        # recorded against the project's main branch, so a feature branch
58        # replaces main's results — a branch that removes findings makes
59        # main look clean before its fix is merged, and one that adds
60        # findings makes main look broken when it is not (#154).
61        BRANCH="${GITBAY_REF:-}"
62        BRANCH="${BRANCH#refs/heads/}"
63        BRANCH_ARG=""
64        if [ -n "$BRANCH" ] && [ "$BRANCH" != "main" ]; then
65          BRANCH_ARG="-Dsonar.branch.name=$BRANCH"
66        fi
67        SONAR_HOST_URL=https://sonarcloud.io \
68        "$SCANNER/bin/sonar-scanner" -Dsonar.scm.revision="${GITBAY_SHA:-}" $BRANCH_ARG || true