Skip to content

Commit b95a717

Browse files
authored
chore: refactor update-3rdparty-licenses workflow (#7061)
- Change checkout to base branch and fetch PR files as needed for comparison - Fix event name check from pull_request to pull_request_target
1 parent 2ce2872 commit b95a717

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

.github/workflows/update-3rdparty-licenses.yml

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@ jobs:
1717
env:
1818
REPOSITORY_URL: ${{ github.server_url }}/${{ github.repository }}
1919
steps:
20-
- name: Check out PR branch
20+
- name: Check out base branch
2121
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
22-
with:
23-
ref: ${{ github.event.pull_request.head.sha }}
2422

2523
- name: Get GitHub token with appropriate permissions
2624
uses: DataDog/dd-octo-sts-action@acaa02eee7e3bb0839e4272dacb37b8f3b58ba80 # v1.0.3
@@ -72,29 +70,48 @@ jobs:
7270
--no-scancode-strategy \
7371
--no-github-sbom-strategy \
7472
--yarn-subdir vendor \
75-
"${REPOSITORY_URL}" > LICENSE-3rdparty.csv
73+
"${REPOSITORY_URL}" > LICENSE-3rdparty.csv.generated
7674
77-
- name: Append vendored dependencies
75+
- name: Fetch files from PR branch
7876
run: |
79-
cat .github/vendored-dependencies.csv >> LICENSE-3rdparty.csv
77+
# Fetch the PR branch
78+
git fetch origin ${{ github.event.pull_request.head.sha }}
79+
80+
# Fetch vendored-dependencies.csv from PR branch
81+
git show ${{ github.event.pull_request.head.sha }}:.github/vendored-dependencies.csv > vendored-dependencies.csv.pr || touch vendored-dependencies.csv.pr
82+
83+
# Fetch LICENSE-3rdparty.csv from PR branch for comparison
84+
git show ${{ github.event.pull_request.head.sha }}:LICENSE-3rdparty.csv > LICENSE-3rdparty.csv.pr || touch LICENSE-3rdparty.csv.pr
85+
86+
- name: Append vendored dependencies from PR
87+
run: |
88+
cat vendored-dependencies.csv.pr >> LICENSE-3rdparty.csv.generated
8089
8190
- name: Run LICENSE-3rdparty.csv update check
8291
env:
8392
PR_AUTHOR: ${{ github.event.pull_request.user.login }}
8493
PR_USER_TYPE: ${{ github.event.pull_request.user.type }}
8594
GITHUB_EVENT_NAME: ${{ github.event_name }}
8695
GITHUB_HEAD_REF: ${{ github.head_ref }}
96+
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
8797
run: |
8898
set -e
8999
90-
if git diff --ignore-space-at-eol --exit-code LICENSE-3rdparty.csv; then
100+
if diff --ignore-space-at-eol LICENSE-3rdparty.csv.generated LICENSE-3rdparty.csv.pr > /dev/null; then
91101
echo "✅ LICENSE-3rdparty.csv is already up to date"
92102
else
93103
echo "📝 LICENSE-3rdparty.csv was modified by license attribution command"
94104
95-
if [[ "$PR_USER_TYPE" == "Bot" ]] && [[ "${GITHUB_EVENT_NAME}" == "pull_request" ]]; then
105+
if [[ "$PR_USER_TYPE" == "Bot" ]] && [[ "${GITHUB_EVENT_NAME}" == "pull_request_target" ]]; then
96106
echo "🤖 Bot-created PR detected. Auto-committing LICENSE-3rdparty.csv changes..."
97107
108+
# Checkout the PR branch for committing
109+
git fetch origin ${PR_HEAD_SHA}
110+
git checkout ${PR_HEAD_SHA}
111+
112+
# Move the generated file into place
113+
mv LICENSE-3rdparty.csv.generated LICENSE-3rdparty.csv
114+
98115
git config --local user.email "action@github.com"
99116
git config --local user.name "GitHub Action"
100117

0 commit comments

Comments
 (0)