|
6 | 6 | - "yarn.lock" |
7 | 7 |
|
8 | 8 | jobs: |
9 | | - update-3rdparty-licenses: |
| 9 | + check-licenses: |
10 | 10 | runs-on: ubuntu-latest |
11 | 11 | permissions: |
12 | 12 | contents: read |
13 | | - id-token: write |
| 13 | + outputs: |
| 14 | + needs_update: ${{ steps.check.outputs.needs_update }} |
| 15 | + is_bot_same_repo: ${{ steps.check.outputs.is_bot_same_repo }} |
| 16 | + head_oid: ${{ steps.check.outputs.head_oid }} |
14 | 17 | env: |
15 | 18 | REPOSITORY_URL: ${{ github.server_url }}/${{ github.repository }} |
16 | 19 | steps: |
17 | | - - name: Mint GitHub App token (octo-sts) for bot PR updates |
18 | | - if: github.event.pull_request.user.type == 'Bot' && github.event_name == 'pull_request' |
19 | | - uses: DataDog/dd-octo-sts-action@acaa02eee7e3bb0839e4272dacb37b8f3b58ba80 # v1.0.3 |
20 | | - id: octo-sts |
21 | | - with: |
22 | | - scope: DataDog/dd-trace-js |
23 | | - policy: update-3rdparty-licenses |
24 | | - |
25 | 20 | - name: Check out PR branch |
26 | 21 | uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
27 | 22 |
|
@@ -74,68 +69,112 @@ jobs: |
74 | 69 | run: | |
75 | 70 | cat .github/vendored-dependencies.csv >> LICENSE-3rdparty.csv |
76 | 71 |
|
77 | | - - name: Run LICENSE-3rdparty.csv update check |
| 72 | + - name: Check for LICENSE-3rdparty.csv changes |
| 73 | + id: check |
78 | 74 | env: |
79 | 75 | PR_USER_TYPE: ${{ github.event.pull_request.user.type }} |
80 | | - GITHUB_EVENT_NAME: ${{ github.event_name }} |
81 | | - GITHUB_HEAD_REF: ${{ github.head_ref }} |
82 | 76 | PR_HEAD_REPO: ${{ github.event.pull_request.head.repo.full_name }} |
83 | 77 | BASE_REPO: ${{ github.repository }} |
84 | | - GH_TOKEN: ${{ steps.octo-sts.outputs.token }} |
85 | 78 | run: | |
86 | 79 | set -e |
87 | 80 |
|
| 81 | + echo "head_oid=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT |
| 82 | +
|
88 | 83 | if git diff --ignore-space-at-eol --exit-code LICENSE-3rdparty.csv; then |
89 | 84 | echo "✅ LICENSE-3rdparty.csv is already up to date" |
| 85 | + echo "needs_update=false" >> $GITHUB_OUTPUT |
90 | 86 | else |
91 | 87 | echo "📝 LICENSE-3rdparty.csv was modified by license attribution command" |
| 88 | + echo "needs_update=true" >> $GITHUB_OUTPUT |
| 89 | + fi |
92 | 90 |
|
93 | | - if [[ "$PR_USER_TYPE" == "Bot" ]] && [[ "${GITHUB_EVENT_NAME}" == "pull_request" ]] && [[ "$PR_HEAD_REPO" == "$BASE_REPO" ]]; then |
94 | | - echo "🤖 Bot-created PR detected. Auto-committing LICENSE-3rdparty.csv changes..." |
95 | | -
|
96 | | - expected_head_oid="$(git rev-parse HEAD)" |
97 | | - contents="$(base64 -w 0 LICENSE-3rdparty.csv)" |
98 | | -
|
99 | | - variables="$(jq -c \ |
100 | | - --arg repo "$GITHUB_REPOSITORY" \ |
101 | | - --arg branch "$GITHUB_HEAD_REF" \ |
102 | | - --arg msg "Update LICENSE-3rdparty.csv" \ |
103 | | - --arg expected "$expected_head_oid" \ |
104 | | - --arg path "LICENSE-3rdparty.csv" \ |
105 | | - --arg contents "$contents" \ |
106 | | - '{ |
107 | | - input: { |
108 | | - branch: { repositoryNameWithOwner: $repo, branchName: $branch }, |
109 | | - message: { headline: $msg }, |
110 | | - expectedHeadOid: $expected, |
111 | | - fileChanges: { additions: [{ path: $path, contents: $contents }] } |
112 | | - } |
113 | | - }' |
114 | | - )" |
115 | | -
|
116 | | - query='mutation($input: CreateCommitOnBranchInput!) { createCommitOnBranch(input: $input) { commit { oid url } } }' |
117 | | - gh api graphql -f query="$query" -f variables="$variables" -q '.data.createCommitOnBranch.commit.url' >/dev/null |
118 | | -
|
119 | | - echo "✅ Successfully committed and pushed LICENSE-3rdparty.csv updates" |
120 | | - else |
121 | | - echo "❌ The LICENSE-3rdparty.csv file needs to be updated!" |
122 | | - echo "" |
123 | | - echo "The license attribution command has modified LICENSE-3rdparty.csv." |
124 | | - echo "" |
125 | | - echo "To fix this issue:" |
126 | | - echo "1. Set up dd-license-attribution locally by following the installation instructions in:" |
127 | | - echo " https://github.com/DataDog/dd-license-attribution" |
128 | | - echo "2. Run the license CSV generation command locally:" |
129 | | - echo " dd-license-attribution generate-sbom-csv \\" |
130 | | - echo " --no-scancode-strategy \\" |
131 | | - echo " --no-github-sbom-strategy \\" |
132 | | - echo " https://github.com/datadog/dd-trace-js > LICENSE-3rdparty.csv" |
133 | | - echo "3. Append vendored dependencies:" |
134 | | - echo " cat .github/vendored-dependencies.csv >> LICENSE-3rdparty.csv" |
135 | | - echo "4. Commit the updated LICENSE-3rdparty.csv file" |
136 | | - echo "5. Push your changes" |
137 | | - echo "" |
138 | | - echo "This helps keep the 3rd-party license information accurate." |
139 | | - exit 1 |
140 | | - fi |
| 91 | + if [[ "$PR_USER_TYPE" == "Bot" ]] && [[ "$PR_HEAD_REPO" == "$BASE_REPO" ]]; then |
| 92 | + echo "is_bot_same_repo=true" >> $GITHUB_OUTPUT |
| 93 | + else |
| 94 | + echo "is_bot_same_repo=false" >> $GITHUB_OUTPUT |
141 | 95 | fi |
| 96 | +
|
| 97 | + - name: Upload updated LICENSE-3rdparty.csv |
| 98 | + if: steps.check.outputs.needs_update == 'true' && steps.check.outputs.is_bot_same_repo == 'true' |
| 99 | + uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0 |
| 100 | + with: |
| 101 | + name: license-csv |
| 102 | + path: LICENSE-3rdparty.csv |
| 103 | + if-no-files-found: error |
| 104 | + |
| 105 | + - name: Fail for PRs with outdated licenses |
| 106 | + if: steps.check.outputs.needs_update == 'true' && steps.check.outputs.is_bot_same_repo != 'true' |
| 107 | + run: | |
| 108 | + echo "❌ The LICENSE-3rdparty.csv file needs to be updated!" |
| 109 | + echo "" |
| 110 | + echo "The license attribution command has modified LICENSE-3rdparty.csv." |
| 111 | + echo "" |
| 112 | + echo "To fix this issue:" |
| 113 | + echo "1. Set up dd-license-attribution locally by following the installation instructions in:" |
| 114 | + echo " https://github.com/DataDog/dd-license-attribution" |
| 115 | + echo "2. Run the license CSV generation command locally:" |
| 116 | + echo " dd-license-attribution generate-sbom-csv \\" |
| 117 | + echo " --no-scancode-strategy \\" |
| 118 | + echo " --no-github-sbom-strategy \\" |
| 119 | + echo " https://github.com/datadog/dd-trace-js > LICENSE-3rdparty.csv" |
| 120 | + echo "3. Append vendored dependencies:" |
| 121 | + echo " cat .github/vendored-dependencies.csv >> LICENSE-3rdparty.csv" |
| 122 | + echo "4. Commit the updated LICENSE-3rdparty.csv file" |
| 123 | + echo "5. Push your changes" |
| 124 | + echo "" |
| 125 | + echo "This helps keep the 3rd-party license information accurate." |
| 126 | + exit 1 |
| 127 | +
|
| 128 | + auto-commit-licenses: |
| 129 | + needs: check-licenses |
| 130 | + if: needs.check-licenses.outputs.needs_update == 'true' && needs.check-licenses.outputs.is_bot_same_repo == 'true' |
| 131 | + runs-on: ubuntu-latest |
| 132 | + permissions: |
| 133 | + contents: read |
| 134 | + id-token: write |
| 135 | + steps: |
| 136 | + - name: Mint GitHub App token (octo-sts) |
| 137 | + uses: DataDog/dd-octo-sts-action@acaa02eee7e3bb0839e4272dacb37b8f3b58ba80 # v1.0.3 |
| 138 | + id: octo-sts |
| 139 | + with: |
| 140 | + scope: DataDog/dd-trace-js |
| 141 | + policy: update-3rdparty-licenses |
| 142 | + |
| 143 | + - name: Download updated LICENSE-3rdparty.csv |
| 144 | + uses: actions/download-artifact@70fc10c6e5e1ce46ad2ea6f2b72d43f7d47b13c3 # v8.0.0 |
| 145 | + with: |
| 146 | + name: license-csv |
| 147 | + |
| 148 | + - name: Commit LICENSE-3rdparty.csv via GitHub API |
| 149 | + env: |
| 150 | + GITHUB_HEAD_REF: ${{ github.head_ref }} |
| 151 | + EXPECTED_HEAD_OID: ${{ needs.check-licenses.outputs.head_oid }} |
| 152 | + GH_TOKEN: ${{ steps.octo-sts.outputs.token }} |
| 153 | + run: | |
| 154 | + set -e |
| 155 | +
|
| 156 | + echo "🤖 Bot-created PR detected. Auto-committing LICENSE-3rdparty.csv changes..." |
| 157 | +
|
| 158 | + contents="$(base64 -w 0 LICENSE-3rdparty.csv)" |
| 159 | +
|
| 160 | + variables="$(jq -c \ |
| 161 | + --arg repo "$GITHUB_REPOSITORY" \ |
| 162 | + --arg branch "$GITHUB_HEAD_REF" \ |
| 163 | + --arg msg "Update LICENSE-3rdparty.csv" \ |
| 164 | + --arg expected "$EXPECTED_HEAD_OID" \ |
| 165 | + --arg path "LICENSE-3rdparty.csv" \ |
| 166 | + --arg contents "$contents" \ |
| 167 | + '{ |
| 168 | + input: { |
| 169 | + branch: { repositoryNameWithOwner: $repo, branchName: $branch }, |
| 170 | + message: { headline: $msg }, |
| 171 | + expectedHeadOid: $expected, |
| 172 | + fileChanges: { additions: [{ path: $path, contents: $contents }] } |
| 173 | + } |
| 174 | + }' |
| 175 | + )" |
| 176 | +
|
| 177 | + query='mutation($input: CreateCommitOnBranchInput!) { createCommitOnBranch(input: $input) { commit { oid url } } }' |
| 178 | + gh api graphql -f query="$query" -f variables="$variables" -q '.data.createCommitOnBranch.commit.url' >/dev/null |
| 179 | +
|
| 180 | + echo "✅ Successfully committed and pushed LICENSE-3rdparty.csv updates" |
0 commit comments