Skip to content

Commit 298b414

Browse files
thpiercejj22ee
authored andcommitted
feat: prevent versioned 3P GitHub actions in PR builds (#1212)
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 my contribution is made under the terms of the Apache 2.0 license.
1 parent 47152b4 commit 298b414

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

.github/workflows/pr-build.yml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@ env:
1414
TEST_TAG: public.ecr.aws/aws-observability/adot-autoinstrumentation-java:test-v2
1515

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

2424
- name: Check CHANGELOG
25+
if: always()
2526
run: |
2627
# Check if PR is from workflows bot or dependabot
2728
if [[ "${{ github.event.pull_request.user.login }}" == "aws-application-signals-bot" ]]; then
@@ -50,6 +51,24 @@ jobs:
5051
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."
5152
exit 1
5253
54+
- name: Check for versioned GitHub actions
55+
if: always()
56+
run: |
57+
# Get changed GitHub workflow/action files
58+
CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }}..HEAD | grep -E "^\.github/(workflows|actions)/.*\.ya?ml$" || true)
59+
60+
if [ -n "$CHANGED_FILES" ]; then
61+
# Check for any versioned actions, excluding comments and this validation script
62+
VIOLATIONS=$(grep -Hn "uses:.*@v" $CHANGED_FILES | grep -v "grep.*uses:.*@v" | grep -v "#.*@v" || true)
63+
if [ -n "$VIOLATIONS" ]; then
64+
echo "Found versioned GitHub actions. Use commit SHAs instead:"
65+
echo "$VIOLATIONS"
66+
exit 1
67+
fi
68+
fi
69+
70+
echo "No versioned actions found in changed files"
71+
5372
testpatch:
5473
name: Test patches applied to dependencies
5574
runs-on: aws-otel-java-instrumentation_ubuntu-latest_32-core
@@ -220,7 +239,7 @@ jobs:
220239

221240
all-pr-checks-pass:
222241
runs-on: ubuntu-latest
223-
needs: [changelog-check, testpatch, build, build-lambda]
242+
needs: [static-code-checks, testpatch, build, build-lambda]
224243
if: always()
225244
steps:
226245
- name: Checkout to get workflow file

0 commit comments

Comments
 (0)