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 - name: System packages
38 run: pacman -Syu --noconfirm --needed git gcc
39 - uses: actions/checkout@v6
40 # Job containers reach Forgejo through the Gordon edge on the host loopback,
41 # in plain HTTP on :8088 (see vps-infra homelab/igor/ci-runner).
42 - name: Fetch bnema.dev/ermite* modules through the runner's Forgejo route
43 run: git config --global url."http://git.bnema.dev:8088/".insteadOf "https://git.bnema.dev/"
44 - uses: actions/setup-go@v5
45 with:
46 go-version-file: go.mod
47 cache: true
48 - name: Git is at least 2.45
49 run: |
50 git --version
51 v=$(git --version | sed -E 's/^git version ([0-9]+)\.([0-9]+).*/\1 \2/')
52 set -- $v
53 if [ "$1" -lt 2 ] || { [ "$1" -eq 2 ] && [ "$2" -lt 45 ]; }; then
54 echo "git 2.45 or newer is required" >&2
55 exit 1
56 fi
57 - name: Verify tidy
58 run: |
59 go mod tidy
60 git diff --exit-code -- go.mod go.sum
61 - name: Generated templ code is up to date
62 run: scripts/templ-drift.sh
63 - run: go vet ./...
64 - run: go test -race ./...
65 - name: Architecture
66 run: go tool hexcheck -fail-on warn ./...
67
68 proto:
69 name: Protobuf and generated code
70 runs-on: ubuntu-latest
71 steps:
72 - uses: actions/checkout@v6
73 with:
74 # buf breaking compares with the base branch.
75 fetch-depth: 0
76 # Job containers reach Forgejo through the Gordon edge on the host loopback,
77 # in plain HTTP on :8088 (see vps-infra homelab/igor/ci-runner).
78 - name: Fetch bnema.dev/ermite* modules through the runner's Forgejo route
79 run: git config --global url."http://git.bnema.dev:8088/".insteadOf "https://git.bnema.dev/"
80 - uses: actions/setup-go@v5
81 with:
82 go-version-file: go.mod
83 cache: true
84 - run: go tool buf lint
85 - name: Breaking changes
86 if: github.event_name == 'pull_request'
87 # Skipped by the script while the base branch has no proto/ directory.
88 run: scripts/buf-breaking.sh "origin/${{ github.base_ref }}"
89 - name: Generated protobuf code is up to date
90 run: |
91 go tool buf generate
92 git diff --exit-code -- gen/
93 test -z "$(git status --porcelain -- gen/)"
94 - name: Generated mocks are up to date
95 run: |
96 go generate ./internal/ports
97 git diff --exit-code -- internal/ports/mocks/
98 test -z "$(git status --porcelain -- internal/ports/mocks/)"
99
100 image:
101 name: Image
102 # Build only, nothing is pushed. The arch job container gets the runner's rootless
103 # Podman socket as /var/run/docker.sock (docker_host in ci-runner/config.yml), so the
104 # docker CLI builds through Podman.
105 runs-on: arch
106 steps:
107 - name: System packages
108 run: pacman -Syu --noconfirm --needed git docker
109 - uses: actions/checkout@v6
110 with:
111 # git describe needs the tags for the image version.
112 fetch-depth: 0
113 # The build runs in Podman on the runner host. With the host network it resolves
114 # git.bnema.dev through the host's /etc/hosts (127.0.0.1, see vps-infra
115 # homelab/igor/ci-runner) and reaches Forgejo on :8088. Podman's Docker API rejects
116 # the classic builder's --add-host encoding, so host networking is used instead.
117 # Acceptable because only trusted branches of this repo trigger CI (no fork PRs).
118 - name: Build the image
119 run: |
120 docker build \
121 --network host \
122 --build-arg GIT_REWRITE_BASE=http://git.bnema.dev:8088/ \
123 --build-arg VERSION="$(git describe --tags --always --dirty)" \
124 -t ermite:ci .
125 - name: Smoke test
126 run: |
127 docker run --rm ermite:ci version | tee /dev/stderr | grep -qF "ermite $(git describe --tags --always --dirty)"
128 docker run --rm --entrypoint git ermite:ci --version