Skip to content

Commit

Permalink
Fix auto commit handling for PR cases where the green tests files hav…
Browse files Browse the repository at this point in the history
…e not changed. (#167)
  • Loading branch information
lauxjpn authored Oct 26, 2023
1 parent f865ea4 commit 6d9e20d
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 9 deletions.
57 changes: 49 additions & 8 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,41 @@ jobs:
- name: Install .NET SDK
shell: pwsh
run: |
&([scriptblock]::Create((Invoke-WebRequest -UseBasicParsing 'https://dot.net/v1/dotnet-install.ps1'))) -JSonFile global.json -Architecture '${{ matrix.aceArchitecture }}' -InstallDir '${{ env.dotnetInstallDirectory }}' -Verbose
function Retry-Command {
[CmdletBinding()]
Param(
[Parameter(Position=0, Mandatory=$true)]
[ScriptBlock]$ScriptBlock,
[Parameter(Position=1, Mandatory=$false)]
[int]$Maximum = 5,
[Parameter(Mandatory=$false)]
[switch]$ExponentialBackoff
)
$attempt = 0
do {
if ($attempt -gt 0 -and $ExponentialBackoff) {
Start-Sleep -Seconds ([Math]::Pow(2, $attempt) - 1)
}
$attempt++
try {
$ScriptBlock.Invoke()
return
} catch {
Write-Error $_.Exception.InnerException.Message -ErrorAction Continue
}
} while ($attempt -lt $Maximum)
throw 'Max retries exceeded.'
}
Retry-Command {
&([ScriptBlock]::Create((Invoke-WebRequest -UseBasicParsing 'https://dot.net/v1/dotnet-install.ps1'))) -JSonFile global.json -Architecture '${{ matrix.aceArchitecture }}' -InstallDir '${{ env.dotnetInstallDirectory }}' -Verbose
} -Maximum 10 -ExponentialBackoff
- name: .NET Information After SDK Install
shell: pwsh
run: try { & '${{ env.dotnetExecutable }}' --info } catch { echo 'No ${{ matrix.aceArchitecture }} .NET SDK installed.' }
Expand Down Expand Up @@ -229,19 +263,27 @@ jobs:
$establishedGreenTestsFilePath = ".\test\EFCore.Jet.FunctionalTests\GreenTests\ace_${{ matrix.aceVersion }}_$('${{ matrix.dataAccessProviderType }}'.Replace(' ', '').ToLowerInvariant())_${{ matrix.aceArchitecture }}.txt"
if (Test-Path $establishedGreenTestsFilePath) {
$notGreenAnymore = Compare-Object (Get-Content $establishedGreenTestsFilePath) (Get-Content $greenTestsFilePath) | Where-Object { $_.SideIndicator -eq '<=' } | Select-Object -ExpandProperty InputObject
$diffResult = Compare-Object (Get-Content $establishedGreenTestsFilePath) (Get-Content $greenTestsFilePath)
$notGreenAnymore = $diffResult | Where-Object { $_.SideIndicator -eq '<=' } | Select-Object -ExpandProperty InputObject
if ($null -ne $notGreenAnymore) {
echo "`nThe following $(@($notGreenAnymore).Length) tests passed in previous runs, but didn't pass in this run:`n"
$notGreenAnymore
exit 1
}
echo 'All tests that passed in previous runs still passed in this run.'
Copy-Item $greenTestsFilePath $establishedGreenTestsFilePath -Force -Verbose
$commitGreenTestsFile = $establishedGreenTestsFilePath
echo "commitGreenTestsFile=$commitGreenTestsFile" >> $env:GITHUB_ENV
$newlyGreenTests = $diffResult | Where-Object { $_.SideIndicator -eq '=>' } | Select-Object -ExpandProperty InputObject
if ($newlyGreenTests.Length -gt 0) {
Copy-Item $greenTestsFilePath $establishedGreenTestsFilePath -Force -Verbose
echo "`nThe following new tests passed that did not pass before:`n"
$newlyGreenTests
$commitGreenTestsFile = $establishedGreenTestsFilePath
echo "commitGreenTestsFile=$commitGreenTestsFile" >> $env:GITHUB_ENV
}
}
echo 'Check succeeded.'
- name: 'Upload Green Tests'
Expand Down Expand Up @@ -280,6 +322,5 @@ jobs:
- name: 'Final Status'
shell: pwsh
run: |
echo 'needs.CheckArtifacts.outputs.hasGreenTestsArtifacts: ${{ needs.CheckArtifacts.outputs.hasGreenTestsArtifacts }}'
echo 'All workflows succeeded.'
exit 0
36 changes: 35 additions & 1 deletion .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,41 @@ jobs:
- name: Install .NET SDK
shell: pwsh
run: |
&([scriptblock]::Create((Invoke-WebRequest -UseBasicParsing 'https://dot.net/v1/dotnet-install.ps1'))) -JSonFile global.json -Architecture '${{ matrix.aceArchitecture }}' -InstallDir '${{ env.dotnetInstallDirectory }}' -Verbose
function Retry-Command {
[CmdletBinding()]
Param(
[Parameter(Position=0, Mandatory=$true)]
[ScriptBlock]$ScriptBlock,
[Parameter(Position=1, Mandatory=$false)]
[int]$Maximum = 5,
[Parameter(Mandatory=$false)]
[switch]$ExponentialBackoff
)
$attempt = 0
do {
if ($attempt -gt 0 -and $ExponentialBackoff) {
Start-Sleep -Seconds ([Math]::Pow(2, $attempt) - 1)
}
$attempt++
try {
$ScriptBlock.Invoke()
return
} catch {
Write-Error $_.Exception.InnerException.Message -ErrorAction Continue
}
} while ($attempt -lt $Maximum)
throw 'Max retries exceeded.'
}
Retry-Command {
&([ScriptBlock]::Create((Invoke-WebRequest -UseBasicParsing 'https://dot.net/v1/dotnet-install.ps1'))) -JSonFile global.json -Architecture '${{ matrix.aceArchitecture }}' -InstallDir '${{ env.dotnetInstallDirectory }}' -Verbose
} -Maximum 10 -ExponentialBackoff
- name: .NET Information After SDK Install
shell: pwsh
run: try { & '${{ env.dotnetExecutable }}' --info } catch { echo 'No ${{ matrix.aceArchitecture }} .NET SDK installed.' }
Expand Down

0 comments on commit 6d9e20d

Please sign in to comment.