Skip to content

feat: implement comprehensive API documentation and testing infrastructure (issue #6) #9

feat: implement comprehensive API documentation and testing infrastructure (issue #6)

feat: implement comprehensive API documentation and testing infrastructure (issue #6) #9

Workflow file for this run

name: CI
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
env:
GO_VERSION: '1.24.4'
# CI Strategy:
# - Uses enhanced Makefile targets that adapt behavior based on CI environment
# - Testing follows pyramid approach: many unit tests, some integration tests
# - All jobs use consistent caching with Go version in cache key
# - Dependencies are downloaded once per job and cached across workflow runs
# - Jobs are parallelized where possible but coordinated to maximize cache hits
# - Build job waits for all quality checks (test, lint, security) to complete
jobs:
unit-tests:
name: Unit Tests
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: Verify dependencies
run: go mod verify
- name: Run unit tests with coverage
env:
CI: true
JWT_SECRET_KEY: test-secret-key-for-ci
run: make test
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
file: ./coverage.out
flags: unittests
name: codecov-umbrella
fail_ci_if_error: false
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: Install golangci-lint
run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
- name: Run linting with format check
env:
CI: true
run: make lint
security:
name: Security Scan
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: Install gosec
run: go install github.com/securego/gosec/v2/cmd/gosec@latest
- name: Run security scan
env:
CI: true
run: make security
- name: Upload SARIF file
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: gosec.sarif
build:
name: Build
runs-on: ubuntu-latest
needs: [unit-tests, lint, security]
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: Build API server
run: make build
- name: Test build executable
run: ./bin/voidrunner-api --help || echo "Binary built successfully"
integration-test:
name: Integration Tests
runs-on: ubuntu-latest
needs: [unit-tests]
services:
postgres:
image: postgres:17
env:
POSTGRES_PASSWORD: testpassword
POSTGRES_USER: testuser
POSTGRES_DB: voidrunner_test
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
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 integration tests
env:
CI: true
TEST_DB_HOST: localhost
TEST_DB_PORT: 5432
TEST_DB_USER: testuser
TEST_DB_PASSWORD: testpassword
TEST_DB_NAME: voidrunner_test
TEST_DB_SSLMODE: disable
JWT_SECRET_KEY: test-secret-key-for-integration
run: make test-integration
docs:
name: Documentation
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
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: Install swag
run: go install github.com/swaggo/swag/cmd/swag@latest
- name: Generate API documentation
run: swag init -g cmd/api/main.go -o docs/
- name: Deploy documentation to GitHub Pages
if: success()
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs
destination_dir: api-docs
dependency-review:
name: Dependency Review
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Dependency Review
uses: actions/dependency-review-action@v4
with:
fail-on-severity: moderate
performance:
name: Performance Tests
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
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 benchmark tests
run: go test -bench=. -benchmem ./... -run=^$ | tee benchmark.txt
- name: Store benchmark result
uses: benchmark-action/github-action-benchmark@v1
if: success()
with:
tool: 'go'
output-file-path: benchmark.txt
github-token: ${{ secrets.GITHUB_TOKEN }}
auto-push: true
comment-on-alert: true
alert-threshold: '200%'
fail-on-alert: true