mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 05:11:34 +00:00
- Add comprehensive GitHub Actions workflows for Go backend - Build workflow with binary compilation and attestation - Test workflow with coverage reporting and race detection - Lint workflow with golangci-lint and security scanning - Docker build workflow with multi-architecture support - Deploy workflow for production deployment - Security workflow with vulnerability scanning - All workflows follow Single Responsibility Principle - Use semantic versioning and latest action versions - Enable security features: OIDC auth, attestations, minimal permissions
115 lines
2.9 KiB
YAML
115 lines
2.9 KiB
YAML
name: Test
|
|
|
|
on:
|
|
push:
|
|
branches: [main, develop]
|
|
pull_request:
|
|
branches: [main, develop]
|
|
|
|
jobs:
|
|
unit-tests:
|
|
name: Unit Tests
|
|
runs-on: ubuntu-latest
|
|
services:
|
|
postgres:
|
|
image: postgres:15
|
|
env:
|
|
POSTGRES_PASSWORD: postgres
|
|
POSTGRES_DB: testdb
|
|
options: >-
|
|
--health-cmd pg_isready
|
|
--health-interval 10s
|
|
--health-timeout 5s
|
|
--health-retries 5
|
|
ports:
|
|
- 5432:5432
|
|
|
|
redis:
|
|
image: redis:7-alpine
|
|
ports:
|
|
- 6379:6379
|
|
options: --health-cmd "redis-cli ping" --health-interval 10s --health-timeout 5s --health-retries 5
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v6
|
|
|
|
- name: Setup Go
|
|
uses: actions/setup-go@v6
|
|
with:
|
|
go-version: "1.25"
|
|
cache: true
|
|
|
|
- name: Install dependencies
|
|
run: go mod download
|
|
|
|
- name: Run tests with coverage
|
|
run: |
|
|
go test -v -race -coverprofile=coverage.out -covermode=atomic ./...
|
|
go tool cover -html=coverage.out -o coverage.html
|
|
|
|
- name: Generate test summary
|
|
if: always()
|
|
run: |
|
|
echo "### Test Results :test_tube:" >> $GITHUB_STEP_SUMMARY
|
|
echo "" >> $GITHUB_STEP_SUMMARY
|
|
echo "- **Coverage**: See artifact for detailed report" >> $GITHUB_STEP_SUMMARY
|
|
echo "- **Race Detection**: Enabled" >> $GITHUB_STEP_SUMMARY
|
|
echo "- **Go Version**: 1.25" >> $GITHUB_STEP_SUMMARY
|
|
|
|
- name: Upload coverage reports
|
|
uses: actions/upload-artifact@v5
|
|
with:
|
|
name: coverage-report
|
|
path: |
|
|
coverage.out
|
|
coverage.html
|
|
retention-days: 30
|
|
|
|
compatibility-matrix:
|
|
name: Go ${{ matrix.go-version }} Compatibility
|
|
runs-on: ubuntu-latest
|
|
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
go-version: ["1.22", "1.23", "1.24", "1.25"]
|
|
services:
|
|
postgres:
|
|
image: postgres:15
|
|
env:
|
|
POSTGRES_PASSWORD: postgres
|
|
POSTGRES_DB: testdb
|
|
options: >-
|
|
--health-cmd pg_isready
|
|
--health-interval 10s
|
|
--health-timeout 5s
|
|
--health-retries 5
|
|
ports:
|
|
- 5432:5432
|
|
|
|
redis:
|
|
image: redis:7-alpine
|
|
ports:
|
|
- 6379:6379
|
|
options: --health-cmd "redis-cli ping" --health-interval 10s --health-timeout 5s --health-retries 5
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v6
|
|
|
|
- name: Setup Go ${{ matrix.go-version }}
|
|
uses: actions/setup-go@v6
|
|
with:
|
|
go-version: ${{ matrix.go-version }}
|
|
cache: true
|
|
|
|
- name: Install dependencies
|
|
run: go mod download
|
|
|
|
- name: Run tests
|
|
run: go test -v -race ./...
|
|
|
|
- name: Build
|
|
run: go build -v ./...
|