@@ -19,31 +19,12 @@ permissions:
1919 contents : read
2020
2121jobs :
22- REUSE :
23- runs-on : ubuntu-latest
24- steps :
25- - name : Harden Runner
26- uses : step-security/harden-runner@a5ad31d6a139d249332a2605b85202e8c0b78450 # v2.19.1
27- with :
28- egress-policy : audit
29-
30- - name : Checkout
31- uses : actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
32- with :
33- fetch-depth : 1
34-
35- - name : REUSE Compliance Check
36- uses : fsfe/reuse-action@676e2d560c9a403aa252096d99fcab3e1132b0f5 # v6.0.0
37-
38- CheckSignedOffCommit :
39- if : >
40- github.event_name == 'push' &&
41- !contains(github.actor, '[bot]') &&
42- !contains(github.event.pusher.name, '[bot]') &&
43- github.event.pusher.name != 'web-flow'
22+ CheckSignedOff :
23+ if : github.event_name != 'pull_request' || !contains(github.event.pull_request.labels.*.name, 'bypass-dco')
4424 runs-on : ubuntu-latest
4525 permissions :
4626 contents : read
27+ pull-requests : read
4728 steps :
4829 - name : Harden Runner
4930 uses : step-security/harden-runner@a5ad31d6a139d249332a2605b85202e8c0b78450 # v2.19.1
5637 fetch-depth : 0
5738
5839 - name : Determine pushed commits
59- id : range
40+ if : >
41+ github.event_name == 'push' &&
42+ !contains(github.actor, '[bot]') &&
43+ !contains(github.event.pusher.name, '[bot]') &&
44+ github.event.pusher.name != 'web-flow'
6045 env :
6146 # Use GitHub-provided SHAs to build the range for this push
6247 BEFORE : ${{ github.event.before }}
@@ -72,10 +57,25 @@ jobs:
7257 git rev-list --no-merges "$BEFORE".."$AFTER" > shas.txt
7358 fi
7459
60+ - name : Get PR commits
61+ if : github.event_name == 'pull_request'
62+ env :
63+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
64+ run : |
65+ set -euo pipefail
66+
67+ # Fetch all commits of the PR with pagination and extract SHAs
68+ gh api -H "Accept: application/vnd.github+json" --paginate \
69+ repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/commits \
70+ | jq -r '.[].sha' > shas.txt
71+
7572 - name : Check for Signed-off-by
7673 env :
7774 GH_ACTOR : ${{ github.actor }}
78- GH_NAME : ${{ github.event.pusher.name }}
75+ GH_NAME : ${{ github.event.name == 'push' && github.event.pusher.name
76+ || github.event.pull_request.user.login }}
77+ GH_NAME_SOURCE : ${{ github.event_name == 'push' && 'github.event.pusher.name'
78+ || 'github.event.pull_request.user.login' }}
7979 run : |
8080 set -euo pipefail
8181 missing=""
@@ -102,27 +102,51 @@ jobs:
102102 echo "Commit $sha missing Signed-off-by"
103103 missing="true"
104104
105- echo " Committer name: $committer_name"
106- echo " Committer email: $committer_email"
107- echo " github.actor: $GH_ACTOR"
108- echo "github.event.pusher.name: $GH_NAME"
105+ printf "%-38s %s" " Committer name:" " $committer_name"
106+ printf "%-38s %s" " Committer email:" " $committer_email"
107+ printf "%-38s %s" " github.actor:" " $GH_ACTOR"
108+ printf "%-38s %s" "$GH_NAME_SOURCE:" " $GH_NAME"
109109 fi
110110 done < shas.txt
111111
112112 if [ "$missing" = "true" ]
113113 then
114- echo "DCO check failed on push "
114+ echo "DCO check failed for commits "
115115 exit 1
116116 fi
117117
118- echo "All pushed commits are signed"
118+ echo "All commits are signed"
119+
120+ FormatCheck :
121+ strategy :
122+ matrix :
123+ go-version :
124+ - " stable"
125+ runs-on : ubuntu-latest
126+ steps :
127+ - name : Harden Runner
128+ uses : step-security/harden-runner@a5ad31d6a139d249332a2605b85202e8c0b78450 # v2.19.1
129+ with :
130+ egress-policy : audit
131+
132+ - name : Install Go
133+ uses : actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
134+ with :
135+ go-version : ${{matrix.go-version}}
136+
137+ - name : Checkout
138+ uses : actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
139+ with :
140+ fetch-depth : 1
141+
142+ - name : FormatCheck
143+ run : if [ `go fmt ./... | wc -l` -gt 0 ] ; then echo "Found unformatted code" ; exit 1 ; else exit 0 ; fi
119144
120- CheckSignedOffPullRequest :
121- if : github.event_name == 'pull_request' && !contains(github.event.pull_request.labels.*.name, 'bypass-dco')
145+ GolangCI :
122146 runs-on : ubuntu-latest
123147 permissions :
124148 contents : read
125- pull-requests : read
149+ security-events : write
126150 steps :
127151 - name : Harden Runner
128152 uses : step-security/harden-runner@a5ad31d6a139d249332a2605b85202e8c0b78450 # v2.19.1
@@ -132,61 +156,61 @@ jobs:
132156 - name : Checkout
133157 uses : actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
134158 with :
135- fetch-depth : 0
159+ fetch-depth : 1
136160
137- - name : Get PR commits
138- env :
139- GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
140- run : |
141- set -euo pipefail
142- gh --version
143- jq --version
161+ - name : Run golangci-lint
162+ uses : golangci/golangci-lint-action@1e7e51e771db61008b38414a730f564565cf7c20 # v9.2.0
163+ with :
164+ version : latest
165+ args : --timeout=5m --output.sarif.path=golangci-lint-results.sarif --output.text.path=stdout
144166
145- # Fetch all commits of the PR with pagination and extract SHAs
146- gh api -H "Accept: application/vnd. github+json" --paginate \
147- repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/commits \
148- | jq -r '.[].sha' > shas.txt
167+ - name : Upload golangci-lint results to GitHub Security tab
168+ uses : github/codeql-action/upload-sarif@95e58e9a2cdfd71adc6e0353d5c52f41a045d225 # v4.35.2
169+ with :
170+ sarif_file : golangci-lint-results.sarif
149171
150- - name : Check for Signed-off-by
151- env :
152- GH_ACTOR : ${{ github.actor }}
153- GH_NAME : ${{ github.event.pull_request.user.login}}
154- run : |
155- set -euo pipefail
156- missing=""
172+ REUSE :
173+ runs-on : ubuntu-latest
174+ steps :
175+ - name : Harden Runner
176+ uses : step-security/harden-runner@a5ad31d6a139d249332a2605b85202e8c0b78450 # v2.19.1
177+ with :
178+ egress-policy : audit
157179
158- while read -r sha
159- do
160- [ -n "$sha" ] || continue
180+ - name : Checkout
181+ uses : actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
182+ with :
183+ fetch-depth : 1
161184
162- # Skip commits from bots
163- committer_name=`git log --format=%cn -n 1 "$sha"`
164- committer_email=`git log --format=%ce -n 1 "$sha"`
165- if echo "$committer_name" | grep -Fq '[bot]' \
166- || [ "$committer_name" = "web-flow" ] \
167- || echo "$committer_email" | grep -Eqi 'noreply@github\.com$|@users\.noreply\.github\.com$'
168- then
169- echo "Skipping commit $sha from $committer_name <$committer_email>"
170- continue
171- fi
185+ - name : REUSE Compliance Check
186+ uses : fsfe/reuse-action@676e2d560c9a403aa252096d99fcab3e1132b0f5 # v6.0.0
172187
173- msg=`git log --format=%B -n 1 "$sha"`
188+ StaticCheck :
189+ strategy :
190+ matrix :
191+ go-version :
192+ - " stable"
193+ runs-on : ubuntu-latest
194+ steps :
195+ - name : Harden Runner
196+ uses : step-security/harden-runner@a5ad31d6a139d249332a2605b85202e8c0b78450 # v2.19.1
197+ with :
198+ egress-policy : audit
174199
175- if ! printf '%s' "$msg" | grep -Eqi '^[[:space:]]*Signed[- ]off[- ]by:'
176- then
177- echo "Commit $sha missing Signed-off-by"
178- missing="true"
200+ - name : Install Go
201+ uses : actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
202+ with :
203+ go-version : ${{matrix.go-version}}
179204
180- echo "Committer name: $committer_name"
181- echo "Committer email: $committer_email"
182- echo "github.actor: $GH_ACTOR"
183- echo "github.event.pull_request.user.login: $GH_NAME"
184- fi
185- done < shas.txt
205+ - name : Checkout
206+ uses : actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
207+ with :
208+ fetch-depth : 1
186209
187- if [ "$missing" = "true" ]
188- then
189- echo "DCO check failed"; exit 1
190- fi
210+ - name : StaticCheck
211+ uses : dominikh/staticcheck-action@9716614d4101e79b4340dd97b10e54d68234e431 # v1.4.1
212+ with :
213+ version : latest
214+ install-go : false
215+ cache-key : ${{matrix.go-version}}
191216
192- echo "All commits are signed"
0 commit comments