Skip to content

Commit ed1fabb

Browse files
committed
feat: pin GitHub Actions to SHA digests and add pin-check workflow
1 parent 3111815 commit ed1fabb

6 files changed

Lines changed: 69 additions & 6 deletions

File tree

.github/workflows/conventional-commits.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
name: PR Title
1414
runs-on: ubuntu-latest
1515
steps:
16-
- uses: amannn/action-semantic-pull-request@v5
16+
- uses: amannn/action-semantic-pull-request@e32d7e603df1aa1ba07e981f2a23455dee596825 # v5
1717
env:
1818
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1919
with:
@@ -33,9 +33,9 @@ jobs:
3333
name: Commit Messages
3434
runs-on: ubuntu-latest
3535
steps:
36-
- uses: actions/checkout@v4
36+
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
3737
with:
3838
fetch-depth: 0
39-
- uses: wagoid/commitlint-github-action@v6
39+
- uses: wagoid/commitlint-github-action@b948419dd99f3fd78a6548d48f94e3df7f6bf3ed # v6
4040
with:
4141
configFile: .commitlintrc.yml

.github/workflows/issues-add-to-project.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
name: Add issue to project
1414
runs-on: ubuntu-latest
1515
steps:
16-
- uses: actions/add-to-project@v1.0.2
16+
- uses: actions/add-to-project@244f685bbc3b7adfa8466e08b698b5577571133e # v1.0.2
1717
with:
1818
project-url: https://github.com/orgs/opendefensecloud/projects/3
1919
github-token: ${{ secrets.ADD_TO_PROJECT_PAT }}

.github/workflows/release-drafter.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
# echo "GHE_HOST=${GITHUB_SERVER_URL##https:\/\/}" >> $GITHUB_ENV
3434

3535
# Drafts your next Release notes as Pull Requests are merged into "master"
36-
- uses: release-drafter/release-drafter@v7
36+
- uses: release-drafter/release-drafter@c2e2804cc59f45f57076a99af580d0fedb697927 # v7
3737
# (Optional) specify config name to use, relative to .github/. Default: release-drafter.yml
3838
# with:
3939
# config-name: my-config.yml
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Update Action Pins
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- ".github/workflows/**"
7+
8+
jobs:
9+
check-pins:
10+
name: Check action pins
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
14+
- name: Verify all actions are pinned to a SHA
15+
run: |
16+
unpinned=$(grep -rE '^\s+(- )?uses: ' .github/workflows/ \
17+
| grep -vE '^\s+(- )?uses: \.\/' \
18+
| grep -vE '@[0-9a-f]{40}($|\s)')
19+
if [[ -n "$unpinned" ]]; then
20+
echo "::error::Found unpinned GitHub Actions (must use SHA digest, not tag):"
21+
echo "$unpinned"
22+
echo ""
23+
echo "Run 'GITHUB_TOKEN=\$(gh auth token) update-action-pins .github/workflows/' to fix."
24+
exit 1
25+
fi

common.mk

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ REPO_RULESET := { \
9999

100100
.PHONY: repo-settings
101101
repo-settings: ## Reconcile GitHub repository settings (labels, merge strategy, branch protection, security)
102-
@REPO=$$($(GH) repo view --json nameWithOwner -q .nameWithOwner) || { echo "error: not a GitHub repository or gh not authenticated"; exit 1; }; \
102+
@$(GH) auth status >/dev/null 2>&1 || { echo "error: gh is not authenticated; run 'gh auth login'"; exit 1; }; \
103+
REPO=$$($(GH) repo view --json nameWithOwner -q .nameWithOwner) || { echo "error: not a GitHub repository"; exit 1; }; \
103104
echo "Reconciling settings for $$REPO..."; \
104105
\
105106
echo " Syncing labels..."; \
@@ -130,8 +131,44 @@ repo-settings: ## Reconcile GitHub repository settings (labels, merge strategy,
130131
echo " Created new ruleset"; \
131132
fi; \
132133
\
134+
echo " Installing update-action-pins workflow..."; \
135+
mkdir -p .github/workflows; \
136+
printf '%s\n' \
137+
'name: Update Action Pins' \
138+
'' \
139+
'on:' \
140+
' pull_request:' \
141+
' paths:' \
142+
' - ".github/workflows/**"' \
143+
'' \
144+
'jobs:' \
145+
' check-pins:' \
146+
' name: Check action pins' \
147+
' runs-on: ubuntu-latest' \
148+
' steps:' \
149+
' - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4' \
150+
' - name: Verify all actions are pinned to a SHA' \
151+
' run: |' \
152+
' unpinned=$$(grep -rE ''^\s+(- )?uses: '' .github/workflows/ \' \
153+
' | grep -vE ''^\s+(- )?uses: \.\/'' \' \
154+
' | grep -vE ''@[0-9a-f]{40}($$|\s)'')' \
155+
' if [[ -n "$$unpinned" ]]; then' \
156+
' echo "::error::Found unpinned GitHub Actions (must use SHA digest, not tag):"' \
157+
' echo "$$unpinned"' \
158+
' echo ""' \
159+
' echo "Run '"'"'GITHUB_TOKEN=$$(gh auth token) update-action-pins .github/workflows/'"'"' to fix."' \
160+
' exit 1' \
161+
' fi' \
162+
> .github/workflows/update-action-pins.yml; \
163+
echo " Wrote .github/workflows/update-action-pins.yml"; \
164+
\
133165
echo "Done."
134166

167+
.PHONY: update-action-pins
168+
update-action-pins: ## Update GitHub Action pins to their latest commit SHA
169+
@$(GH) auth status >/dev/null 2>&1 || { echo "error: gh is not authenticated; run 'gh auth login'"; exit 1; }; \
170+
GITHUB_TOKEN=$(gh auth token) update-action-pins .github/workflows/
171+
135172
##@ General
136173

137174
# The help target prints out all targets with their descriptions organized

example/renovate.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"extends": [
44
"config:recommended"
55
],
6+
"pinDigests": true,
67
"customManagers": [
78
{
89
"customType": "regex",

0 commit comments

Comments
 (0)