Skip to content

adding slack notification to channel if it loops for more than 5 mins #1100

adding slack notification to channel if it loops for more than 5 mins

adding slack notification to channel if it loops for more than 5 mins #1100

Workflow file for this run

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)
$logDirectory = "C:\Path\To\Log\Directory"
# Ensure the log directory exists
if (-not (Test-Path -Path $logDirectory)) {
New-Item -Path $logDirectory -ItemType Directory | Out-Null
}
$stdoutFile = Join-Path -Path $logDirectory -ChildPath "build_stdout.txt"
$stderrFile = Join-Path -Path $logDirectory -ChildPath "build_stderr.txt"
# Function to send Slack notification
function Send-SlackNotification {
param (
[string]$message
)
$slackPayload = @{
text = $message
} | ConvertTo-Json -Depth 10
Invoke-RestMethod -Uri "${{ secrets.SLACK_WEBHOOK_URL }}" -Method POST -ContentType "application/json" -Body $slackPayload
}
Write-Host "Starting build..."
try {
# Initialize the process start info
$startInfo = New-Object System.Diagnostics.ProcessStartInfo
$startInfo.FileName = "cmd.exe"
$startInfo.Arguments = "/c run_ci.bat C:\GM-TestFramework\configs\config_windows.json https://gms.yoyogames.com/Zeus-Runtime-Nocturnus-I.rss"
$startInfo.RedirectStandardOutput = $true
$startInfo.RedirectStandardError = $true
$startInfo.UseShellExecute = $false
$startInfo.CreateNoWindow = $true
# Start the process
$process = New-Object System.Diagnostics.Process
$process.StartInfo = $startInfo
$process.Start() | Out-Null
# Open the log files for writing
$stdoutWriter = [System.IO.StreamWriter]::new($stdoutFile, $false)
$stderrWriter = [System.IO.StreamWriter]::new($stderrFile, $false)
# Monitor the process output
while (-not $process.HasExited) {
if ((Get-Date) -gt $maxTime) {
# If looping exceeds the timeout, send a Slack notification and terminate the process
Send-SlackNotification "Build is stuck in a loop for more than $timeoutMinutes minutes. Exiting process."
$process.Kill()
throw "Test Framework Build exceeded the $timeoutMinutes-minute timeout and was terminated."
}
# Read and display standard output
if (-not $process.StandardOutput.EndOfStream) {
$outputLine = $process.StandardOutput.ReadLine()
Write-Host $outputLine
$stdoutWriter.WriteLine($outputLine)
}
# Read and display standard error
if (-not $process.StandardError.EndOfStream) {
$errorLine = $process.StandardError.ReadLine()
Write-Host $errorLine
$stderrWriter.WriteLine($errorLine)
}
Start-Sleep -Milliseconds 100
}
# Ensure all output is processed after the process exits
while (-not $process.StandardOutput.EndOfStream) {
$outputLine = $process.StandardOutput.ReadLine()
Write-Host $outputLine
$stdoutWriter.WriteLine($outputLine)
}
while (-not $process.StandardError.EndOfStream) {
$errorLine = $process.StandardError.ReadLine()
Write-Host $errorLine
$stderrWriter.WriteLine($errorLine)
}
# Close the log writers
$stdoutWriter.Close()
$stderrWriter.Close()
# Check the exit code of the process
if ($process.ExitCode -ne 0) {
$errorOutput = Get-Content -Path $stderrFile -Raw
Send-SlackNotification "Build failed with exit code $($process.ExitCode). Error details: $errorOutput"
throw "Build process exited with code $($process.ExitCode)."
} else {
Write-Host "Build completed successfully."
}
} catch {
Write-Error "An error occurred: $_"
Send-SlackNotification "An error occurred during the build process: $_"
throw
}
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