15
15
- Release
16
16
- RelWithDebInfo
17
17
- Debug
18
+ tunnelDurationHours :
19
+ description : " Hours amount the restricted tunnel should stay up"
20
+ required : true
21
+ default : " 1"
22
+ type : choice
23
+ options :
24
+ - " 1"
25
+ - " 2"
26
+ - " 3"
27
+ - " 4"
28
+ - " 5"
18
29
withDiscordMSG :
19
30
description : " Send Discord message after tunnel is up"
20
31
required : true
44
55
docker network create --driver nat docker_default
45
56
if ($LASTEXITCODE -ne 0) { exit 1 }
46
57
}
47
-
58
+
59
+ $sendDiscord = "${{ inputs.withDiscordMSG }}" -eq "true"
60
+ Write-Host "::notice::Should send discord message? $sendDiscord"
61
+
62
+ - name : Download Restricted Reverse Proxy binaries, setup NGINX config
63
+ run : |
64
+ Invoke-WebRequest -Uri https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-windows-amd64.exe -OutFile cloudflared.exe
65
+ Invoke-WebRequest -Uri "https://nginx.org/download/nginx-1.24.0.zip" -OutFile nginx.zip
66
+ Expand-Archive nginx.zip -DestinationPath nginx
67
+
68
+ Remove-Item -Recurse -Force "nginx/nginx-1.24.0/conf"
69
+ New-Item -ItemType Directory -Path "nginx/nginx-1.24.0/conf" -Force | Out-Null
70
+
71
+ ' ${{ secrets.NSC_BASIC_AUTH_HTPASSWD }}' | Out-File nginx/nginx-1.24.0/conf/.htpasswd -Encoding ascii
72
+ $htpasswdPath = (Resolve-Path "nginx/nginx-1.24.0/conf/.htpasswd").Path -replace '\\', '/'
73
+
74
+ @"
75
+ events {}
76
+
77
+ http {
78
+ server {
79
+ listen 10241;
80
+
81
+ location / {
82
+ auth_basic "Restricted Compiler Explorer access for Development & NSC Artifact Tests, downloaded from Nabla actions pipeline";
83
+ auth_basic_user_file "$htpasswdPath";
84
+
85
+ proxy_pass http://127.0.0.1:10240;
86
+ proxy_set_header Host `$host;
87
+ proxy_set_header X-Real-IP `$remote_addr;
88
+ }
89
+ }
90
+ }
91
+ " @ | Out-File nginx/nginx-1.24.0/conf/nginx.conf -Encoding ascii
92
+
93
+ Write-Host " ::group::Generated nginx.conf"
94
+ Get-Content nginx/nginx-1.24.0/conf/nginx.conf
95
+ Write-Host "::endgroup::"
96
+
97
+ & "nginx/nginx-1.24.0/nginx.exe" -t -p "nginx/nginx-1.24.0" -c "conf/nginx.conf"
98
+
48
99
- name : Download NSC Godbolt artifact
49
100
uses : actions/download-artifact@v4
50
101
with :
@@ -107,7 +158,7 @@ jobs:
107
158
108
159
docker compose -f compose.generated.yml up -d
109
160
110
- - name : Wait for local server on port 10240
161
+ - name : Wait for NSC container response on port
111
162
run : |
112
163
$maxRetries = 24
113
164
$retryDelay = 5
@@ -117,34 +168,35 @@ jobs:
117
168
try {
118
169
$response = Invoke-WebRequest -Uri "http://localhost:10240" -UseBasicParsing -TimeoutSec 5
119
170
if ($response.StatusCode -eq 200) {
120
- Write-Host "Local server is up and responding."
171
+ Write-Host "NSC container is up listening on port 10240 and responding."
121
172
$success = $true
122
173
break
123
174
} else {
124
175
Write-Host "Received HTTP $($response.StatusCode), retrying..."
125
176
}
126
177
} catch {
127
- Write-Host "Local server not responding yet , retrying..."
178
+ Write-Host "NSC container is not responding on port 10240 , retrying..."
128
179
}
129
180
Start-Sleep -Seconds $retryDelay
130
181
}
131
182
132
183
if (-not $success) {
133
- Write-Error "Local server on port 10240 did not respond within timeout."
184
+ Write-Error "No response from NSC container on port 10240, timeout."
134
185
exit 1
135
186
}
136
187
137
- - name : Print Container Logs
188
+ - name : Print NSC container logs
138
189
run : |
139
190
docker logs nsc-godbolt
140
191
141
- - name : Download cloudflared
192
+ - name : Start Restricted Tunnel
193
+ env :
194
+ DISCORD_ENABLED : ${{ inputs.withDiscordMSG }}
195
+ TUNNEL_DURATION_HOURS : ${{ inputs.tunnelDurationHours }}
142
196
run : |
143
- Invoke-WebRequest -Uri https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-windows-amd64.exe -OutFile cloudflared.exe
144
-
145
- - name : Start tunnel
146
- run : |
147
- Start-Process -NoNewWindow -FilePath .\cloudflared.exe -ArgumentList "tunnel", "--url", "http://localhost:10240", "--logfile", "cf.log"
197
+ Start-Process -NoNewWindow -FilePath .\nginx\nginx-1.24.0\nginx.exe -ArgumentList '-p', (Join-Path $PWD 'nginx/nginx-1.24.0'), '-c', 'conf/nginx.conf'
198
+ Start-Process -NoNewWindow -FilePath .\cloudflared.exe -ArgumentList "tunnel", "--url", "http://localhost:10241", "--logfile", "cf.log"
199
+ netstat -an | findstr 10241
148
200
149
201
$tries = 60
150
202
$url = $null
@@ -164,23 +216,27 @@ jobs:
164
216
Start-Sleep -Seconds 1
165
217
$tries -= 1
166
218
}
167
-
219
+
168
220
if (-not $url) {
169
221
Write-Error "Could not get tunnel URL from cloudflared log"
170
222
exit 1
171
223
}
172
224
173
225
$webhookUrl = "$env:DISCORD_WEBHOOK"
174
- $runId = "${{ inputs.run_id }} "
226
+ $runId = "$env:GITHUB_RUN_ID "
175
227
$actor = "$env:GITHUB_ACTOR"
176
- $startTime = (Get-Date -Format "yyyy-MM-dd HH:mm:ss")
177
228
$composedURL = "https://github.com/Devsh-Graphics-Programming/Nabla/actions/runs/$runId"
178
- $workflowRunURL = "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
179
- $sendDiscord = "${{ inputs.withDiscordMSG }}" -eq "true"
229
+ $workflowRunURL = "https://github.com/$env:GITHUB_REPOSITORY/actions/runs/$runId"
230
+ $sendDiscord = "$env:DISCORD_ENABLED" -eq "true"
231
+ $hours = [int]$env:TUNNEL_DURATION_HOURS
232
+ $duration = $hours * 3600
233
+
234
+ Write-Host "Blocking job for $hours hours"
180
235
181
236
$description = @"
182
- - tunnel opened for 5 hours, click [here](<$url>) to connect
183
- - workflow [logs #${{ github.run_id }}](<$workflowRunURL>)
237
+ - tunnel opened for $hours hours, click [here](<$url>) to connect
238
+ - requires authentication
239
+ - workflow [logs #$runId](<$workflowRunURL>)
184
240
- image downloaded from [run #$runId](<$composedURL>)
185
241
- dispatched by $actor
186
242
"@
@@ -191,16 +247,17 @@ jobs:
191
247
title = "Running NSC Godbolt Container"
192
248
description = $description
193
249
color = 15844367
194
- footer = @{
195
- text = "sent from GitHub Actions runner"
196
- }
250
+ footer = @{ text = "sent from GitHub Actions runner" }
197
251
timestamp = (Get-Date).ToString("o")
198
252
}
199
253
)
200
254
} | ConvertTo-Json -Depth 10
201
-
255
+
202
256
if ($sendDiscord) {
257
+ Write-Host "Sending Discord webhook..."
203
258
Invoke-RestMethod -Uri $webhookUrl -Method Post -ContentType 'application/json' -Body $payload
259
+ } else {
260
+ Write-Host "Discord webhook disabled"
204
261
}
205
262
206
- Start-Sleep -Seconds 18000
263
+ Start-Sleep -Seconds $duration
0 commit comments