cairn/.forgejo/workflows/test.yml

83 lines
2.3 KiB
YAML

name: Test
on:
pull_request:
branches:
- main
- master
jobs:
test:
name: Run Tests
runs-on: x86_64-linux
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.25.7"
- run: go mod download
- run: go test -v -race -coverprofile=coverage.out ./...
- run: go tool cover -func=coverage.out
lint:
name: Lint
runs-on: x86_64-linux
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.25.7"
- run: go vet ./...
- name: Check formatting
run: |
if [ -n "$(gofmt -l .)" ]; then
echo "Go files are not formatted:"
gofmt -l .
exit 1
fi
- name: Check go.mod tidy
run: |
go mod tidy
if [ -n "$(git diff --name-only go.mod go.sum)" ]; then
echo "go.mod or go.sum is not tidy. Run 'go mod tidy' and commit the changes."
git diff go.mod go.sum
exit 1
fi
- name: golangci-lint
uses: golangci/golangci-lint-action@v7
with:
version: latest
- name: Install govulncheck
run: go install golang.org/x/vuln/cmd/govulncheck@latest
- name: Run govulncheck
run: govulncheck ./...
build:
name: Build
runs-on: debian-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.25.7"
- name: Build Go binaries
run: |
CGO_ENABLED=0 GOOS=linux go build -ldflags="-w -s" -o ./bin/cairn-server ./cmd/cairn-server
CGO_ENABLED=0 GOOS=linux go build -ldflags="-w -s" -o ./bin/cairn ./cmd/cairn
- name: Install Docker CLI
run: |
apt-get update && apt-get install -y curl
curl -fsSL https://download.docker.com/linux/static/stable/x86_64/docker-27.5.1.tgz \
| tar xz --strip-components=1 -C /usr/local/bin docker/docker
- name: Wait for Docker
run: |
timeout=30
elapsed=0
while ! docker info >/dev/null 2>&1; do
[ $elapsed -ge $timeout ] && echo "Docker not ready" && exit 1
sleep 2
elapsed=$((elapsed + 2))
done
- name: Build Docker image
run: docker build -t cairn:test .