Add .forgejo/workflows/build.yml: vet, test, cross-compile to windows/amd64
Two jobs: 'test' runs go vet + go test -race + a Linux smoke build to catch generic compile errors cheaply. 'build-windows' cross-compiles drover.exe with version metadata baked in and uploads it as an artifact with 14-day retention. CGO is disabled - divert-go integration in a later phase will switch it on with mingw. Manual git clone (no actions/checkout/setup-go) because the runner's golang:1.23-bookworm image lacks Node.js. Both jobs cache GOMODCACHE and GOCACHE keyed by go.sum hash. Concurrency cancel-in-progress keeps the queue tidy when commits land in quick succession. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
name: Build
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
paths-ignore:
|
||||
- 'docs/**'
|
||||
- 'README.md'
|
||||
- 'LICENSE'
|
||||
- '*.md'
|
||||
pull_request:
|
||||
paths-ignore:
|
||||
- 'docs/**'
|
||||
- '*.md'
|
||||
|
||||
concurrency:
|
||||
group: build-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: go
|
||||
steps:
|
||||
- name: Checkout
|
||||
run: |
|
||||
git clone --no-checkout "https://forgejo-runner:${GITHUB_TOKEN}@git.okcu.io/${GITHUB_REPOSITORY}.git" /tmp/src
|
||||
git -C /tmp/src checkout "$GITHUB_SHA"
|
||||
cp -a /tmp/src/. .
|
||||
- name: Cache Go modules
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: |
|
||||
~/.cache/go-build
|
||||
~/go/pkg/mod
|
||||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||
restore-keys: ${{ runner.os }}-go-
|
||||
- name: Vet
|
||||
run: go vet ./...
|
||||
- name: Test with race
|
||||
run: go test -race -coverprofile=coverage.txt -covermode=atomic ./...
|
||||
- name: Linux smoke build
|
||||
run: |
|
||||
mkdir -p bin
|
||||
go build -trimpath -ldflags="-s -w" -o bin/drover ./cmd/drover
|
||||
|
||||
build-windows:
|
||||
runs-on: go
|
||||
needs: test
|
||||
steps:
|
||||
- name: Checkout
|
||||
run: |
|
||||
git clone --no-checkout "https://forgejo-runner:${GITHUB_TOKEN}@git.okcu.io/${GITHUB_REPOSITORY}.git" /tmp/src
|
||||
git -C /tmp/src checkout "$GITHUB_SHA"
|
||||
cp -a /tmp/src/. .
|
||||
- name: Cache Go modules
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: |
|
||||
~/.cache/go-build
|
||||
~/go/pkg/mod
|
||||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||
restore-keys: ${{ runner.os }}-go-
|
||||
- name: Cross-compile drover.exe (windows/amd64)
|
||||
env:
|
||||
GOOS: windows
|
||||
GOARCH: amd64
|
||||
CGO_ENABLED: '0'
|
||||
run: |
|
||||
SHORT_SHA="${GITHUB_SHA:0:7}"
|
||||
BUILD_DATE="$(date -u +%Y-%m-%d)"
|
||||
mkdir -p bin
|
||||
go build -trimpath -ldflags="-s -w \
|
||||
-X main.Version=dev-${SHORT_SHA} \
|
||||
-X main.Commit=${SHORT_SHA} \
|
||||
-X main.BuildDate=${BUILD_DATE}" \
|
||||
-o bin/drover.exe ./cmd/drover
|
||||
ls -la bin/
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: drover-windows-amd64-${{ github.sha }}
|
||||
path: bin/drover.exe
|
||||
retention-days: 14
|
||||
Reference in New Issue
Block a user