ci.yml RawHistoryFolder
1name: CI
2
3on:
4 push:
5 branches: [main]
6 pull_request:
7
8env:
9 # Test the module alone, with the versions in go.mod (never a go.work).
10 GOWORK: "off"
11 GOPRIVATE: bnema.dev/ermite*
12
13jobs:
14 lint:
15 name: Lint
16 runs-on: ubuntu-latest
17 steps:
18 - uses: actions/checkout@v6
19 # Job containers reach Forgejo through the Gordon edge on the host loopback,
20 # in plain HTTP on :8088 (see vps-infra homelab/igor/ci-runner).
21 - name: Fetch bnema.dev/ermite* modules through the runner's Forgejo route
22 run: git config --global url."http://git.bnema.dev:8088/".insteadOf "https://git.bnema.dev/"
23 - uses: actions/setup-go@v5
24 with:
25 go-version-file: go.mod
26 cache: true
27 - uses: golangci/golangci-lint-action@v9
28 with:
29 version: v2.14.0
30
31 test:
32 name: Test
33 # ermite needs git >= 2.45; the ubuntu-latest image (Debian bookworm) has 2.39.
34 # The arch label runs archlinux:latest as root, with a current git.
35 runs-on: arch
36 steps:
37 # openssh provides ssh-keygen, which the tests use to check that the squash
38 # commits verify (git verify-commit, ADR 0022). The tests fail without it when CI is set.
39 # nodejs runs the tests of the file finder (internal/adapters/web/jstest).
40 - name: System packages
41 run: pacman -Syu --noconfirm --needed git gcc openssh nodejs
42 - uses: actions/checkout@v6
43 # Job containers reach Forgejo through the Gordon edge on the host loopback,
44 # in plain HTTP on :8088 (see vps-infra homelab/igor/ci-runner).
45 - name: Fetch bnema.dev/ermite* modules through the runner's Forgejo route
46 run: git config --global url."http://git.bnema.dev:8088/".insteadOf "https://git.bnema.dev/"
47 - uses: actions/setup-go@v5
48 with:
49 go-version-file: go.mod
50 cache: true
51 - name: Git is at least 2.45
52 run: |
53 git --version
54 v=$(git --version | sed -E 's/^git version ([0-9]+)\.([0-9]+).*/\1 \2/')
55 set -- $v
56 if [ "$1" -lt 2 ] || { [ "$1" -eq 2 ] && [ "$2" -lt 45 ]; }; then
57 echo "git 2.45 or newer is required" >&2
58 exit 1
59 fi
60 - name: Verify tidy
61 run: |
62 go mod tidy
63 git diff --exit-code -- go.mod go.sum
64 - name: Generated templ code is up to date
65 run: scripts/templ-drift.sh
66 - run: go vet ./...
67 # The end-to-end tests (internal/app, a real server per test) run before a
68 # PR is opened (README, Build) and here on main only: they are most of the
69 # time of a PR run.
70 - name: Tests
71 run: go test -race $(go list ./... | grep -vx 'bnema.dev/ermite/internal/app')
72 - name: End-to-end tests
73 if: github.event_name == 'push'
74 run: go test -race ./internal/app/
75 - name: Architecture
76 run: go tool hexcheck -fail-on warn ./...
77 # The core of the file finder (static/js/files.js) runs in Node.
78 - name: JavaScript tests
79 run: node --test 'internal/adapters/web/jstest/*.test.mjs'
80
81 proto:
82 name: Protobuf and generated code
83 runs-on: ubuntu-latest
84 steps:
85 - uses: actions/checkout@v6
86 with:
87 # buf breaking compares with the base branch.
88 fetch-depth: 0
89 # Job containers reach Forgejo through the Gordon edge on the host loopback,
90 # in plain HTTP on :8088 (see vps-infra homelab/igor/ci-runner).
91 - name: Fetch bnema.dev/ermite* modules through the runner's Forgejo route
92 run: git config --global url."http://git.bnema.dev:8088/".insteadOf "https://git.bnema.dev/"
93 - uses: actions/setup-go@v5
94 with:
95 go-version-file: go.mod
96 cache: true
97 - run: go tool buf lint
98 - name: Breaking changes
99 if: github.event_name == 'pull_request'
100 # Skipped by the script while the base branch has no proto/ directory.
101 run: scripts/buf-breaking.sh "origin/${{ github.base_ref }}"
102 - name: Generated protobuf code is up to date
103 run: |
104 go tool buf generate
105 git diff --exit-code -- gen/
106 test -z "$(git status --porcelain -- gen/)"
107 - name: Generated mocks are up to date
108 run: |
109 go generate ./internal/ports
110 git diff --exit-code -- internal/ports/mocks/
111 test -z "$(git status --porcelain -- internal/ports/mocks/)"
112
113 image:
114 name: Image
115 # Build only, nothing is pushed. The arch job container gets the runner's rootless
116 # Podman socket as /var/run/docker.sock (docker_host in ci-runner/config.yml), so the
117 # docker CLI builds through Podman.
118 runs-on: arch
119 steps:
120 - name: System packages
121 run: pacman -Syu --noconfirm --needed git docker
122 - uses: actions/checkout@v6
123 with:
124 # git describe needs the tags for the image version.
125 fetch-depth: 0
126 # The build runs in Podman on the runner host. With the host network it resolves
127 # git.bnema.dev through the host's /etc/hosts (127.0.0.1, see vps-infra
128 # homelab/igor/ci-runner) and reaches Forgejo on :8088. Podman's Docker API rejects
129 # the classic builder's --add-host encoding, so host networking is used instead.
130 # Acceptable because only trusted branches of this repo trigger CI (no fork PRs).
131 - name: Build the image
132 run: |
133 docker build \
134 --network host \
135 --build-arg GIT_REWRITE_BASE=http://git.bnema.dev:8088/ \
136 --build-arg VERSION="$(git describe --tags --always --dirty)" \
137 -t ermite:ci .
138 - name: Smoke test
139 run: |
140 docker run --rm ermite:ci version | tee /dev/stderr | grep -qF "ermite $(git describe --tags --always --dirty)"
141 docker run --rm --entrypoint git ermite:ci --version