209 lines
5.7 KiB
YAML
209 lines
5.7 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@a4a2eec1d0ddf3f5835416e10cb208206f91ce91 # v5.0.0
|
|
with:
|
|
go-version: '1.23'
|
|
|
|
- name: Cache Go modules
|
|
uses: actions/cache@e5f3f4dc664b57a06a2055cfc9b80cf9f20aba75 # v4.0.1
|
|
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@971c284620f5fc42b58b3b01cc4aefd4b19f4599 # v4.0.0
|
|
with:
|
|
version: v2.0.0
|
|
skip-cache: true
|
|
|
|
# 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@a4a2eec1d0ddf3f5835416e10cb208206f91ce91 # v5.0.0
|
|
with:
|
|
go-version: '1.23'
|
|
|
|
- name: Cache Go modules
|
|
uses: actions/cache@e5f3f4dc664b57a06a2055cfc9b80cf9f20aba75 # v4.0.1
|
|
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@c16abc29c95fcf9174b58eb7e6f695e0d003b6f5 # v4.1.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@26f96dfc338e3cd6585081a28241e5868b2b888f # v4.3.0
|
|
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@a4a2eec1d0ddf3f5835416e10cb208206f91ce91 # v5.0.0
|
|
with:
|
|
go-version: ${{ matrix.go-version }}
|
|
|
|
- name: Cache Go modules
|
|
uses: actions/cache@e5f3f4dc664b57a06a2055cfc9b80cf9f20aba75 # v4.0.1
|
|
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@fb7b1ae3fa6edf41bfe27490ab69d8657bea0656 # v4.1.7
|
|
with:
|
|
name: coverage-report
|
|
|
|
- name: SonarCloud Scan
|
|
uses: SonarSource/sonarcloud-github-action@master
|
|
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@v4
|
|
|
|
- name: Set up Go
|
|
uses: actions/setup-go@v5
|
|
with:
|
|
go-version: '1.23'
|
|
|
|
- name: Cache Go modules
|
|
uses: actions/cache@v4
|
|
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
|