295a9948f7
- Add findDataFile() helper to search up directory tree for data files - Fixes tests running from subdirectories (internal/handlers) - Install Chrome in GitHub Actions for PDF generation tests This resolves test failures that have existed since PDF tests were introduced: - Error: 'open data/cv-es.json: no such file or directory' - Error: 'chrome failed to start' Tests now properly locate data files from any working directory and have Chrome available for PDF generation in CI environment.
98 lines
2.7 KiB
YAML
98 lines
2.7 KiB
YAML
name: Test CV Site
|
|
|
|
on:
|
|
pull_request:
|
|
branches: [main, develop]
|
|
push:
|
|
branches: [main, develop]
|
|
|
|
jobs:
|
|
test:
|
|
name: Test on Go ${{ matrix.go-version }}
|
|
runs-on: ubuntu-latest
|
|
strategy:
|
|
matrix:
|
|
go-version: ['1.25.1']
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup Go
|
|
uses: actions/setup-go@v5
|
|
with:
|
|
go-version: ${{ matrix.go-version }}
|
|
cache: true
|
|
|
|
- name: Install dependencies
|
|
run: go mod download
|
|
|
|
- name: Verify dependencies
|
|
run: go mod verify
|
|
|
|
- name: Install Chrome for PDF tests
|
|
run: |
|
|
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
|
|
sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list'
|
|
sudo apt-get update
|
|
sudo apt-get install -y google-chrome-stable
|
|
|
|
- name: Run linter
|
|
uses: golangci/golangci-lint-action@v7
|
|
with:
|
|
version: v2.6.0
|
|
|
|
- name: Run tests with coverage
|
|
run: |
|
|
go test -v -race -coverprofile=coverage.txt -covermode=atomic ./...
|
|
|
|
- name: Generate coverage report
|
|
run: |
|
|
go tool cover -func=coverage.txt | tee coverage-report.txt
|
|
|
|
- name: Check coverage threshold
|
|
run: |
|
|
coverage=$(go tool cover -func=coverage.txt | grep total | awk '{print $3}' | sed 's/%//')
|
|
echo "Total coverage: ${coverage}%"
|
|
echo "COVERAGE=${coverage}" >> $GITHUB_ENV
|
|
if (( $(echo "$coverage < 70" | bc -l) )); then
|
|
echo "⚠️ Coverage ${coverage}% is below target of 70%"
|
|
echo "This is a warning, not a failure (building towards 70% coverage)"
|
|
else
|
|
echo "✅ Coverage ${coverage}% meets or exceeds target"
|
|
fi
|
|
|
|
- name: Upload coverage to Codecov
|
|
uses: codecov/codecov-action@v4
|
|
with:
|
|
files: ./coverage.txt
|
|
flags: unittests
|
|
name: codecov-umbrella
|
|
fail_ci_if_error: false
|
|
|
|
- name: Run benchmarks
|
|
run: |
|
|
go test -bench=. -benchmem ./... | tee benchmark.txt
|
|
|
|
- name: Build binary
|
|
run: |
|
|
go build -v -o cv-server .
|
|
|
|
- name: Upload test artifacts
|
|
uses: actions/upload-artifact@v4
|
|
if: always()
|
|
with:
|
|
name: test-results-go-${{ matrix.go-version }}
|
|
path: |
|
|
coverage.txt
|
|
coverage-report.txt
|
|
benchmark.txt
|
|
retention-days: 30
|
|
|
|
- name: Upload binary artifact
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: cv-server-binary
|
|
path: cv-server
|
|
retention-days: 7
|