-
Notifications
You must be signed in to change notification settings - Fork 11
135 lines (115 loc) · 5.17 KB
/
CI.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
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 = "${{ github.workspace }}\GM-TF\logs"
# 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 = $false
# 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