|
5 | 5 | branches: |
6 | 6 | - main |
7 | 7 | tags: |
8 | | - - '*' |
| 8 | + - 'v[0-9]+.[0-9]+.[0-9]+*' # Only semver tags (v1.2.3, v1.2.3-rc1, etc.) |
9 | 9 | pull_request: |
10 | 10 | types: [opened, reopened, synchronize] |
11 | 11 |
|
12 | | -permissions: |
13 | | - contents: write |
14 | | - |
15 | 12 | jobs: |
16 | | - goreleaser: |
| 13 | + # PR and main branch: only build validation, NO goreleaser (prevents hook injection) |
| 14 | + validate: |
| 15 | + if: github.event_name == 'pull_request' || (github.event_name == 'push' && !startsWith(github.ref, 'refs/tags/')) |
17 | 16 | runs-on: ubuntu-latest |
| 17 | + permissions: |
| 18 | + contents: read |
18 | 19 | steps: |
19 | 20 | - name: Checkout |
20 | | - uses: actions/checkout@v4 |
| 21 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
21 | 22 |
|
22 | 23 | - name: Set up Go |
23 | | - uses: actions/setup-go@v4 |
| 24 | + uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0 |
24 | 25 | with: |
25 | 26 | go-version: 1.22 |
26 | 27 |
|
27 | | - - name: Run GoReleaser release (SKIP publish) |
28 | | - uses: goreleaser/goreleaser-action@v5 |
29 | | - if: startsWith(github.ref, 'refs/tags/') != true |
| 28 | + - name: Security scan for dangerous Go patterns |
| 29 | + run: | |
| 30 | + if grep -rn '//go:generate\|import "C"\|#cgo' --include='*.go' .; then |
| 31 | + echo "::error::Detected potentially dangerous Go directive" |
| 32 | + exit 1 |
| 33 | + fi |
| 34 | +
|
| 35 | + - name: Build |
| 36 | + run: go build -v ./... |
| 37 | + |
| 38 | + - name: Test |
| 39 | + run: go test -v ./... |
| 40 | + |
| 41 | + # Release: only on semver tags, with environment protection |
| 42 | + release: |
| 43 | + if: startsWith(github.ref, 'refs/tags/v') |
| 44 | + runs-on: ubuntu-latest |
| 45 | + environment: production |
| 46 | + permissions: |
| 47 | + contents: write |
| 48 | + id-token: write |
| 49 | + steps: |
| 50 | + - name: Checkout |
| 51 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
30 | 52 | with: |
31 | | - distribution: goreleaser |
32 | | - version: latest |
33 | | - args: release --clean --skip=publish --snapshot |
34 | | - env: |
35 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 53 | + fetch-depth: 0 |
| 54 | + |
| 55 | + - name: Set up Go |
| 56 | + uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0 |
| 57 | + with: |
| 58 | + go-version: 1.22 |
36 | 59 |
|
37 | | - - name: Run GoReleaser release |
38 | | - uses: goreleaser/goreleaser-action@v5 |
39 | | - if: startsWith(github.ref, 'refs/tags/') |
| 60 | + - name: Run GoReleaser |
| 61 | + uses: goreleaser/goreleaser-action@9c156ee8a17a598857849441385a2041ef570552 # v6.3.0 |
40 | 62 | with: |
41 | 63 | distribution: goreleaser |
42 | | - version: latest |
| 64 | + version: "2.6.1" |
43 | 65 | args: release --clean |
44 | 66 | env: |
45 | 67 | GITHUB_TOKEN: ${{ secrets.GH_PAT }} |
0 commit comments