|
| 1 | +name: Lint and Scan |
| 2 | + |
| 3 | +on: |
| 4 | + # Only run on PRs targeting master |
| 5 | + pull_request: |
| 6 | + branches: [ master ] |
| 7 | + types: [opened, synchronize, reopened] |
| 8 | + # For direct pushes to master only |
| 9 | + push: |
| 10 | + branches: [ master ] |
| 11 | + paths-ignore: |
| 12 | + - '**.md' |
| 13 | + - 'docs/**' |
| 14 | + - '.github/**' |
| 15 | + - '!.github/workflows/lint.yml' |
| 16 | + |
| 17 | +# Prevent duplicate workflow runs |
| 18 | +concurrency: |
| 19 | + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} |
| 20 | + cancel-in-progress: true |
| 21 | + |
| 22 | +jobs: |
| 23 | + golangci: |
| 24 | + name: Go Linting |
| 25 | + runs-on: ubuntu-latest |
| 26 | + # Allow job to succeed even with lint issues for now |
| 27 | + continue-on-error: true |
| 28 | + steps: |
| 29 | + - name: Check out code |
| 30 | + uses: actions/checkout@v4 |
| 31 | + |
| 32 | + - name: Set up Go |
| 33 | + uses: actions/setup-go@v5 |
| 34 | + with: |
| 35 | + go-version: 1.24.x |
| 36 | + cache: true |
| 37 | + |
| 38 | + # Simple linting first using standard go tools |
| 39 | + - name: Run go fmt |
| 40 | + run: | |
| 41 | + go fmt ./... |
| 42 | + |
| 43 | + - name: Run go vet |
| 44 | + run: | |
| 45 | + go vet ./... |
| 46 | +
|
| 47 | + - name: Run golangci-lint |
| 48 | + id: lint |
| 49 | + uses: golangci/golangci-lint-action@v7 |
| 50 | + with: |
| 51 | + version: latest |
| 52 | + |
| 53 | + gosec-issues: |
| 54 | + name: Security Scan Issues |
| 55 | + runs-on: ubuntu-latest |
| 56 | + steps: |
| 57 | + - name: Check out code |
| 58 | + uses: actions/checkout@v4 |
| 59 | + |
| 60 | + # Fail only on high severity issues |
| 61 | + - name: Run gosec security scan |
| 62 | + uses: securego/gosec@master |
| 63 | + with: |
| 64 | + args: -exclude-generated -fmt=json -out=results.json ./... |
| 65 | + |
| 66 | + - name: Check for high severity issues |
| 67 | + run: | |
| 68 | + if [ ! -f results.json ]; then |
| 69 | + echo "Error: gosec scan results not found" |
| 70 | + exit 1 |
| 71 | + fi |
| 72 | + |
| 73 | + # Check if any high severity issues exist (level 3) |
| 74 | + HIGH_ISSUES=$(cat results.json | grep -c '"severity":"HIGH"' || true) |
| 75 | + if [ "$HIGH_ISSUES" -gt 0 ]; then |
| 76 | + echo "Found $HIGH_ISSUES high severity security issues!" |
| 77 | + cat results.json | grep -A 5 -B 5 '"severity":"HIGH"' |
| 78 | + exit 1 |
| 79 | + else |
| 80 | + echo "No high severity security issues found." |
| 81 | + fi |
| 82 | + |
| 83 | + - name: Upload security scan results |
| 84 | + if: always() # Run even if previous steps failed |
| 85 | + uses: actions/upload-artifact@v4 |
| 86 | + with: |
| 87 | + name: gosec-results |
| 88 | + path: results.json |
| 89 | + retention-days: 7 |
| 90 | + if-no-files-found: warn |
| 91 | + |
| 92 | + license-check: |
| 93 | + name: License Compliance |
| 94 | + runs-on: ubuntu-latest |
| 95 | + steps: |
| 96 | + - name: Check out code |
| 97 | + uses: actions/checkout@v4 |
| 98 | + |
| 99 | + - name: Set up Go |
| 100 | + uses: actions/setup-go@v5 |
| 101 | + with: |
| 102 | + go-version: 1.24.x |
| 103 | + |
| 104 | + - name: Check License Headers |
| 105 | + run: | |
| 106 | + # Only check Go files that aren't in vendor or generated |
| 107 | + echo "Checking for Apache License headers in Go files..." |
| 108 | + # Store files missing license in a variable |
| 109 | + MISSING_LICENSE=$(find . -name "*.go" -type f -not -path "*/vendor/*" -not -path "*/mocks/*" | xargs grep -L "Licensed under the Apache License" || true) |
| 110 | + |
| 111 | + # If any files are missing license headers, report and exit with error |
| 112 | + if [ -n "$MISSING_LICENSE" ]; then |
| 113 | + echo "ERROR: The following files are missing Apache License headers:" |
| 114 | + echo "$MISSING_LICENSE" |
| 115 | + echo "License check failed. Please add the appropriate license headers." |
| 116 | + exit 1 |
| 117 | + else |
| 118 | + echo "License check passed. All files have proper license headers." |
| 119 | + fi |
0 commit comments