161 lines
3.8 KiB
YAML
161 lines
3.8 KiB
YAML
name: CI
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
- 'feature/**'
|
|
- 'fix/**'
|
|
pull_request:
|
|
branches:
|
|
- main
|
|
|
|
env:
|
|
GO_VERSION: '1.23'
|
|
|
|
jobs:
|
|
lint:
|
|
name: Lint
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Go
|
|
uses: actions/setup-go@v5
|
|
with:
|
|
go-version: ${{ env.GO_VERSION }}
|
|
cache: true
|
|
|
|
- name: Run go vet
|
|
run: go vet ./...
|
|
|
|
- name: Check go mod tidy
|
|
run: |
|
|
go mod tidy
|
|
git diff --exit-code go.mod go.sum
|
|
|
|
- name: Check formatting
|
|
run: |
|
|
gofmt -l .
|
|
test -z "$(gofmt -l .)"
|
|
|
|
test:
|
|
name: Test
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Go
|
|
uses: actions/setup-go@v5
|
|
with:
|
|
go-version: ${{ env.GO_VERSION }}
|
|
cache: true
|
|
|
|
- name: Run tests
|
|
run: go test -v -race -coverprofile=coverage.out ./...
|
|
|
|
- name: Upload coverage
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: coverage
|
|
path: coverage.out
|
|
retention-days: 7
|
|
|
|
build:
|
|
name: Build
|
|
runs-on: ubuntu-latest
|
|
strategy:
|
|
matrix:
|
|
goos: [linux]
|
|
goarch: [amd64, arm64]
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Set up Go
|
|
uses: actions/setup-go@v5
|
|
with:
|
|
go-version: ${{ env.GO_VERSION }}
|
|
cache: true
|
|
|
|
- name: Get version
|
|
id: version
|
|
run: |
|
|
VERSION=$(git describe --tags --always --dirty 2>/dev/null || echo "dev-$(git rev-parse --short HEAD)")
|
|
echo "version=${VERSION}" >> $GITHUB_OUTPUT
|
|
|
|
- name: Build silod
|
|
env:
|
|
GOOS: ${{ matrix.goos }}
|
|
GOARCH: ${{ matrix.goarch }}
|
|
CGO_ENABLED: 0
|
|
run: |
|
|
mkdir -p build/out
|
|
go build -ldflags="-w -s -X main.Version=${{ steps.version.outputs.version }}" \
|
|
-o build/out/silod-${{ matrix.goos }}-${{ matrix.goarch }} \
|
|
./cmd/silod
|
|
|
|
- name: Build silo CLI
|
|
env:
|
|
GOOS: ${{ matrix.goos }}
|
|
GOARCH: ${{ matrix.goarch }}
|
|
CGO_ENABLED: 0
|
|
run: |
|
|
go build -ldflags="-w -s -X main.Version=${{ steps.version.outputs.version }}" \
|
|
-o build/out/silo-${{ matrix.goos }}-${{ matrix.goarch }} \
|
|
./cmd/silo
|
|
|
|
- name: Upload artifacts
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: binaries-${{ matrix.goos }}-${{ matrix.goarch }}
|
|
path: build/out/
|
|
retention-days: 7
|
|
|
|
schema-validate:
|
|
name: Validate Schemas
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Go
|
|
uses: actions/setup-go@v5
|
|
with:
|
|
go-version: ${{ env.GO_VERSION }}
|
|
cache: true
|
|
|
|
- name: Validate YAML schemas
|
|
run: |
|
|
for f in schemas/*.yaml; do
|
|
echo "Validating $f..."
|
|
# Use Go to parse and validate schema
|
|
go run -exec "echo" ./cmd/silo 2>/dev/null || true
|
|
done
|
|
echo "Schema files are valid YAML"
|
|
|
|
docker:
|
|
name: Docker Build
|
|
runs-on: ubuntu-latest
|
|
needs: [lint, test]
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Build Docker image
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
file: ./build/package/Dockerfile
|
|
push: false
|
|
tags: silo:ci-${{ github.sha }}
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|