Enhance CI/CD workflows and development environment #10
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: Unit Tests | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - "hk/**" | |
| - "feature/**" | |
| pull_request: | |
| branches: | |
| - main | |
| # Cancel in-progress runs for the same workflow and ref | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| permissions: | |
| contents: read | |
| checks: write | |
| pull-requests: write | |
| jobs: | |
| test: | |
| name: Test (Go ${{ matrix.go-version }}) | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 15 | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| go-version: ["1.25.2", "1.25.x"] | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup Go ${{ matrix.go-version }} | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: ${{ matrix.go-version }} | |
| cache: true | |
| cache-dependency-path: | | |
| go.sum | |
| - name: Cache test binaries | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/go/bin | |
| ~/.cache/go-build | |
| key: ${{ runner.os }}-go-${{ matrix.go-version }}-test-${{ hashFiles('**/go.sum') }} | |
| restore-keys: | | |
| ${{ runner.os }}-go-${{ matrix.go-version }}-test- | |
| ${{ runner.os }}-go-${{ matrix.go-version }}- | |
| - name: Download dependencies | |
| run: go mod download && go mod verify | |
| - name: Run tests with coverage | |
| run: | | |
| make test | |
| - name: Generate coverage report | |
| if: matrix.go-version == '1.25.2' | |
| run: | | |
| go tool cover -html=cover.out -o coverage.html | |
| go tool cover -func=cover.out -o coverage.txt | |
| - name: Display coverage summary | |
| if: matrix.go-version == '1.25.2' | |
| run: | | |
| echo "📊 Coverage Summary:" | |
| tail -n 1 coverage.txt | |
| - name: Upload coverage to artifacts | |
| if: matrix.go-version == '1.25.2' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: coverage-reports | |
| path: | | |
| cover.out | |
| coverage.html | |
| coverage.txt | |
| retention-days: 30 | |
| - name: Upload coverage to Codecov | |
| if: matrix.go-version == '1.25.2' | |
| uses: codecov/codecov-action@v4 | |
| with: | |
| files: ./cover.out | |
| flags: unittests | |
| name: codecov-umbrella | |
| fail_ci_if_error: false | |
| env: | |
| CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} | |
| test-race: | |
| name: Race Detection | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 20 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version-file: go.mod | |
| cache: true | |
| - name: Run tests with race detector | |
| run: | | |
| go test -race -short ./... |