Skip to content

Commit 3e427c1

Browse files
authored
Merge pull request ceph#65720 from rhcs-dashboard/fix-73307-main
.github: pin GH Actions to SHA-1 commit
2 parents cfee77c + e936cab commit 3e427c1

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

.github/workflows/qa-symlink.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ jobs:
1414
runs-on: ubuntu-latest
1515
steps:
1616
- name: checkout PR HEAD
17-
uses: actions/checkout@v4
17+
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4
1818
with:
1919
path: head
2020

2121
- name: checkout base
22-
uses: actions/checkout@v4
22+
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4
2323
with:
2424
path: base
2525
ref: ${{ github.base_ref }}

src/script/pin-gh-workflow-deps.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
WORKFLOWS_DIR="${1:-.}/.github/workflows"
5+
6+
echo "Scanning workflows in: $WORKFLOWS_DIR"
7+
8+
# Recursively grep workflow files for actions not pinned to SHA-1
9+
grep -Prno --include="*.yml" --include="*.yaml" 'uses:\s*([^/]+)/([^@]+)@([^[:space:]]+)' "${WORKFLOWS_DIR}" | \
10+
while IFS=: read -r file _line_num uses_line; do
11+
echo -n "$file - "
12+
# Extract owner/repo/version
13+
if [[ "$uses_line" =~ uses:\ ([^/]+)/([^@]+)@([^[:space:]]+) ]]; then
14+
owner="${BASH_REMATCH[1]}"
15+
repo="${BASH_REMATCH[2]}"
16+
version="${BASH_REMATCH[3]}"
17+
action="$owner/$repo"
18+
echo -n "$owner/$repo: "
19+
else
20+
echo "Failed to parse line: $uses_line [FAIL]"
21+
continue
22+
fi
23+
24+
# Skip if already pinned to SHA
25+
if [[ "$version" =~ ^[0-9a-f]{40}$ ]]; then
26+
echo "SHA-1 pinned: $version [OK]"
27+
continue
28+
else
29+
echo -n "Tag pinned: $version [WARNING], "
30+
fi
31+
32+
api_url="https://api.github.com/repos/$owner/$repo/git/ref/tags/$version"
33+
34+
# Get full SHA
35+
sha=$(curl -s "$api_url" | jq -r '.object.sha')
36+
if [[ "$sha" == "null" || -z "$sha" ]]; then
37+
echo "Could not resolve $action@$version [FAIL]"
38+
continue
39+
fi
40+
41+
echo "Replacing $version$sha [OK]"
42+
43+
# Precise sed replacement: match 'uses:' literally and append comment
44+
sed -i.bak "s|uses:\s*$action@$version|uses: $action@$sha # $version|g" "$file"
45+
done

0 commit comments

Comments
 (0)