Files
onvif-go/.github/workflows/ci.yml
T

209 lines
5.9 KiB
YAML

name: CI
on:
push:
branches: [ master, main, develop ]
pull_request:
branches: [ master, main, develop ]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
# Quick validation - fail fast on obvious issues
validate:
name: Quick Validation
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Set up Go
uses: actions/setup-go@0a12ed9d6470c3512128ab8f076f97fbbff3da52 # v5.0.1
with:
go-version: '1.23'
- name: Cache Go modules
uses: actions/cache@1bd1e32a3bdc2474371e44e3f675e0e8cb6f3eff # v4.2.0
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Download dependencies
run: go mod download && go mod verify
- name: Check formatting
run: |
if [ "$(gofmt -s -l . | grep -v vendor | wc -l)" -gt 0 ]; then
echo "Code formatting issues found:"
gofmt -s -d . | grep -v vendor
exit 1
fi
- name: Lint
uses: golangci/golangci-lint-action@3cfe3a4ac716397848d91e4042119f51a40b6aaf # v4.0.0
with:
version: latest
args: --timeout=5m --fix=false
# Test on primary Go version
test:
name: Test (Go 1.23)
runs-on: ubuntu-latest
needs: validate
steps:
- name: Checkout code
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Set up Go
uses: actions/setup-go@0a12ed9d6470c3512128ab8f076f97fbbff3da52 # v5.0.1
with:
go-version: '1.23'
- name: Cache Go modules
uses: actions/cache@1bd1e32a3bdc2474371e44e3f675e0e8cb6f3eff # v4.2.0
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-1.23-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-1.23-
- name: Download dependencies
run: go mod download
- name: Run tests with coverage
run: go test -v -race -covermode=atomic -coverprofile=coverage.out ./...
- name: Generate coverage report
run: go tool cover -html=coverage.out -o coverage.html
- name: Upload coverage to Codecov
uses: codecov/codecov-action@8a4b2d1c64a2a31fb92d9fa9f1e2b02e35d2db1a # v4.0.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.out
flags: unittests
name: codecov-umbrella
fail_ci_if_error: true
- name: Archive coverage
if: always()
uses: actions/upload-artifact@89ef406dd8d8a50a2f1e5e903c0e970c27a27de8 # v4.3.5
with:
name: coverage-report
path: |
coverage.out
coverage.html
retention-days: 30
# Test on multiple Go versions (after primary test passes)
test-matrix:
name: Test (Go ${{ matrix.go-version }})
runs-on: ${{ matrix.os }}
needs: test
strategy:
fail-fast: true # Stop on first failure
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
go-version: ['1.21', '1.22']
exclude:
- os: macos-latest
go-version: '1.21'
- os: windows-latest
go-version: '1.21'
steps:
- name: Checkout code
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Set up Go
uses: actions/setup-go@0a12ed9d6470c3512128ab8f076f97fbbff3da52 # v5.0.1
with:
go-version: ${{ matrix.go-version }}
- name: Cache Go modules
uses: actions/cache@1bd1e32a3bdc2474371e44e3f675e0e8cb6f3eff # v4.2.0
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ matrix.go-version }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-${{ matrix.go-version }}-
- name: Download dependencies
run: go mod download
- name: Run tests
run: go test -v -race ./...
# Code quality - only run if tests pass
sonarcloud:
name: Code Quality (SonarCloud)
runs-on: ubuntu-latest
needs: test
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
steps:
- name: Checkout code
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
fetch-depth: 0
- name: Download coverage from test job
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
with:
name: coverage-report
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@3b335e14ab49358d133eef17b8c1590fe7c21c0e # v2.2.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
args: >
-Dsonar.projectKey=0x524a_go-onvif
-Dsonar.organization=0x524a
-Dsonar.go.coverage.reportPaths=coverage.out
# Build verification
build:
name: Build
runs-on: ubuntu-latest
needs: test
steps:
- name: Checkout code
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Set up Go
uses: actions/setup-go@0a12ed9d6470c3512128ab8f076f97fbbff3da52 # v5.0.1
with:
go-version: '1.23'
- name: Cache Go modules
uses: actions/cache@1bd1e32a3bdc2474371e44e3f675e0e8cb6f3eff # v4.2.0
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-1.23-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-1.23-
- name: Download dependencies
run: go mod download
- name: Build main packages
run: go build -v ./...
- name: Build examples
run: |
for dir in examples/*/; do
echo "Building $dir"
(cd "$dir" && go build -v .)
done