Skip to content

Commit f3b0e5b

Browse files
committed
Add GitHub Actions workflow to automate updating
1 parent 99535de commit f3b0e5b

File tree

2 files changed

+125
-0
lines changed

2 files changed

+125
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
if git diff --exit-code LICENSE-3rdparty.csv; then
6+
echo "✅ LICENSE-3rdparty.csv is already up to date"
7+
else
8+
echo "📝 LICENSE-3rdparty.csv was modified by license attribution command"
9+
10+
PR_AUTHOR="${PR_AUTHOR:-}"
11+
PR_USER_TYPE="${PR_USER_TYPE:-}"
12+
13+
if [[ "$PR_USER_TYPE" == "Bot" ]] && [[ "${GITHUB_EVENT_NAME:-}" == "pull_request" ]]; then
14+
echo "🤖 Bot-created PR detected. Auto-committing LICENSE-3rdparty.csv changes..."
15+
16+
git config --local user.email "action@github.com"
17+
git config --local user.name "GitHub Action"
18+
19+
git add LICENSE-3rdparty.csv
20+
git commit -m "Update LICENSE-3rdparty.csv"
21+
22+
git push origin HEAD:${GITHUB_HEAD_REF}
23+
24+
echo "✅ Successfully committed and pushed LICENSE-3rdparty.csv updates"
25+
else
26+
echo "❌ The LICENSE-3rdparty.csv file needs to be updated!"
27+
echo ""
28+
echo "The license attribution command has modified LICENSE-3rdparty.csv."
29+
echo ""
30+
echo "To fix this issue:"
31+
echo "1. Set up dd-license-attribution locally by following the installation instructions in:"
32+
echo " https://github.com/DataDog/dd-license-attribution"
33+
echo "2. Run the license CSV generation command locally:"
34+
echo " dd-license-attribution generate-sbom-csv \\"
35+
echo " --no-scancode-strategy \\"
36+
echo " --no-github-sbom-strategy \\"
37+
echo " https://github.com/datadog/dd-trace-js > LICENSE-3rdparty.csv"
38+
echo "3. Commit the updated LICENSE-3rdparty.csv file"
39+
echo "4. Push your changes"
40+
echo ""
41+
echo "This helps keep the 3rd-party license information accurate."
42+
exit 1
43+
fi
44+
fi
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: Update 3rd-party licenses
2+
3+
on:
4+
pull_request_target:
5+
branches:
6+
- master
7+
paths:
8+
- 'yarn.lock'
9+
10+
jobs:
11+
update-3rdparty-licenses:
12+
runs-on: ubuntu-latest
13+
permissions:
14+
id-token: write
15+
contents: write
16+
pull-requests: write
17+
env:
18+
REPOSITORY_URL: ${{ github.server_url }}/${{ github.repository }}
19+
steps:
20+
- name: Check out PR branch
21+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
22+
with:
23+
ref: ${{ github.event.pull_request.head.sha }}
24+
25+
- name: Get GitHub token with appropriate permissions
26+
uses: DataDog/dd-octo-sts-action@acaa02eee7e3bb0839e4272dacb37b8f3b58ba80 # v1.0.3
27+
id: octo-sts
28+
with:
29+
scope: DataDog
30+
policy: dd-trace-js-license-attribution-read
31+
32+
- name: Set up Python
33+
uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0
34+
with:
35+
python-version: '3.14'
36+
37+
- name: Check out dd-license-attribution
38+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
39+
with:
40+
repository: DataDog/dd-license-attribution
41+
ref: 8a4624fd08a16717ffbf92d389e65fa609a4f067
42+
path: dd-license-attribution
43+
44+
- name: Install dd-license-attribution
45+
working-directory: dd-license-attribution
46+
run: |
47+
pip install .
48+
49+
- name: Create mirrors.json for PR branch
50+
env:
51+
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
52+
HEAD_REF: ${{ github.head_ref }}
53+
run: |
54+
cat > mirrors.json <<EOF
55+
[
56+
{
57+
"original_url": "${REPOSITORY_URL}",
58+
"mirror_url": "${REPOSITORY_URL}",
59+
"ref_mapping": {
60+
"branch:${DEFAULT_BRANCH}": "branch:${HEAD_REF}"
61+
}
62+
}
63+
]
64+
EOF
65+
66+
- name: Regenerate LICENSE-3rdparty.csv
67+
env:
68+
GITHUB_TOKEN: ${{ steps.octo-sts.outputs.token }}
69+
run: |
70+
dd-license-attribution generate-sbom-csv \
71+
--use-mirrors=mirrors.json \
72+
--no-scancode-strategy \
73+
--no-github-sbom-strategy \
74+
"${REPOSITORY_URL}" > LICENSE-3rdparty.csv
75+
76+
- name: Run LICENSE-3rdparty.csv update check
77+
env:
78+
PR_AUTHOR: ${{ github.event.pull_request.user.login }}
79+
PR_USER_TYPE: ${{ github.event.pull_request.user.type }}
80+
GITHUB_EVENT_NAME: ${{ github.event_name }}
81+
run: ./.github/scripts/update-3rdparty-licenses.sh

0 commit comments

Comments
 (0)