5
5
branches : [ main, dotnet-vnext ]
6
6
7
7
env :
8
+ POWERSHELL_YAML_VERSION : ' 0.4.12'
8
9
REVIEWER_LOGIN : ${{ vars.REVIEWER_USER_NAME }}
9
10
10
- permissions :
11
- contents : read
11
+ permissions : {}
12
12
13
13
jobs :
14
14
review-pull-request :
15
15
runs-on : ubuntu-latest
16
- if : ${{ github.event.pull_request.user.login == vars.UPDATER_COMMIT_USER_NAME }}
16
+ if : github.event.pull_request.user.login == vars.UPDATER_COMMIT_USER_NAME
17
+
18
+ permissions :
19
+ contents : read
17
20
18
21
steps :
19
22
@@ -23,31 +26,33 @@ jobs:
23
26
with :
24
27
application_id : ${{ secrets.REVIEWER_APPLICATION_ID }}
25
28
application_private_key : ${{ secrets.REVIEWER_APPLICATION_PRIVATE_KEY }}
26
- permissions : " contents:write, pull_requests:write"
29
+ permissions : ' contents:write, pull_requests:write'
27
30
28
31
- name : Install powershell-yaml
29
32
shell : pwsh
30
- run : Install-Module -Name powershell-yaml -Force -MaximumVersion "0.4.7"
33
+ run : Install-Module -Name powershell-yaml -Force -MaximumVersion ${env:POWERSHELL_YAML_VERSION}
31
34
32
35
- name : Check which dependencies were updated
33
36
id : check-dependencies
34
37
env :
35
38
# This list of trusted package prefixes needs to stay in sync with include-nuget-packages in the update-dotnet-sdk workflow.
36
- INCLUDE_NUGET_PACKAGES : " Microsoft.AspNetCore.,Microsoft.EntityFrameworkCore.,Microsoft.Extensions.,Microsoft.NET.Test.Sdk"
39
+ INCLUDE_NUGET_PACKAGES : ' Microsoft.AspNetCore.,Microsoft.EntityFrameworkCore.,Microsoft.Extensions.,Microsoft.NET.Test.Sdk'
37
40
GH_TOKEN : ${{ steps.generate-application-token.outputs.token }}
41
+ PR_NUMBER : ${{ github.event.pull_request.number }}
42
+ UPDATER_COMMIT_USER_NAME : ${{ vars.UPDATER_COMMIT_USER_NAME }}
38
43
shell : pwsh
39
44
run : |
40
45
# Replicate the logic in the dependabot/fetch-metadata action.
41
46
# See https://github.com/dependabot/fetch-metadata/blob/aea2135c95039f05c64436f1d14638c300e10b2b/src/dependabot/update_metadata.ts#L29-L68.
42
47
# Query the GitHub API to get the commits in the pull request.
43
48
$commits = gh api `
44
- /repos/${{ github.repository }} /pulls/${{ github.event.pull_request.number }} /commits `
49
+ " /repos/${env:GITHUB_REPOSITORY} /pulls/${env:PR_NUMBER} /commits" `
45
50
--jq '.[] | { author: .author.login, message: .commit.message }' | ConvertFrom-Json
46
51
47
52
# We should only approve pull requests that only contain commits from
48
53
# the GitHub user we expected and only commits that contain the metadata
49
54
# we need to determine what dependencies were updated by the other workflow.
50
- $expectedUser = "${{ vars. UPDATER_COMMIT_USER_NAME } }"
55
+ $expectedUser = "${env: UPDATER_COMMIT_USER_NAME}"
51
56
$onlyDependencyUpdates = $True
52
57
$onlyChangesFromUser = $True
53
58
82
87
# Did we find at least one dependency?
83
88
$isPatch = $dependencies.Length -gt 0
84
89
$onlyTrusted = $dependencies.Length -gt 0
85
- $trustedPackages = $env:INCLUDE_NUGET_PACKAGES.Split(',')
90
+ $trustedPackages = ${ env:INCLUDE_NUGET_PACKAGES} .Split(',')
86
91
87
92
foreach ($dependency in $dependencies) {
88
93
$isPatch = $isPatch -And $dependency.Type -eq "version-update:semver-patch"
@@ -98,34 +103,38 @@ jobs:
98
103
# Microsoft-published NuGet packages that were made by the GitHub
99
104
# login we expect to make those changes in the other workflow.
100
105
$isTrusted = (($onlyTrusted -And $isPatch) -And $onlyChangesFromUser) -And $onlyDependencyUpdates
101
- "is-trusted-update=$isTrusted" >> $env:GITHUB_OUTPUT
106
+ "is-trusted-update=$isTrusted" >> ${ env:GITHUB_OUTPUT}
102
107
103
108
- name : Checkout code
104
109
uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
110
+ with :
111
+ filter : ' tree:0'
112
+ show-progress : false
105
113
106
114
# As long as it's not already approved, approve the pull request and enable auto-merge.
107
115
# Our CI tests coupled with required statuses should ensure that the changes compile
108
116
# and that the application is still functional after the update; any bug that might be
109
117
# introduced by the update should be caught by the tests. If that happens, the build
110
118
# workflow will fail and the preconditions for the auto-merge to happen won't be met.
111
119
- name : Approve pull request and enable auto-merge
112
- if : ${{ steps.check-dependencies.outputs.is-trusted-update == 'true' }}
120
+ if : steps.check-dependencies.outputs.is-trusted-update == 'true'
113
121
env :
114
122
GH_TOKEN : ${{ steps.generate-application-token.outputs.token }}
123
+ PR_NUMBER : ${{ github.event.pull_request.number }}
115
124
PR_URL : ${{ github.event.pull_request.html_url }}
116
125
shell : pwsh
117
126
run : |
118
- $approvals = gh api /repos/${{ github.repository }} /pulls/${{ github.event.pull_request.number }} /reviews | ConvertFrom-Json
119
- $approvals = $approvals | Where-Object { $_.user.login -eq $env:REVIEWER_LOGIN }
127
+ $approvals = gh api " /repos/${env:GITHUB_REPOSITORY} /pulls/${env:PR_NUMBER} /reviews" | ConvertFrom-Json
128
+ $approvals = $approvals | Where-Object { $_.user.login -eq ${ env:REVIEWER_LOGIN} }
120
129
$approvals = $approvals | Where-Object { $_.state -eq "APPROVED" }
121
130
122
131
if ($approvals.Length -eq 0) {
123
- gh pr checkout "$ env:PR_URL"
124
- gh pr review --approve "$ env:PR_URL"
125
- gh pr merge --auto --squash "$ env:PR_URL"
132
+ gh pr checkout ${ env:PR_URL}
133
+ gh pr review --approve ${ env:PR_URL}
134
+ gh pr merge --auto --squash ${ env:PR_URL}
126
135
}
127
136
else {
128
- Write-Host "PR already approved.";
137
+ Write-Output "PR already approved.";
129
138
}
130
139
131
140
# If something was present in the pull request that isn't expected, then disable
@@ -134,27 +143,28 @@ jobs:
134
143
# automatically if there's an unexpected change introduced. Any existing review
135
144
# approvals that were made by the bot are also dismissed so human approval is required.
136
145
- name : Disable auto-merge and dismiss approvals
137
- if : ${{ steps.check-dependencies.outputs.is-trusted-update != 'true' }}
146
+ if : steps.check-dependencies.outputs.is-trusted-update != 'true'
138
147
env :
139
148
GH_TOKEN : ${{ steps.generate-application-token.outputs.token }}
149
+ PR_NUMBER : ${{ github.event.pull_request.number }}
140
150
PR_URL : ${{ github.event.pull_request.html_url }}
141
151
shell : pwsh
142
152
run : |
143
- $approvals = gh api /repos/${{ github.repository }} /pulls/${{ github.event.pull_request.number }} /reviews | ConvertFrom-Json
144
- $approvals = $approvals | Where-Object { $_.user.login -eq $env:REVIEWER_LOGIN }
153
+ $approvals = gh api " /repos/${env:GITHUB_REPOSITORY} /pulls/${env:PR_NUMBER} /reviews" | ConvertFrom-Json
154
+ $approvals = $approvals | Where-Object { $_.user.login -eq ${ env:REVIEWER_LOGIN} }
145
155
$approvals = $approvals | Where-Object { $_.state -eq "APPROVED" }
146
156
147
157
if ($approvals.Length -gt 0) {
148
- gh pr checkout "$ env:PR_URL"
149
- gh pr merge --disable-auto "$ env:PR_URL"
158
+ gh pr checkout ${ env:PR_URL}
159
+ gh pr merge --disable-auto ${ env:PR_URL}
150
160
foreach ($approval in $approvals) {
151
161
gh api `
152
162
--method PUT `
153
- /repos/${{ github.repository }} /pulls/${{ github.event.pull_request.number }} /reviews/$($approval.id)/dismissals `
163
+ " /repos/${env:GITHUB_REPOSITORY} /pulls/${env:PR_NUMBER} /reviews/$($approval.id)/dismissals" `
154
164
-f message='Cannot approve as other changes have been introduced.' `
155
165
-f event='DISMISS'
156
166
}
157
167
}
158
168
else {
159
- Write-Host "PR not already approved.";
169
+ Write-Output "PR not already approved.";
160
170
}
0 commit comments