adding slack notification to channel if it loops for more than 5 mins #1094
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI | |
on: | |
pull_request: | |
jobs: | |
CI: | |
name: "CI" | |
runs-on: Windows | |
timeout-minutes: 60 | |
steps: | |
- name: Check out the GM-TestFramework repo | |
uses: actions/checkout@v4 | |
with: | |
path: GM-TF | |
# - name: Wait for 10 Minutes | |
# run: Start-Sleep -Seconds 300 | |
# shell: pwsh | |
- run: .\setup.bat | |
working-directory: GM-TF | |
shell: cmd | |
- name: Testing on PR | |
run: | | |
$startTime = Get-Date | |
$timeoutMinutes = 5 | |
$maxTime = $startTime.AddMinutes($timeoutMinutes) | |
Write-Host "Starting build..." | |
# Initialize the process start information | |
$processStartInfo = New-Object System.Diagnostics.ProcessStartInfo | |
$processStartInfo.FileName = "cmd.exe" | |
$processStartInfo.Arguments = "/c run_ci.bat C:\GM-TestFramework\configs\config_windows.json https://gms.yoyogames.com/Zeus-Runtime-Nocturnus-I.rss" | |
$processStartInfo.RedirectStandardOutput = $true | |
$processStartInfo.RedirectStandardError = $true | |
$processStartInfo.UseShellExecute = $false | |
$processStartInfo.CreateNoWindow = $true | |
# Start the process | |
$process = New-Object System.Diagnostics.Process | |
$process.StartInfo = $processStartInfo | |
$process.Start() | Out-Null | |
# Read the output streams asynchronously | |
$stdOut = [System.Collections.ArrayList]::Synchronized((New-Object System.Collections.ArrayList)) | |
$stdErr = [System.Collections.ArrayList]::Synchronized((New-Object System.Collections.ArrayList)) | |
$stdOutEvent = { | |
param([object]$sender, [System.Diagnostics.DataReceivedEventArgs]$e) | |
if ($e.Data) { | |
$stdOut.Add($e.Data) | Out-Null | |
} | |
} | |
$stdErrEvent = { | |
param([object]$sender, [System.Diagnostics.DataReceivedEventArgs]$e) | |
if ($e.Data) { | |
$stdErr.Add($e.Data) | Out-Null | |
} | |
} | |
$process.BeginOutputReadLine() | |
$process.BeginErrorReadLine() | |
$process.add_OutputDataReceived($stdOutEvent) | |
$process.add_ErrorDataReceived($stdErrEvent) | |
# Monitor process for looping | |
while (-not $process.HasExited) { | |
if ((Get-Date) -gt $maxTime) { | |
# If looping exceeds 5 minutes, send a Slack notification and exit | |
$slackPayload = @{ | |
text = "Build is stuck in a loop for more than 5 minutes. Exiting process." | |
} | ConvertTo-Json -Depth 10 | |
Invoke-RestMethod -Uri "${{ secrets.SLACK_WEBHOOK_URL }}" -Method POST -ContentType "application/json" -Body $slackPayload | |
$process.Kill() | |
throw "Test Framework Build exceeded the 5-minute timeout and was terminated." | |
} | |
Start-Sleep -Seconds 10 # Check every 10 seconds | |
} | |
# Ensure asynchronous read operations have completed | |
$process.WaitForExit() | |
$process.WaitForExit() | Out-Null | |
# Output the captured stdout and stderr | |
Write-Host "Standard Output:" | |
$stdOut | ForEach-Object { Write-Host $_ } | |
Write-Host "Standard Error:" | |
$stdErr | ForEach-Object { Write-Host $_ } | |
working-directory: GM-TF | |
shell: pwsh | |
- name: Upload Results Artifacts | |
if: always() | |
uses: actions/upload-artifact@v4 | |
with: | |
name: summary_file | |
path: ${{ github.workspace }}\GM-TF\results | |