Merge pull request #129 from DFanso/dependabot/go_modules/github.com/… #38
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 | |
| permissions: | |
| contents: read | |
| on: | |
| push: | |
| branches: [ main, develop ] | |
| pull_request: | |
| branches: [ main, develop ] | |
| jobs: | |
| test: | |
| name: Test | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| go-version: ['1.21', '1.22', '1.23'] | |
| steps: | |
| - name: Checkout code | |
| 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: | | |
| ~/.cache/go-build | |
| ~/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: go mod download | |
| - name: Verify dependencies | |
| run: go mod verify | |
| - name: Run go vet | |
| run: go vet ./... | |
| - name: Run go fmt | |
| run: | | |
| # Auto-format all Go files | |
| gofmt -s -w . | |
| # Check if any files were formatted (would indicate pre-existing formatting issues) | |
| if [ -n "$(git status --porcelain 2>/dev/null)" ]; then | |
| echo "Some files were auto-formatted. Consider running 'gofmt -s -w .' locally before committing." | |
| git diff --name-only | |
| fi | |
| # Final check to ensure all files are properly formatted | |
| if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then | |
| echo "The following files are still not formatted after auto-format:" | |
| gofmt -s -l . | |
| exit 1 | |
| fi | |
| - name: Run tests | |
| run: go test -v -race -coverprofile=coverage.out ./... | |
| - name: Run tests with short mode | |
| run: go test -v -short ./... | |
| - name: Upload coverage to Codecov | |
| uses: codecov/codecov-action@v4 | |
| with: | |
| file: ./coverage.out | |
| flags: unittests | |
| name: codecov-umbrella | |
| fail_ci_if_error: false | |
| - name: Generate coverage report | |
| run: go tool cover -html=coverage.out -o coverage.html | |
| - name: Upload coverage report | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: coverage-report-go${{ matrix.go-version }} | |
| path: coverage.html | |
| test-build: | |
| name: Test Build | |
| runs-on: ubuntu-latest | |
| needs: test | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.23' | |
| - name: Download dependencies | |
| run: go mod download | |
| - name: Build | |
| run: go build -v -o commit ./cmd/commit-msg | |
| - name: Verify binary | |
| run: ./commit --help || true |