|
1 | 1 | name: Label breaking changes for semantic versioning |
2 | 2 |
|
3 | | -on: [pull_request] |
| 3 | +on: pull_request_target # Run on the merge target branch instead of the merge commit to grant pull-requests:write permission |
4 | 4 | jobs: |
5 | 5 | Label: |
6 | 6 | runs-on: windows-latest |
| 7 | + permissions: |
| 8 | + pull-requests: write # Allow adding a label to this pull request |
7 | 9 | steps: |
8 | 10 | - uses: actions/checkout@v6 |
9 | 11 | with: |
10 | | - submodules: recursive |
| 12 | + fetch-depth: 0 # Fetch all commit history and tags, instead of the default fetch of only one commit |
| 13 | + ref: ${{ github.event.pull_request.head.sha }} # Checkout the PR branch |
11 | 14 | - name: If there are changes in PublicApi.Shipped.txt, fail the workflow |
12 | 15 | if: github.head_ref != 'action/ship-publicapi' # Same branch name specified in Release.yml |
13 | 16 | run: | |
14 | | - git fetch origin ${{ github.base_ref }} |
15 | | - $changes = git diff --numstat --shortstat origin/${{ github.base_ref }}...HEAD -- '**/PublicApi.Shipped.txt' |
| 17 | + $changes = git diff --numstat --shortstat origin/${{ github.base_ref }}...HEAD -- '**/PublicApi.Shipped.txt' # Note that ** must expand to at least one folder here, this doesn't check root |
16 | 18 | Write-Output "$changes" |
17 | 19 | if ($changes) { |
18 | 20 | Write-Error "Changes detected in PublicApi.Shipped.txt files. Public API changes must be shipped through the release process, not in regular pull requests." |
|
21 | 23 | shell: pwsh |
22 | 24 | - name: Label based on PublicApi.Unshipped.txt |
23 | 25 | run: | |
24 | | - git fetch origin ${{ github.base_ref }} |
25 | | - |
26 | | - # Determine the appropriate label (Sync these labels with release-drafter.yml) |
27 | | - if ("${{ github.head_ref }}" -eq "action/ship-publicapi") { # Same branch name specified in Release.yml |
| 26 | + if ("${{ github.head_ref }}" -eq "action/ship-publicapi") { |
28 | 27 | $labels = @('Type/Housekeeping') |
29 | | - Write-Output "This is a ship-publicapi PR, labeling as Type/Maintenance" |
| 28 | + Write-Output "This is a ship-publicapi PR, labeling as Type/Housekeeping" |
30 | 29 | } else { |
31 | 30 | # For regular PRs, check for API changes |
32 | 31 | $changes = git diff origin/${{ github.base_ref }}...HEAD -- '**/PublicApi.Unshipped.txt' |
|
44 | 43 | Write-Output "Publicly facing API changes include only additions. Labelling as enhancement." |
45 | 44 | } |
46 | 45 | } else { |
47 | | - $labels = @('Type/Bug') |
48 | | - Write-Output "No publicly facing API changes. Labelling as bug." |
| 46 | + Write-Output "No publicly facing API changes. Exiting the workflow." |
| 47 | + Exit |
49 | 48 | } |
50 | 49 | } |
51 | 50 | |
|
0 commit comments