Skip to content

Commit 9054f27

Browse files
committed
Add GitHub Actions workflow to automate updating
1 parent b9d4ec5 commit 9054f27

File tree

2 files changed

+123
-0
lines changed

2 files changed

+123
-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: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: Update 3rd-party licenses
2+
3+
on:
4+
pull_request:
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+
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+
30+
- name: Set up Python
31+
uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0
32+
with:
33+
python-version: '3.14'
34+
35+
- name: Check out dd-license-attribution
36+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
37+
with:
38+
repository: DataDog/dd-license-attribution
39+
ref: 848797a26d0cfd009482976d05af7f492bb5242c
40+
path: dd-license-attribution
41+
42+
- name: Install dd-license-attribution
43+
working-directory: dd-license-attribution
44+
run: |
45+
pip install .
46+
47+
- name: Create mirrors.json for PR branch
48+
env:
49+
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
50+
HEAD_REF: ${{ github.head_ref }}
51+
run: |
52+
cat > mirrors.json <<EOF
53+
[
54+
{
55+
"original_url": "${REPOSITORY_URL}",
56+
"mirror_url": "${REPOSITORY_URL}",
57+
"ref_mapping": {
58+
"branch:${DEFAULT_BRANCH}": "branch:${HEAD_REF}"
59+
}
60+
}
61+
]
62+
EOF
63+
64+
- name: Regenerate LICENSE-3rdparty.csv
65+
env:
66+
GITHUB_TOKEN: ${{ steps.octo-sts.outputs.token }}
67+
run: |
68+
dd-license-attribution generate-sbom-csv \
69+
--use-mirrors=mirrors.json \
70+
--no-scancode-strategy \
71+
--no-github-sbom-strategy \
72+
"${REPOSITORY_URL}" > LICENSE-3rdparty.csv
73+
74+
- name: Run LICENSE-3rdparty.csv update check
75+
env:
76+
PR_AUTHOR: ${{ github.event.pull_request.user.login }}
77+
PR_USER_TYPE: ${{ github.event.pull_request.user.type }}
78+
GITHUB_EVENT_NAME: ${{ github.event_name }}
79+
run: ./.github/scripts/update-3rdparty-licenses.sh

0 commit comments

Comments
 (0)