Skip to content

Commit 47bde2b

Browse files
authored
feat: prevent versioned 3P GitHub actions in PR builds (#262)
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 By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
1 parent e8f9d08 commit 47bde2b

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

.github/workflows/pr-build.yml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ permissions:
1616
id-token: write
1717

1818
jobs:
19-
changelog-check:
19+
static-code-checks:
2020
runs-on: ubuntu-latest
2121
steps:
2222
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 #v5.0.0
2323
with:
2424
fetch-depth: 0
2525

2626
- name: Check CHANGELOG
27+
if: always()
2728
run: |
2829
# Check if PR is from workflows bot or dependabot
2930
if [[ "${{ github.event.pull_request.user.login }}" == "aws-application-signals-bot" ]]; then
@@ -51,6 +52,24 @@ jobs:
5152
5253
echo "It looks like you didn't add an entry to CHANGELOG.md. If this change affects the SDK behavior, please update CHANGELOG.md and link this PR in your entry. If this PR does not need a CHANGELOG entry, you can add the 'Skip Changelog' label to this PR."
5354
exit 1
55+
56+
- name: Check for versioned GitHub actions
57+
if: always()
58+
run: |
59+
# Get changed GitHub workflow/action files
60+
CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }}..HEAD | grep -E "^\.github/(workflows|actions)/.*\.ya?ml$" || true)
61+
62+
if [ -n "$CHANGED_FILES" ]; then
63+
# Check for any versioned actions, excluding comments and this validation script
64+
VIOLATIONS=$(grep -Hn "uses:.*@v" $CHANGED_FILES | grep -v "grep.*uses:.*@v" | grep -v "#.*@v" || true)
65+
if [ -n "$VIOLATIONS" ]; then
66+
echo "Found versioned GitHub actions. Use commit SHAs instead:"
67+
echo "$VIOLATIONS"
68+
exit 1
69+
fi
70+
fi
71+
72+
echo "No versioned actions found in changed files"
5473
5574
build:
5675
runs-on: ${{ matrix.os }}

0 commit comments

Comments
 (0)