|
| 1 | +name: CI |
| 2 | + |
| 3 | +concurrency: |
| 4 | + group: ci-${{ github.ref }} |
| 5 | + cancel-in-progress: true |
| 6 | + |
| 7 | +on: |
| 8 | + push: |
| 9 | + branches: ["*"] |
| 10 | + pull_request: |
| 11 | + branches: ["*"] |
| 12 | + |
| 13 | +jobs: |
| 14 | + lint: |
| 15 | + name: Static Code Analysis |
| 16 | + runs-on: ubuntu-latest |
| 17 | + steps: |
| 18 | + - name: Checkout repository |
| 19 | + uses: actions/checkout@v4 |
| 20 | + |
| 21 | + - name: Set up Go |
| 22 | + uses: actions/setup-go@v5 |
| 23 | + with: |
| 24 | + go-version: "1.23" |
| 25 | + cache: true |
| 26 | + |
| 27 | + - name: Check Formatting (gofmt) |
| 28 | + run: | |
| 29 | + unformatted=$(gofmt -l .) |
| 30 | + if [ -n "$unformatted" ]; then |
| 31 | + echo "The following files are not formatted correctly:" |
| 32 | + echo "$unformatted" |
| 33 | + echo "Please run 'gofmt -w .' locally to fix them." |
| 34 | + exit 1 |
| 35 | + fi |
| 36 | +
|
| 37 | + - name: Run golangci-lint |
| 38 | + uses: golangci/golangci-lint-action@v6 |
| 39 | + with: |
| 40 | + version: latest |
| 41 | + args: --config=.golangci.yml |
| 42 | + |
| 43 | + vulncheck: |
| 44 | + name: Security Vulnerability Scan |
| 45 | + runs-on: ubuntu-latest |
| 46 | + steps: |
| 47 | + - name: Checkout repository |
| 48 | + uses: actions/checkout@v4 |
| 49 | + |
| 50 | + - name: Set up Go |
| 51 | + uses: actions/setup-go@v5 |
| 52 | + with: |
| 53 | + go-version: "1.23" |
| 54 | + cache: true |
| 55 | + |
| 56 | + - name: Run govulncheck |
| 57 | + run: | |
| 58 | + go install golang.org/x/vuln/cmd/govulncheck@latest |
| 59 | + govulncheck ./... |
| 60 | +
|
| 61 | + test: |
| 62 | + name: Build & Test |
| 63 | + runs-on: ubuntu-latest |
| 64 | + needs: [lint, vulncheck] |
| 65 | + steps: |
| 66 | + - name: Checkout repository |
| 67 | + uses: actions/checkout@v4 |
| 68 | + |
| 69 | + - name: Set up Go |
| 70 | + uses: actions/setup-go@v5 |
| 71 | + with: |
| 72 | + go-version: "1.23" |
| 73 | + cache: true |
| 74 | + |
| 75 | + - name: Download Go dependencies |
| 76 | + run: go mod download |
| 77 | + |
| 78 | + - name: Build Project |
| 79 | + run: go build -v ./... |
| 80 | + |
| 81 | + - name: Run Unit Tests |
| 82 | + run: go test -v -race -coverprofile=coverage.out -covermode=atomic ./... |
| 83 | + |
| 84 | + - name: Generate Coverage Summary |
| 85 | + if: always() |
| 86 | + run: | |
| 87 | + if [ -f coverage.out ]; then |
| 88 | + echo "### Test Coverage Summary" >> $GITHUB_STEP_SUMMARY |
| 89 | + echo '```' >> $GITHUB_STEP_SUMMARY |
| 90 | + go tool cover -func=coverage.out >> $GITHUB_STEP_SUMMARY |
| 91 | + echo '```' >> $GITHUB_STEP_SUMMARY |
| 92 | + else |
| 93 | + echo "### Test Coverage Summary" >> $GITHUB_STEP_SUMMARY |
| 94 | + echo "No coverage file found." >> $GITHUB_STEP_SUMMARY |
| 95 | + fi |
0 commit comments