Auto-commit #14
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Test Suite | |
| on: | |
| push: | |
| branches: [ main, develop ] | |
| pull_request: | |
| branches: [ main ] | |
| jobs: | |
| unit-tests: | |
| name: Unit Tests | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| go-version: [1.19, 1.20, 1.21] | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: Set up Go | |
| uses: actions/setup-go@v3 | |
| with: | |
| go-version: ${{ matrix.go-version }} | |
| - name: Cache Go modules | |
| uses: actions/cache@v3 | |
| with: | |
| path: ~/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: cd go && go mod download | |
| - name: Run unit tests | |
| run: | | |
| cd go | |
| go test ./coordinatorpkg ./workerpkg ./cachepkg ./monitorpkg -v -race -coverprofile=coverage.out -covermode=atomic | |
| - name: Check coverage | |
| run: | | |
| cd go | |
| go tool cover -func=coverage.out | tail -1 | |
| COVERAGE=$(go tool cover -func=coverage.out | tail -1 | grep -o '[0-9.]*%' | sed 's/%//') | |
| if (( $(echo "$COVERAGE < 90" | bc -l) )); then | |
| echo "Coverage $COVERAGE% is below required 90%" | |
| exit 1 | |
| fi | |
| echo "Coverage $COVERAGE% meets requirements" | |
| - name: Upload coverage to Codecov | |
| uses: codecov/codecov-action@v3 | |
| with: | |
| file: ./go/coverage.out | |
| flags: unittests | |
| name: codecov-umbrella | |
| integration-tests: | |
| name: Integration Tests | |
| runs-on: ubuntu-latest | |
| needs: unit-tests | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: Set up Go | |
| uses: actions/setup-go@v3 | |
| with: | |
| go-version: 1.21 | |
| - name: Cache Go modules | |
| uses: actions/cache@v3 | |
| with: | |
| path: ~/go/pkg/mod | |
| key: ${{ runner.os }}-go-1.21-${{ hashFiles('**/go.sum') }} | |
| restore-keys: | | |
| ${{ runner.os }}-go-1.21- | |
| - name: Download dependencies | |
| run: cd go && go mod download | |
| - name: Run integration tests | |
| run: | | |
| cd go | |
| go test ./tests/integration -v -timeout 60s -coverprofile=integration-coverage.out | |
| - name: Upload integration coverage | |
| uses: codecov/codecov-action@v3 | |
| with: | |
| file: ./go/integration-coverage.out | |
| flags: integration | |
| name: codecov-umbrella | |
| security-tests: | |
| name: Security Tests | |
| runs-on: ubuntu-latest | |
| needs: unit-tests | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: Set up Go | |
| uses: actions/setup-go@v3 | |
| with: | |
| go-version: 1.21 | |
| - name: Cache Go modules | |
| uses: actions/cache@v3 | |
| with: | |
| path: ~/go/pkg/mod | |
| key: ${{ runner.os }}-go-1.21-${{ hashFiles('**/go.sum') }} | |
| restore-keys: | | |
| ${{ runner.os }}-go-1.21- | |
| - name: Download dependencies | |
| run: cd go && go mod download | |
| - name: Run security tests | |
| run: | | |
| cd go | |
| go test ./tests/security -v -timeout 30s -coverprofile=security-coverage.out | |
| - name: Run Gosec Security Scanner | |
| uses: securecodewarrior/github-action-gosec@master | |
| with: | |
| args: './go/...' | |
| - name: Upload security coverage | |
| uses: codecov/codecov-action@v3 | |
| with: | |
| file: ./go/security-coverage.out | |
| flags: security | |
| name: codecov-umbrella | |
| performance-tests: | |
| name: Performance Tests | |
| runs-on: ubuntu-latest | |
| needs: integration-tests | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: Set up Go | |
| uses: actions/setup-go@v3 | |
| with: | |
| go-version: 1.21 | |
| - name: Cache Go modules | |
| uses: actions/cache@v3 | |
| with: | |
| path: ~/go/pkg/mod | |
| key: ${{ runner.os }}-go-1.21-${{ hashFiles('**/go.sum') }} | |
| restore-keys: | | |
| ${{ runner.os }}-go-1.21- | |
| - name: Download dependencies | |
| run: cd go && go mod download | |
| - name: Run performance tests | |
| run: | | |
| cd go | |
| go test ./tests/performance -v -timeout 120s -short -coverprofile=performance-coverage.out | |
| - name: Generate performance report | |
| run: | | |
| cd go | |
| go test ./tests/performance -bench=. -run=^$ -count=3 | tee performance-bench.txt | |
| - name: Upload performance results | |
| uses: actions/upload-artifact@v3 | |
| with: | |
| name: performance-results | |
| path: go/performance-bench.txt | |
| - name: Upload performance coverage | |
| uses: codecov/codecov-action@v3 | |
| with: | |
| file: ./go/performance-coverage.out | |
| flags: performance | |
| name: codecov-umbrella | |
| load-tests: | |
| name: Load Tests | |
| runs-on: ubuntu-latest | |
| needs: integration-tests | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: Set up Go | |
| uses: actions/setup-go@v3 | |
| with: | |
| go-version: 1.21 | |
| - name: Cache Go modules | |
| uses: actions/cache@v3 | |
| with: | |
| path: ~/go/pkg/mod | |
| key: ${{ runner.os }}-go-1.21-${{ hashFiles('**/go.sum') }} | |
| restore-keys: | | |
| ${{ runner.os }}-go-1.21- | |
| - name: Download dependencies | |
| run: cd go && go mod download | |
| - name: Run load tests | |
| run: | | |
| cd go | |
| go test ./tests/load -v -timeout 120s -short -coverprofile=load-coverage.out | |
| - name: Upload load coverage | |
| uses: codecov/codecov-action@v3 | |
| with: | |
| file: ./go/load-coverage.out | |
| flags: load | |
| name: codecov-umbrella | |
| test-summary: | |
| name: Test Summary | |
| runs-on: ubuntu-latest | |
| needs: [unit-tests, integration-tests, security-tests] | |
| if: always() | |
| steps: | |
| - name: Download all coverage reports | |
| uses: actions/download-artifact@v3 | |
| - name: Generate test summary | |
| run: | | |
| echo "# Test Summary" >> $GITHUB_STEP_SUMMARY | |
| echo "| Test Suite | Status |" >> $GITHUB_STEP_SUMMARY | |
| echo "|------------|--------|" >> $GITHUB_STEP_SUMMARY | |
| echo "| Unit Tests | ${{ needs.unit-tests.result }} |" >> $GITHUB_STEP_SUMMARY | |
| echo "| Integration Tests | ${{ needs.integration-tests.result }} |" >> $GITHUB_STEP_SUMMARY | |
| echo "| Security Tests | ${{ needs.security-tests.result }} |" >> $GITHUB_STEP_SUMMARY | |
| if [ "${{ needs.unit-tests.result }}" = "success" ] && \ | |
| [ "${{ needs.integration-tests.result }}" = "success" ] && \ | |
| [ "${{ needs.security-tests.result }}" = "success" ]; then | |
| echo "✅ All critical tests passed!" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "❌ Some tests failed - please review" >> $GITHUB_STEP_SUMMARY | |
| fi | |
| sonarcloud: | |
| name: SonarCloud Analysis | |
| runs-on: ubuntu-latest | |
| needs: [unit-tests, integration-tests, security-tests] | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| steps: | |
| - uses: actions/checkout@v3 | |
| with: | |
| fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis | |
| - name: Set up Go | |
| uses: actions/setup-go@v3 | |
| with: | |
| go-version: 1.21 | |
| - name: Download dependencies | |
| run: cd go && go mod download | |
| - name: Run tests with coverage | |
| run: | | |
| cd go | |
| go test ./... -v -race -coverprofile=sonar-coverage.out -covermode=atomic | |
| - name: SonarCloud Scan | |
| uses: SonarSource/sonarcloud-github-action@master | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |