Skip to content

Commit a7bc14c

Browse files
authored
feat: prevent versioned 3P GitHub actions in PR builds (#457)
Add validation step to require commit SHAs instead of version tags for third-party GitHub actions in workflow files. Repo config `Require actions to be pinned to a full-length commit SHA` will protect against this if we missed any others. ### Testing done * See: aws-observability/aws-otel-python-instrumentation#475 *Rollback procedure:* Git revert - no risk *Ensure you've run the following tests on your changes and include the link below:* pr workflow sufficient By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 5578257 commit a7bc14c

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

.github/workflows/pr-build.yml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,31 @@ on:
66
- main
77

88
jobs:
9+
static-code-checks:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
13+
with:
14+
fetch-depth: 0
15+
16+
- name: Check for versioned GitHub actions
17+
if: always()
18+
run: |
19+
# Get changed GitHub workflow/action files
20+
CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }}..HEAD | grep -E "^\.github/(workflows|actions)/.*\.ya?ml$" || true)
21+
22+
if [ -n "$CHANGED_FILES" ]; then
23+
# Check for any versioned actions, excluding comments and this validation script
24+
VIOLATIONS=$(grep -Hn "uses:.*@v" $CHANGED_FILES | grep -v "grep.*uses:.*@v" | grep -v "#.*@v" || true)
25+
if [ -n "$VIOLATIONS" ]; then
26+
echo "Found versioned GitHub actions. Use commit SHAs instead:"
27+
echo "$VIOLATIONS"
28+
exit 1
29+
fi
30+
fi
31+
32+
echo "No versioned actions found in changed files"
33+
934
build:
1035
name: Gradle Build
1136
runs-on: ubuntu-latest
@@ -25,7 +50,7 @@ jobs:
2550

2651
all-pr-checks-pass:
2752
runs-on: ubuntu-latest
28-
needs: [build]
53+
needs: [build, static-code-checks]
2954
if: always()
3055
steps:
3156
- name: Checkout to get workflow file

0 commit comments

Comments
 (0)