Skip to content

Commit a897a20

Browse files
authored
chore: simplify update-3rdparty-licenses workflow (#7064)
- Switch from pull_request_target to pull_request trigger - Remove custom GitHub token (dd-octo-sts-action) as it's no longer needed - Simplify permissions to only contents: write - Check out PR branch directly instead of fetching files from it - Remove unnecessary temporary file operations - Remove unused environment variables (PR_AUTHOR, PR_HEAD_SHA)
1 parent 9aaadb5 commit a897a20

File tree

1 file changed

+6
-39
lines changed

1 file changed

+6
-39
lines changed

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

Lines changed: 6 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,21 @@
11
name: Update 3rd-party licenses
22

33
on:
4-
pull_request_target:
5-
branches:
6-
- master
4+
pull_request:
75
paths:
86
- 'yarn.lock'
97

108
jobs:
119
update-3rdparty-licenses:
1210
runs-on: ubuntu-latest
1311
permissions:
14-
id-token: write
1512
contents: write
16-
pull-requests: write
1713
env:
1814
REPOSITORY_URL: ${{ github.server_url }}/${{ github.repository }}
1915
steps:
20-
- name: Check out base branch
16+
- name: Check out PR branch
2117
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
2218

23-
- name: Get GitHub token with appropriate permissions
24-
uses: DataDog/dd-octo-sts-action@acaa02eee7e3bb0839e4272dacb37b8f3b58ba80 # v1.0.3
25-
id: octo-sts
26-
with:
27-
scope: DataDog
28-
policy: dd-trace-js-license-attribution-read
29-
3019
- name: Set up Python
3120
uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0
3221
with:
@@ -62,56 +51,34 @@ jobs:
6251
EOF
6352
6453
- name: Regenerate LICENSE-3rdparty.csv
65-
env:
66-
GITHUB_TOKEN: ${{ steps.octo-sts.outputs.token }}
6754
run: |
6855
dd-license-attribution generate-sbom-csv \
6956
--use-mirrors=mirrors.json \
7057
--no-scancode-strategy \
7158
--no-github-sbom-strategy \
7259
--yarn-subdir vendor \
73-
"${REPOSITORY_URL}" > LICENSE-3rdparty.csv.generated
74-
75-
- name: Fetch files from PR branch
76-
run: |
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
60+
"${REPOSITORY_URL}" > LICENSE-3rdparty.csv
8561
8662
- name: Append vendored dependencies from PR
8763
run: |
88-
cat vendored-dependencies.csv.pr >> LICENSE-3rdparty.csv.generated
64+
cat .github/vendored-dependencies.csv >> LICENSE-3rdparty.csv
8965
9066
- name: Run LICENSE-3rdparty.csv update check
9167
env:
92-
PR_AUTHOR: ${{ github.event.pull_request.user.login }}
9368
PR_USER_TYPE: ${{ github.event.pull_request.user.type }}
9469
GITHUB_EVENT_NAME: ${{ github.event_name }}
9570
GITHUB_HEAD_REF: ${{ github.head_ref }}
96-
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
9771
run: |
9872
set -e
9973
100-
if diff --ignore-space-at-eol LICENSE-3rdparty.csv.generated LICENSE-3rdparty.csv.pr > /dev/null; then
74+
if git diff --ignore-space-at-eol --exit-code LICENSE-3rdparty.csv; then
10175
echo "✅ LICENSE-3rdparty.csv is already up to date"
10276
else
10377
echo "📝 LICENSE-3rdparty.csv was modified by license attribution command"
10478
105-
if [[ "$PR_USER_TYPE" == "Bot" ]] && [[ "${GITHUB_EVENT_NAME}" == "pull_request_target" ]]; then
79+
if [[ "$PR_USER_TYPE" == "Bot" ]] && [[ "${GITHUB_EVENT_NAME}" == "pull_request" ]]; then
10680
echo "🤖 Bot-created PR detected. Auto-committing LICENSE-3rdparty.csv changes..."
10781
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-
11582
git config --local user.email "action@github.com"
11683
git config --local user.name "GitHub Action"
11784

0 commit comments

Comments
 (0)