-
Notifications
You must be signed in to change notification settings - Fork 406
116 lines (101 loc) · 4.35 KB
/
Copy pathupdate-3rdparty-licenses.yml
File metadata and controls
116 lines (101 loc) · 4.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
name: Update 3rd-party licenses
on:
pull_request:
paths:
- "yarn.lock"
jobs:
update-3rdparty-licenses:
runs-on: ubuntu-latest
permissions:
contents: write
env:
REPOSITORY_URL: ${{ github.server_url }}/${{ github.repository }}
steps:
- name: Check out PR branch
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Set up Python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: "3.14"
- name: Check out dd-license-attribution
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
repository: DataDog/dd-license-attribution
ref: 224a89cb69d3143e8aa4640405037cf9c233ddf5
path: dd-license-attribution
- name: Install dd-license-attribution
working-directory: dd-license-attribution
run: |
pip install .
- name: Create mirrors.json for PR branch
env:
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
HEAD_REF: ${{ github.head_ref }}
run: |
cat > mirrors.json <<EOF
[
{
"original_url": "${REPOSITORY_URL}",
"mirror_url": "${REPOSITORY_URL}",
"ref_mapping": {
"branch:${DEFAULT_BRANCH}": "branch:${HEAD_REF}"
}
}
]
EOF
- name: Regenerate LICENSE-3rdparty.csv
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
dd-license-attribution generate-sbom-csv \
--use-mirrors=mirrors.json \
--no-scancode-strategy \
--no-github-sbom-strategy \
--yarn-subdir vendor \
"${REPOSITORY_URL}" > LICENSE-3rdparty.csv
- name: Append vendored dependencies from PR
run: |
cat .github/vendored-dependencies.csv >> LICENSE-3rdparty.csv
- name: Run LICENSE-3rdparty.csv update check
env:
PR_USER_TYPE: ${{ github.event.pull_request.user.type }}
GITHUB_EVENT_NAME: ${{ github.event_name }}
GITHUB_HEAD_REF: ${{ github.head_ref }}
PR_HEAD_REPO: ${{ github.event.pull_request.head.repo.full_name }}
BASE_REPO: ${{ github.repository }}
run: |
set -e
if git diff --ignore-space-at-eol --exit-code LICENSE-3rdparty.csv; then
echo "✅ LICENSE-3rdparty.csv is already up to date"
else
echo "📝 LICENSE-3rdparty.csv was modified by license attribution command"
if [[ "$PR_USER_TYPE" == "Bot" ]] && [[ "${GITHUB_EVENT_NAME}" == "pull_request" ]] && [[ "$PR_HEAD_REPO" == "$BASE_REPO" ]]; then
echo "🤖 Bot-created PR detected. Auto-committing LICENSE-3rdparty.csv changes..."
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add LICENSE-3rdparty.csv
git commit -m "Update LICENSE-3rdparty.csv"
git push origin HEAD:${GITHUB_HEAD_REF}
echo "✅ Successfully committed and pushed LICENSE-3rdparty.csv updates"
else
echo "❌ The LICENSE-3rdparty.csv file needs to be updated!"
echo ""
echo "The license attribution command has modified LICENSE-3rdparty.csv."
echo ""
echo "To fix this issue:"
echo "1. Set up dd-license-attribution locally by following the installation instructions in:"
echo " https://github.com/DataDog/dd-license-attribution"
echo "2. Run the license CSV generation command locally:"
echo " dd-license-attribution generate-sbom-csv \\"
echo " --no-scancode-strategy \\"
echo " --no-github-sbom-strategy \\"
echo " https://github.com/datadog/dd-trace-js > LICENSE-3rdparty.csv"
echo "3. Append vendored dependencies:"
echo " cat .github/vendored-dependencies.csv >> LICENSE-3rdparty.csv"
echo "4. Commit the updated LICENSE-3rdparty.csv file"
echo "5. Push your changes"
echo ""
echo "This helps keep the 3rd-party license information accurate."
exit 1
fi
fi