|
1 | 1 | name: Update 3rd-party licenses |
2 | 2 |
|
3 | 3 | on: |
4 | | - pull_request_target: |
5 | | - branches: |
6 | | - - master |
| 4 | + pull_request: |
7 | 5 | paths: |
8 | 6 | - 'yarn.lock' |
9 | 7 |
|
10 | 8 | jobs: |
11 | 9 | update-3rdparty-licenses: |
12 | 10 | runs-on: ubuntu-latest |
13 | 11 | permissions: |
14 | | - id-token: write |
15 | 12 | contents: write |
16 | | - pull-requests: write |
17 | 13 | env: |
18 | 14 | REPOSITORY_URL: ${{ github.server_url }}/${{ github.repository }} |
19 | 15 | steps: |
20 | | - - name: Check out base branch |
| 16 | + - name: Check out PR branch |
21 | 17 | uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 |
22 | 18 |
|
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 | 19 | - name: Set up Python |
31 | 20 | uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0 |
32 | 21 | with: |
@@ -62,56 +51,34 @@ jobs: |
62 | 51 | EOF |
63 | 52 |
|
64 | 53 | - name: Regenerate LICENSE-3rdparty.csv |
65 | | - env: |
66 | | - GITHUB_TOKEN: ${{ steps.octo-sts.outputs.token }} |
67 | 54 | run: | |
68 | 55 | dd-license-attribution generate-sbom-csv \ |
69 | 56 | --use-mirrors=mirrors.json \ |
70 | 57 | --no-scancode-strategy \ |
71 | 58 | --no-github-sbom-strategy \ |
72 | 59 | --yarn-subdir vendor \ |
73 | | - "${REPOSITORY_URL}" > LICENSE-3rdparty.csv.generated |
74 | | -
|
75 | | - - name: Fetch files from PR branch |
76 | | - run: | |
77 | | - # Fetch the PR branch |
78 | | - git fetch origin ${{ github.event.pull_request.head.sha }} |
79 | | -
|
80 | | - # Fetch vendored-dependencies.csv from PR branch |
81 | | - git show ${{ github.event.pull_request.head.sha }}:.github/vendored-dependencies.csv > vendored-dependencies.csv.pr || touch vendored-dependencies.csv.pr |
82 | | -
|
83 | | - # Fetch LICENSE-3rdparty.csv from PR branch for comparison |
84 | | - git show ${{ github.event.pull_request.head.sha }}:LICENSE-3rdparty.csv > LICENSE-3rdparty.csv.pr || touch LICENSE-3rdparty.csv.pr |
| 60 | + "${REPOSITORY_URL}" > LICENSE-3rdparty.csv |
85 | 61 |
|
86 | 62 | - name: Append vendored dependencies from PR |
87 | 63 | run: | |
88 | | - cat vendored-dependencies.csv.pr >> LICENSE-3rdparty.csv.generated |
| 64 | + cat .github/vendored-dependencies.csv >> LICENSE-3rdparty.csv |
89 | 65 |
|
90 | 66 | - name: Run LICENSE-3rdparty.csv update check |
91 | 67 | env: |
92 | | - PR_AUTHOR: ${{ github.event.pull_request.user.login }} |
93 | 68 | PR_USER_TYPE: ${{ github.event.pull_request.user.type }} |
94 | 69 | GITHUB_EVENT_NAME: ${{ github.event_name }} |
95 | 70 | GITHUB_HEAD_REF: ${{ github.head_ref }} |
96 | | - PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }} |
97 | 71 | run: | |
98 | 72 | set -e |
99 | 73 |
|
100 | | - if diff --ignore-space-at-eol LICENSE-3rdparty.csv.generated LICENSE-3rdparty.csv.pr > /dev/null; then |
| 74 | + if git diff --ignore-space-at-eol --exit-code LICENSE-3rdparty.csv; then |
101 | 75 | echo "✅ LICENSE-3rdparty.csv is already up to date" |
102 | 76 | else |
103 | 77 | echo "📝 LICENSE-3rdparty.csv was modified by license attribution command" |
104 | 78 |
|
105 | | - if [[ "$PR_USER_TYPE" == "Bot" ]] && [[ "${GITHUB_EVENT_NAME}" == "pull_request_target" ]]; then |
| 79 | + if [[ "$PR_USER_TYPE" == "Bot" ]] && [[ "${GITHUB_EVENT_NAME}" == "pull_request" ]]; then |
106 | 80 | echo "🤖 Bot-created PR detected. Auto-committing LICENSE-3rdparty.csv changes..." |
107 | 81 |
|
108 | | - # Checkout the PR branch for committing |
109 | | - git fetch origin ${PR_HEAD_SHA} |
110 | | - git checkout ${PR_HEAD_SHA} |
111 | | -
|
112 | | - # Move the generated file into place |
113 | | - mv LICENSE-3rdparty.csv.generated LICENSE-3rdparty.csv |
114 | | -
|
115 | 82 | git config --local user.email "action@github.com" |
116 | 83 | git config --local user.name "GitHub Action" |
117 | 84 |
|
|
0 commit comments