0% found this document useful (0 votes)
5 views2 pages

CI Workflow for Ngrok Setup

This document outlines a CI workflow that runs on Windows, which includes steps to download and set up ngrok, configure remote desktop settings, and start an ngrok tunnel. It also includes mechanisms to wait for ngrok to initialize and retrieve its public URL, followed by a cleanup process to terminate the ngrok process after a specified wait time. The workflow is triggered on push events or manually through workflow dispatch.

Uploaded by

ld866353
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

CI Workflow for Ngrok Setup

This document outlines a CI workflow that runs on Windows, which includes steps to download and set up ngrok, configure remote desktop settings, and start an ngrok tunnel. It also includes mechanisms to wait for ngrok to initialize and retrieve its public URL, followed by a cleanup process to terminate the ngrok process after a specified wait time. The workflow is triggered on push events or manually through workflow dispatch.

Uploaded by

ld866353
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

name: CI

on: [push, workflow_dispatch]

jobs:
build:
runs-on: windows-latest

steps:
- name: Download
run: Invoke-WebRequest [Link]
[Link] -OutFile [Link]

- name: Extract
run: Expand-Archive [Link]

- name: Auth
run: .\ngrok\[Link] authtoken $Env:NGROK_AUTH_TOKEN
env:
NGROK_AUTH_TOKEN: ${{ secrets.NGROK_AUTH_TOKEN }}

- name: Enable TS
run: Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal
Server'-name "fDenyTSConnections" -Value 0

- run: Enable-NetFirewallRule -DisplayGroup "Remote Desktop"

- run: Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal


Server\WinStations\RDP-Tcp' -name "UserAuthentication" -Value 1

- run: Set-LocalUser -Name "runneradmin" -Password (ConvertTo-SecureString -


AsPlainText "P@ssw0rd!" -Force)

- name: Start ngrok in the background


run: Start-Process -FilePath ".\ngrok\[Link]" -ArgumentList "tcp 3389"

- name: Wait for ngrok to start


run: Start-Sleep -Seconds 5

- name: Get ngrok tunnel information


run: |
$maxAttempts = 20
$attempts = 0
$ngrokApi = $null

while (($null -eq $ngrokApi) -and ($attempts -lt $maxAttempts)) {


$attempts += 1
try {
$ngrokApi = Invoke-WebRequest "[Link]
} catch {
Write-Host "Waiting for ngrok API... (attempt $attempts of
$maxAttempts)"
Start-Sleep -Seconds 5
}
}

if ($null -eq $ngrokApi) {


throw "Failed to connect to ngrok API after $maxAttempts attempts."
}
$ngrokUrl = ($ngrokApi | ConvertFrom-Json).tunnels[0].public_url
Write-Host "Ngrok URL: $ngrokUrl"

- name: Wait before cleanup


run: Start-Sleep -Seconds 3600

- name: Cleanup
if: always()
run: |
$ngrokProcess = Get-Process -Name "ngrok" -ErrorAction SilentlyContinue
if ($null -ne $ngrokProcess) {
Write-Host "Terminating ngrok process..."
$ngrokProcess | Stop-Process -Force
} else {
Write-Host "Ngrok process not found."
}

- name: Cleanup
if: always()
run: |
$ngrokProcess = Get-Process -Name "ngrok" -ErrorAction SilentlyContinue
if ($null -ne $ngrokProcess) {
Write-Host "Terminating ngrok process..."
$ngrokProcess | Stop-Process -Force
} else {
Write-Host "Ngrok process not found."
}

You might also like