55 branches : [ main, dotnet-vnext ]
66
77env :
8+ POWERSHELL_YAML_VERSION : ' 0.4.12'
89 REVIEWER_LOGIN : ${{ vars.REVIEWER_USER_NAME }}
910
10- permissions :
11- contents : read
11+ permissions : {}
1212
1313jobs :
1414 review-pull-request :
1515 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
1720
1821 steps :
1922
@@ -23,31 +26,33 @@ jobs:
2326 with :
2427 application_id : ${{ secrets.REVIEWER_APPLICATION_ID }}
2528 application_private_key : ${{ secrets.REVIEWER_APPLICATION_PRIVATE_KEY }}
26- permissions : " contents:write, pull_requests:write"
29+ permissions : ' contents:write, pull_requests:write'
2730
2831 - name : Install powershell-yaml
2932 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}
3134
3235 - name : Check which dependencies were updated
3336 id : check-dependencies
3437 env :
3538 # 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'
3740 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 }}
3843 shell : pwsh
3944 run : |
4045 # Replicate the logic in the dependabot/fetch-metadata action.
4146 # See https://github.com/dependabot/fetch-metadata/blob/aea2135c95039f05c64436f1d14638c300e10b2b/src/dependabot/update_metadata.ts#L29-L68.
4247 # Query the GitHub API to get the commits in the pull request.
4348 $commits = gh api `
44- /repos/${{ github.repository }} /pulls/${{ github.event.pull_request.number }} /commits `
49+ " /repos/${env:GITHUB_REPOSITORY} /pulls/${env:PR_NUMBER} /commits" `
4550 --jq '.[] | { author: .author.login, message: .commit.message }' | ConvertFrom-Json
4651
4752 # We should only approve pull requests that only contain commits from
4853 # the GitHub user we expected and only commits that contain the metadata
4954 # 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}"
5156 $onlyDependencyUpdates = $True
5257 $onlyChangesFromUser = $True
5358
8287 # Did we find at least one dependency?
8388 $isPatch = $dependencies.Length -gt 0
8489 $onlyTrusted = $dependencies.Length -gt 0
85- $trustedPackages = $env:INCLUDE_NUGET_PACKAGES.Split(',')
90+ $trustedPackages = ${ env:INCLUDE_NUGET_PACKAGES} .Split(',')
8691
8792 foreach ($dependency in $dependencies) {
8893 $isPatch = $isPatch -And $dependency.Type -eq "version-update:semver-patch"
@@ -98,34 +103,38 @@ jobs:
98103 # Microsoft-published NuGet packages that were made by the GitHub
99104 # login we expect to make those changes in the other workflow.
100105 $isTrusted = (($onlyTrusted -And $isPatch) -And $onlyChangesFromUser) -And $onlyDependencyUpdates
101- "is-trusted-update=$isTrusted" >> $env:GITHUB_OUTPUT
106+ "is-trusted-update=$isTrusted" >> ${ env:GITHUB_OUTPUT}
102107
103108 - name : Checkout code
104109 uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
110+ with :
111+ filter : ' tree:0'
112+ show-progress : false
105113
106114 # As long as it's not already approved, approve the pull request and enable auto-merge.
107115 # Our CI tests coupled with required statuses should ensure that the changes compile
108116 # and that the application is still functional after the update; any bug that might be
109117 # introduced by the update should be caught by the tests. If that happens, the build
110118 # workflow will fail and the preconditions for the auto-merge to happen won't be met.
111119 - 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'
113121 env :
114122 GH_TOKEN : ${{ steps.generate-application-token.outputs.token }}
123+ PR_NUMBER : ${{ github.event.pull_request.number }}
115124 PR_URL : ${{ github.event.pull_request.html_url }}
116125 shell : pwsh
117126 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} }
120129 $approvals = $approvals | Where-Object { $_.state -eq "APPROVED" }
121130
122131 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}
126135 }
127136 else {
128- Write-Host "PR already approved.";
137+ Write-Output "PR already approved.";
129138 }
130139
131140 # If something was present in the pull request that isn't expected, then disable
@@ -134,27 +143,28 @@ jobs:
134143 # automatically if there's an unexpected change introduced. Any existing review
135144 # approvals that were made by the bot are also dismissed so human approval is required.
136145 - 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'
138147 env :
139148 GH_TOKEN : ${{ steps.generate-application-token.outputs.token }}
149+ PR_NUMBER : ${{ github.event.pull_request.number }}
140150 PR_URL : ${{ github.event.pull_request.html_url }}
141151 shell : pwsh
142152 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} }
145155 $approvals = $approvals | Where-Object { $_.state -eq "APPROVED" }
146156
147157 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}
150160 foreach ($approval in $approvals) {
151161 gh api `
152162 --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" `
154164 -f message='Cannot approve as other changes have been introduced.' `
155165 -f event='DISMISS'
156166 }
157167 }
158168 else {
159- Write-Host "PR not already approved.";
169+ Write-Output "PR not already approved.";
160170 }
0 commit comments