Skip to content

Commit 95d59db

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 f04b4de commit 95d59db

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
@@ -8,14 +8,15 @@ env:
88
TEST_TAG: public.ecr.aws/aws-observability/adot-autoinstrumentation-java:test-v2
99

1010
jobs:
11-
changelog-check:
11+
static-code-checks:
1212
runs-on: ubuntu-latest
1313
steps:
1414
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
1515
with:
1616
fetch-depth: 0
1717

1818
- name: Check CHANGELOG
19+
if: always()
1920
run: |
2021
# Check if PR is from workflows bot or dependabot
2122
if [[ "${{ github.event.pull_request.user.login }}" == "aws-application-signals-bot" ]]; then
@@ -44,6 +45,24 @@ jobs:
4445
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."
4546
exit 1
4647
48+
- name: Check for versioned GitHub actions
49+
if: always()
50+
run: |
51+
# Get changed GitHub workflow/action files
52+
CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }}..HEAD | grep -E "^\.github/(workflows|actions)/.*\.ya?ml$" || true)
53+
54+
if [ -n "$CHANGED_FILES" ]; then
55+
# Check for any versioned actions, excluding comments and this validation script
56+
VIOLATIONS=$(grep -Hn "uses:.*@v" $CHANGED_FILES | grep -v "grep.*uses:.*@v" | grep -v "#.*@v" || true)
57+
if [ -n "$VIOLATIONS" ]; then
58+
echo "Found versioned GitHub actions. Use commit SHAs instead:"
59+
echo "$VIOLATIONS"
60+
exit 1
61+
fi
62+
fi
63+
64+
echo "No versioned actions found in changed files"
65+
4766
testpatch:
4867
name: Test patches applied to dependencies
4968
runs-on: aws-otel-java-instrumentation_ubuntu-latest_32-core
@@ -214,7 +233,7 @@ jobs:
214233

215234
all-pr-checks-pass:
216235
runs-on: ubuntu-latest
217-
needs: [changelog-check, testpatch, build, build-lambda]
236+
needs: [static-code-checks, testpatch, build, build-lambda]
218237
if: always()
219238
steps:
220239
- name: Checkout to get workflow file

0 commit comments

Comments
 (0)