-
Notifications
You must be signed in to change notification settings - Fork 11
167 lines (142 loc) · 6.71 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
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 = $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)
# # Event handlers for asynchronous read
# $outputLines = New-Object System.Collections.ArrayList
# $errorLines = New-Object System.Collections.ArrayList
# $process.add_OutputDataReceived({
# param([System.Object] $sender, [System.Diagnostics.DataReceivedEventArgs] $e)
# if ($e.Data) {
# $outputLines.Add($e.Data) | Out-Null
# Write-Host $e.Data
# }
# })
# $process.add_ErrorDataReceived({
# param([System.Object] $sender, [System.Diagnostics.DataReceivedEventArgs] $e)
# if ($e.Data) {
# $errorLines.Add($e.Data) | Out-Null
# Write-Host $e.Data
# }
# })
# # Start the process and begin asynchronous read
# $process.Start() | Out-Null
# $process.BeginOutputReadLine()
# $process.BeginErrorReadLine()
# Monitor the process for timeout
while (-not $process.HasExited) {
if ((Get-Date) -gt $maxTime) {
# If execution exceeds the timeout, send a Slack notification and terminate the process
Send-SlackNotification "TestFramework build ${{ github.run_number }} exceeded the $timeoutMinutes-minute timeout and was terminated."
$process.Kill()
throw "Test Framework Build exceeded the $timeoutMinutes-minute timeout and was terminated."
}
# Read and display standard output
while (-not $process.StandardOutput.EndOfStream) {
$outputLine = $process.StandardOutput.ReadLine()
Write-Host $outputLine
$stdoutWriter.WriteLine($outputLine)
}
# Read and display standard error
while (-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 files
# $stdoutWriter.Close()
# $stderrWriter.Close()
# # Wait for the process to exit
# $process.WaitForExit()
# # Write output to log files
# Set-Content -Path $stdoutFile -Value ($outputLines -join [Environment]::NewLine)
# Set-Content -Path $stderrFile -Value ($errorLines -join [Environment]::NewLine)
# Check the exit code of the process
if ($process.ExitCode -ne 0) {
# $errorOutput = $errorLines -join [Environment]::NewLine
$errorOutput = Get-Content -Path $stderrFile -Raw
Send-SlackNotification "TestFramework build ${{ github.run_number }} 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