-
Notifications
You must be signed in to change notification settings - Fork 406
141 lines (125 loc) · 5.58 KB
/
Copy pathupdate-3rdparty-licenses.yml
File metadata and controls
141 lines (125 loc) · 5.58 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
name: Update 3rd-party licenses
on:
pull_request:
paths:
- "yarn.lock"
jobs:
update-3rdparty-licenses:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
env:
REPOSITORY_URL: ${{ github.server_url }}/${{ github.repository }}
steps:
- name: Mint GitHub App token (octo-sts) for bot PR updates
if: github.event.pull_request.user.type == 'Bot' && github.event_name == 'pull_request'
uses: DataDog/dd-octo-sts-action@acaa02eee7e3bb0839e4272dacb37b8f3b58ba80 # v1.0.3
id: octo-sts
with:
scope: DataDog/dd-trace-js
policy: update-3rdparty-licenses
- 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 }}
GH_TOKEN: ${{ steps.octo-sts.outputs.token }}
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..."
expected_head_oid="$(git rev-parse HEAD)"
contents="$(base64 -w 0 LICENSE-3rdparty.csv)"
variables="$(jq -c \
--arg repo "$GITHUB_REPOSITORY" \
--arg branch "$GITHUB_HEAD_REF" \
--arg msg "Update LICENSE-3rdparty.csv" \
--arg expected "$expected_head_oid" \
--arg path "LICENSE-3rdparty.csv" \
--arg contents "$contents" \
'{
input: {
branch: { repositoryNameWithOwner: $repo, branchName: $branch },
message: { headline: $msg },
expectedHeadOid: $expected,
fileChanges: { additions: [{ path: $path, contents: $contents }] }
}
}'
)"
query='mutation($input: CreateCommitOnBranchInput!) { createCommitOnBranch(input: $input) { commit { oid url } } }'
gh api graphql -f query="$query" -f variables="$variables" -q '.data.createCommitOnBranch.commit.url' >/dev/null
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