|
17 | 17 | env: |
18 | 18 | REPOSITORY_URL: ${{ github.server_url }}/${{ github.repository }} |
19 | 19 | steps: |
20 | | - - name: Check out PR branch |
| 20 | + - name: Check out base branch |
21 | 21 | uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 |
22 | | - with: |
23 | | - ref: ${{ github.event.pull_request.head.sha }} |
24 | 22 |
|
25 | 23 | - name: Get GitHub token with appropriate permissions |
26 | 24 | uses: DataDog/dd-octo-sts-action@acaa02eee7e3bb0839e4272dacb37b8f3b58ba80 # v1.0.3 |
@@ -72,29 +70,48 @@ jobs: |
72 | 70 | --no-scancode-strategy \ |
73 | 71 | --no-github-sbom-strategy \ |
74 | 72 | --yarn-subdir vendor \ |
75 | | - "${REPOSITORY_URL}" > LICENSE-3rdparty.csv |
| 73 | + "${REPOSITORY_URL}" > LICENSE-3rdparty.csv.generated |
76 | 74 |
|
77 | | - - name: Append vendored dependencies |
| 75 | + - name: Fetch files from PR branch |
78 | 76 | run: | |
79 | | - cat .github/vendored-dependencies.csv >> LICENSE-3rdparty.csv |
| 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 |
| 85 | +
|
| 86 | + - name: Append vendored dependencies from PR |
| 87 | + run: | |
| 88 | + cat vendored-dependencies.csv.pr >> LICENSE-3rdparty.csv.generated |
80 | 89 |
|
81 | 90 | - name: Run LICENSE-3rdparty.csv update check |
82 | 91 | env: |
83 | 92 | PR_AUTHOR: ${{ github.event.pull_request.user.login }} |
84 | 93 | PR_USER_TYPE: ${{ github.event.pull_request.user.type }} |
85 | 94 | GITHUB_EVENT_NAME: ${{ github.event_name }} |
86 | 95 | GITHUB_HEAD_REF: ${{ github.head_ref }} |
| 96 | + PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }} |
87 | 97 | run: | |
88 | 98 | set -e |
89 | 99 |
|
90 | | - if git diff --ignore-space-at-eol --exit-code LICENSE-3rdparty.csv; then |
| 100 | + if diff --ignore-space-at-eol LICENSE-3rdparty.csv.generated LICENSE-3rdparty.csv.pr > /dev/null; then |
91 | 101 | echo "✅ LICENSE-3rdparty.csv is already up to date" |
92 | 102 | else |
93 | 103 | echo "📝 LICENSE-3rdparty.csv was modified by license attribution command" |
94 | 104 |
|
95 | | - if [[ "$PR_USER_TYPE" == "Bot" ]] && [[ "${GITHUB_EVENT_NAME}" == "pull_request" ]]; then |
| 105 | + if [[ "$PR_USER_TYPE" == "Bot" ]] && [[ "${GITHUB_EVENT_NAME}" == "pull_request_target" ]]; then |
96 | 106 | echo "🤖 Bot-created PR detected. Auto-committing LICENSE-3rdparty.csv changes..." |
97 | 107 |
|
| 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 | +
|
98 | 115 | git config --local user.email "action@github.com" |
99 | 116 | git config --local user.name "GitHub Action" |
100 | 117 |
|
|
0 commit comments