Add a readme #19
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: CI | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| branches: [main] | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| go-version: ["1.25.1"] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: ${{ matrix.go-version }} | |
| - name: Cache Go modules | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/go/pkg/mod | |
| key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | |
| restore-keys: | | |
| ${{ runner.os }}-go- | |
| - name: Download dependencies | |
| run: go mod download | |
| - name: Verify dependencies | |
| run: go mod verify | |
| - name: Format check | |
| run: | | |
| if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then | |
| echo "Code is not formatted. Run 'go fmt ./...'" | |
| gofmt -s -l . | |
| exit 1 | |
| fi | |
| - name: Vet | |
| run: go vet ./... | |
| - name: Run tests | |
| run: go test -v -race -coverprofile=coverage.out ./... | |
| - name: Generate coverage report | |
| run: go tool cover -html=coverage.out -o coverage.html | |
| - name: Generate coverage summary | |
| if: github.event_name == 'pull_request' | |
| run: | | |
| echo "## 📊 Code Coverage Report" > coverage_summary.md | |
| echo "" >> coverage_summary.md | |
| echo '```' >> coverage_summary.md | |
| go tool cover -func=coverage.out | tail -1 >> coverage_summary.md | |
| echo '```' >> coverage_summary.md | |
| echo "" >> coverage_summary.md | |
| echo "<details>" >> coverage_summary.md | |
| echo "<summary>Coverage by file</summary>" >> coverage_summary.md | |
| echo "" >> coverage_summary.md | |
| echo '```' >> coverage_summary.md | |
| go tool cover -func=coverage.out >> coverage_summary.md | |
| echo '```' >> coverage_summary.md | |
| echo "</details>" >> coverage_summary.md | |
| - name: Add coverage comment to PR | |
| uses: marocchino/sticky-pull-request-comment@v2 | |
| if: github.event_name == 'pull_request' | |
| with: | |
| header: coverage-report | |
| recreate: true | |
| path: coverage_summary.md | |
| - name: Upload coverage reports | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: coverage-report-${{ matrix.go-version }} | |
| path: | | |
| coverage.out | |
| coverage.html | |
| # This job ensures all checks pass before allowing merge | |
| all-checks: | |
| if: always() | |
| runs-on: ubuntu-latest | |
| needs: [test] | |
| steps: | |
| - name: Check all jobs | |
| run: | | |
| if [[ "${{ needs.test.result }}" != "success" ]]; then | |
| echo "Tests failed" | |
| exit 1 | |
| fi | |
| echo "All checks passed!" |