Skip to content

Commit

Permalink
feat: Add other OS on test workflow and autostart on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
AnimMouse committed Aug 30, 2023
1 parent 0699d1c commit d282b42
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 8 deletions.
65 changes: 63 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,82 @@ on:
- scripts/**
- shutdown/action.yml
- .github/workflows/test.yaml
pull_request:
paths:
- action.yml
- scripts/**
- shutdown/action.yml
- .github/workflows/test.yaml

jobs:
test:
test-ubuntu:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
version: [latest, 2023.8.1]

steps:
- name: Setup cloudflared using setup-cloudflared
uses: AnimMouse/setup-cloudflared@main
with:
cloudflare_tunnel_credential: ${{ secrets.CLOUDFLARE_TUNNEL_CREDENTIAL }}
cloudflare_tunnel_configuration: ${{ secrets.CLOUDFLARE_TUNNEL_CONFIGURATION }}
cloudflare_tunnel_configuration: ${{ secrets.CLOUDFLARE_TUNNEL_CONFIGURATION_UBUNTU }}
cloudflare_tunnel_id: ${{ secrets.CLOUDFLARE_TUNNEL_ID }}

- name: Test cloudflared installed by setup-cloudflared using Python HTTP server for 1 minute
run: timeout 1m python -m http.server 8080 || true

- name: Shutdown cloudflared using setup-cloudflared/shutdown
if: always()
uses: AnimMouse/setup-cloudflared/shutdown@main

test-macos:
runs-on: macos-latest
strategy:
fail-fast: false
matrix:
version: [latest, 2023.8.1]

steps:
- name: Setup cloudflared using setup-cloudflared
uses: AnimMouse/setup-cloudflared@main
with:
cloudflare_tunnel_credential: ${{ secrets.CLOUDFLARE_TUNNEL_CREDENTIAL }}
cloudflare_tunnel_configuration: ${{ secrets.CLOUDFLARE_TUNNEL_CONFIGURATION_MACOS }}
cloudflare_tunnel_id: ${{ secrets.CLOUDFLARE_TUNNEL_ID }}

- name: Test cloudflared installed by setup-cloudflared using Python HTTP server for 1 minute
run: |
function timeout(){ perl -e 'alarm shift; exec @ARGV' "$@"; }
timeout 60 python3 -m http.server 8080 || true
- name: Shutdown cloudflared using setup-cloudflared/shutdown
if: always()
uses: AnimMouse/setup-cloudflared/shutdown@main

test-windows:
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
version: [latest, 2023.8.1]

steps:
- name: Setup cloudflared using setup-cloudflared
uses: AnimMouse/setup-cloudflared@main
with:
cloudflare_tunnel_credential: ${{ secrets.CLOUDFLARE_TUNNEL_CREDENTIAL }}
cloudflare_tunnel_configuration: ${{ secrets.CLOUDFLARE_TUNNEL_CONFIGURATION_WINDOWS }}
cloudflare_tunnel_id: ${{ secrets.CLOUDFLARE_TUNNEL_ID }}

- name: Test cloudflared installed by setup-cloudflared using Python HTTP server for 1 minute
run: |
$http_server = Start-Process "python" "-m http.server 8080" -PassThru
Wait-Process $http_server.Id -Timeout 60 -ErrorAction Ignore
Stop-Process $http_server.Id
Wait-Process $http_server.Id
- name: Shutdown cloudflared using setup-cloudflared/shutdown
if: always()
uses: AnimMouse/setup-cloudflared/shutdown@main
7 changes: 6 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,9 @@ runs:
- name: Start Cloudflare Tunnel in the background on Unix-like
if: (runner.os == 'Linux' || runner.os == 'macOS') && inputs.autostart != 'false'
shell: bash
run: $GITHUB_ACTION_PATH/scripts/autostart/Unix-like.sh
run: $GITHUB_ACTION_PATH/scripts/autostart/Unix-like.sh

- name: Start Cloudflare Tunnel in the background on Windows
if: runner.os == 'Windows' && inputs.autostart != 'false'
shell: pwsh
run: '& $env:GITHUB_ACTION_PATH\scripts\autostart\Windows.ps1'
5 changes: 5 additions & 0 deletions scripts/autostart/Windows.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
$ErrorActionPreference = 'Stop'
Set-StrictMode -Version Latest
Write-Host ::group::Autostarting cloudflared for Windows
Start-Process "cloudflared" "--pidfile $env:RUNNER_TEMP/cloudflared.pid --logfile $env:RUNNER_TEMP/cloudflared.log tunnel run"
Write-Host ::endgroup::
1 change: 1 addition & 0 deletions scripts/download/Windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ $ErrorActionPreference = 'Stop'
$ProgressPreference = 'SilentlyContinue'
Set-StrictMode -Version Latest
Write-Host ::group::Downloading cloudflared $env:version for Windows
New-Item cloudflared -ItemType Directory -Force
Invoke-WebRequest $env:GITHUB_SERVER_URL/cloudflare/cloudflared/releases/download/$env:version/cloudflared-windows-amd64.exe -OutFile cloudflared\cloudflared.exe
Write-Host ::endgroup::
26 changes: 21 additions & 5 deletions shutdown/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,30 @@ branding:
runs:
using: composite
steps:
- name: Shutdown Cloudflare Tunnel
- name: Shutdown cloudflared for Unix-like
if: runner.os == 'Linux' || runner.os == 'macOS'
shell: bash
working-directory: ${{ runner.temp }}
run: |
kill $(cat cloudflared.pid)
tail --pid=$(cat cloudflared.pid) -f /dev/null
kill $(< cloudflared.pid)
if [ $RUNNER_OS = macOS ]; then lsof -p $(< cloudflared.pid) +r 1 &>/dev/null; else tail --pid=$(< cloudflared.pid) -f /dev/null; fi
- name: View logs of Cloudflare Tunnel
- name: View logs of cloudflared for Unix-like
if: runner.os == 'Linux' || runner.os == 'macOS'
shell: bash
working-directory: ${{ runner.temp }}
run: cat cloudflared.log
run: cat cloudflared.log

- name: Shutdown cloudflared for Windows
if: runner.os == 'Windows'
shell: pwsh
working-directory: ${{ runner.temp }}
run: |
Stop-Process $(Get-Content cloudflared.pid)
Wait-Process -Id $(Get-Content cloudflared.pid)
- name: View logs of cloudflared for Windows
if: runner.os == 'Windows'
shell: pwsh
working-directory: ${{ runner.temp }}
run: Get-Content cloudflared.log

0 comments on commit d282b42

Please sign in to comment.