diff --git a/.github/workflows/publish-action.yml b/.github/workflows/publish-action.yml
new file mode 100644
index 0000000..cbdfcfe
--- /dev/null
+++ b/.github/workflows/publish-action.yml
@@ -0,0 +1,14 @@
+name: publish-action
+on:
+ release:
+ types: released
+concurrency: ${{ github.workflow }}
+jobs:
+ publish-action:
+ permissions:
+ contents: write
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/publish-action@v0.2.2
+ with:
+ source-tag: ${{ github.event.release.tag_name }}
diff --git a/.github/workflows/test-action.yml b/.github/workflows/test-action.yml
new file mode 100644
index 0000000..ebe7ee0
--- /dev/null
+++ b/.github/workflows/test-action.yml
@@ -0,0 +1,35 @@
+name: Test action
+on:
+ push:
+ branches: "main"
+ paths-ignore:
+ - .gitignore
+ - README.md
+ - LICENSE
+ - .github/**
+ - "!.github/workflows/test-action.yml"
+ - start/**
+ - stop/**
+ pull_request:
+ paths-ignore:
+ - .gitignore
+ - README.md
+ - LICENSE
+ - .github/**
+ - "!.github/workflows/test-action.yml"
+ - start/**
+ - stop/**
+concurrency:
+ group: ${{ github.workflow }}-${{ github.ref }}
+ cancel-in-progress: true
+jobs:
+ test-action:
+ strategy:
+ fail-fast: false
+ matrix:
+ os: [ubuntu-latest, macos-latest, windows-latest]
+ runs-on: ${{ matrix.os }}
+ steps:
+ - uses: actions/checkout@v4
+ - uses: ./
+ - run: cloudflared --version
diff --git a/.github/workflows/test-start-stop.yml b/.github/workflows/test-start-stop.yml
new file mode 100644
index 0000000..7bdc7bb
--- /dev/null
+++ b/.github/workflows/test-start-stop.yml
@@ -0,0 +1,37 @@
+name: Test start & stop
+on:
+ push:
+ branches: "main"
+ paths-ignore:
+ - .gitignore
+ - README.md
+ - LICENSE
+ - .github/**
+ - "!.github/workflows/test-start-stop.yml"
+ pull_request:
+ paths-ignore:
+ - .gitignore
+ - README.md
+ - LICENSE
+ - .github/**
+ - "!.github/workflows/test-start-stop.yml"
+concurrency:
+ group: ${{ github.workflow }}-${{ github.ref }}
+ cancel-in-progress: true
+jobs:
+ test-start-stop:
+ strategy:
+ fail-fast: false
+ matrix:
+ os: [ubuntu-latest, macos-latest, windows-latest]
+ runs-on: ${{ matrix.os }}
+ steps:
+ - uses: actions/checkout@v4
+ - uses: ./
+ - uses: ./start
+ with:
+ run: npx -y serve
+ url: http://localhost:3000
+ - shell: bash
+ run: sleep 100
+ - uses: ./stop
diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml
deleted file mode 100644
index 4ea8ab8..0000000
--- a/.github/workflows/test.yaml
+++ /dev/null
@@ -1,87 +0,0 @@
-name: Test setup-cloudflared
-on:
- push:
- paths:
- - action.yml
- - scripts/**
- - shutdown/action.yml
- - .github/workflows/test.yaml
- pull_request:
- paths:
- - action.yml
- - scripts/**
- - shutdown/action.yml
- - .github/workflows/test.yaml
-
-jobs:
- 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_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
- $http_server.CloseMainWindow()
- Wait-Process $http_server.Id
-
- - name: Shutdown cloudflared using setup-cloudflared/shutdown
- if: always()
- uses: AnimMouse/setup-cloudflared/shutdown@main
\ No newline at end of file
diff --git a/README.md b/README.md
index cafcf28..5415033 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,61 @@
+# Setup Cloudflare Tunnel client
+
+🚛 Installs `cloudflared` for GitHub Actions
+
+
+
+![](https://i.imgur.com/fCYSI7n.png)
+
+
+
+📦 Downloads & installs the `cloudflared` binary \
+🚀 Zero-config to get started; supports [`config.yml`](https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/get-started/create-local-tunnel/#4-create-a-configuration-file) for advanced use \
+▶️ Includes start & stop sub-actions for [Cloudflare Quick Tunnels](https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/do-more-with-tunnels/trycloudflare/) \
+🌈 Works on Windows, macOS, and Linux runners
+
+## Usage
+
+![GitHub Actions](https://img.shields.io/static/v1?style=for-the-badge&message=GitHub+Actions&color=2088FF&logo=GitHub+Actions&logoColor=FFFFFF&label=)
+![GitHub](https://img.shields.io/static/v1?style=for-the-badge&message=GitHub&color=181717&logo=GitHub&logoColor=FFFFFF&label=)
+
+**🚀 Here's what you want:**
+
+```yml
+on: push
+jobs:
+ job:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+ - uses: AnimMouse/setup-cloudflared@v2
+ - uses: AnimMouse/setup-cloudflared/start@v2
+ with:
+ run: npx -y serve
+ url: http://localhost:3000
+ - run: sleep 100
+ - uses: AnimMouse/setup-cloudflared/stop@v2 # OPTIONAL
+```
+
+[📚 Read more about Cloudflare Tunnels and the Cloudflare Tunnel Client](https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/)
+
+### Options
+
+There's only one option so far. If you want to see automatic login or similar,
+just open an Issue! ❤️
+
+- **`cloudflared-version`:** Specifies which version of cloudflared to install from the GitHub Releases page. Note that cloudflared uses a date-based versioning scheme. The default value for this field is `latest` which will automagically default to the latest GitHub Release. This field does support semver ranges like `^2023.0.0`.
+
+- **`cloudflared-token`:** The GitHub token to use when fetching the version list from [cloudflare/cloudflared](https://github.com/cloudflare/cloudflared/releases). You shouldn't have to touch this. The default is the `github.token` if you're on github.com or unauthenticated (rate limited) if you're not on github.com.
+
+## Development
+
+![Bash](https://img.shields.io/static/v1?style=for-the-badge&message=Bash&color=4EAA25&logo=GNU+Bash&logoColor=FFFFFF&label=)
+![PowerShell](https://img.shields.io/static/v1?style=for-the-badge&message=PowerShell&color=5391FE&logo=PowerShell&logoColor=FFFFFF&label=)
+
+This GitHub action is build using Bash.
+
# Setup cloudflared for GitHub Actions
+
Setup [Cloudflare Tunnel client](https://github.com/cloudflare/cloudflared) for GitHub Actions.
This action installs [cloudflared](https://github.com/cloudflare/cloudflared) for use in actions by installing it on tool cache using [AnimMouse/tool-cache](https://github.com/AnimMouse/tool-cache).
@@ -10,6 +67,7 @@ This GitHub action participated on [GitHub Actions Hackathon 2021](https://dev.t
Test page for setup-cloudflared: https://setup-cloudflared.44444444.xyz (This will only work when the test action is running.)
## Usage
+
1. Encode the JSON credential in Base64 using this command `base64 -w 0 .json` and paste it to `CLOUDFLARE_TUNNEL_CREDENTIAL` secret.
2. At the config.yaml, set `credentials-file:` to:
1. Ubuntu: `/home/runner/.cloudflared/.json`
@@ -29,10 +87,10 @@ steps:
cloudflare_tunnel_credential: ${{ secrets.CLOUDFLARE_TUNNEL_CREDENTIAL }}
cloudflare_tunnel_configuration: ${{ secrets.CLOUDFLARE_TUNNEL_CONFIGURATION }}
cloudflare_tunnel_id: ${{ secrets.CLOUDFLARE_TUNNEL_ID }}
-
+
- name: Start Python HTTP server
run: timeout 5m python -m http.server 8080 || true
-
+
- name: Shutdown and view logs of cloudflared
if: always()
uses: AnimMouse/setup-cloudflared/shutdown@v1
@@ -49,12 +107,13 @@ steps:
cloudflare_tunnel_configuration: ${{ secrets.CLOUDFLARE_TUNNEL_CONFIGURATION }}
cloudflare_tunnel_id: ${{ secrets.CLOUDFLARE_TUNNEL_ID }}
autostart: false
-
+
- name: Manually start cloudflared
run: timeout 5m cloudflared tunnel run || true
```
### Specific version
+
You can specify the version you want. By default, this action downloads the latest version if version is not specified.
```yaml
@@ -69,6 +128,7 @@ steps:
```
### GitHub token
+
This action automatically uses a GitHub token in order to authenticate with GitHub API and avoid rate limiting. You can also specify your own read-only fine-grained personal access token.
```yaml
@@ -83,7 +143,9 @@ steps:
```
### Example config.yaml file
+
Ubuntu:
+
```yaml
url: http://localhost:8080
tunnel: deadbeef-1234-4321-abcd-123456789abc
@@ -91,6 +153,7 @@ credentials-file: /home/runner/.cloudflared/deadbeef-1234-4321-abcd-123456789abc
```
Windows:
+
```yaml
url: http://localhost:8080
tunnel: deadbeef-1234-4321-abcd-123456789abc
@@ -98,6 +161,7 @@ credentials-file: C:\Users\runneradmin\.cloudflared\deadbeef-1234-4321-abcd-1234
```
macOS:
+
```yaml
url: http://localhost:8080
tunnel: deadbeef-1234-4321-abcd-123456789abc
@@ -105,7 +169,8 @@ credentials-file: /Users/runner/.cloudflared/deadbeef-1234-4321-abcd-123456789ab
```
### Similar actions
+
1. [vmactions/cf-tunnel](https://github.com/vmactions/cf-tunnel)
2. [apogiatzis/ngrok-tunneling-action](https://github.com/apogiatzis/ngrok-tunneling-action)
3. [vmactions/ngrok-tunnel](https://github.com/vmactions/ngrok-tunnel)
-4. [debugci/setup-cloudflared](https://github.com/debugci/setup-cloudflared)
\ No newline at end of file
+4. [debugci/setup-cloudflared](https://github.com/debugci/setup-cloudflared)
diff --git a/action.yml b/action.yml
index 31b75c4..e65c6d9 100644
--- a/action.yml
+++ b/action.yml
@@ -1,94 +1,32 @@
-name: Setup cloudflared
-description: Setup/Install Cloudflare Tunnel client for GitHub Actions
+name: Setup Cloudflare Tunnel client
+description: 🚛 Installs cloudflared for GitHub Actions
+
branding:
icon: cloud
color: orange
+
inputs:
- cloudflare_tunnel_credential:
- description: Cloudflare Tunnel Credential encoded in Base64 (deadbeef-1234-4321-abcd-123456789abc.json)
- required: true
- cloudflare_tunnel_configuration:
- description: Cloudflare Tunnel Configuration encoded in Base64 (config.yaml)
- required: true
- cloudflare_tunnel_id:
- description: Cloudflare Tunnel ID (deadbeef-1234-4321-abcd-123456789abc)
- required: true
- autostart:
- description: Autostart cloudflared in the background
- default: true
- version:
- description: cloudflared version
+ cloudflared-version:
+ description: Specifies which version of cloudflared to install from the GitHub Releases page. Note that cloudflared uses a date-based versioning scheme. The default value for this field is 'latest' which will automagically default to the latest GitHub Release. This field does support semver ranges like '^2023.0.0'.
default: latest
- token:
- description: GitHub token to avoid API rate limiting
- default: ${{ github.token }}
-
+ cloudflared-token:
+ description: The GitHub token to use when fetching the version list from cloudflare/cloudflared. You shouldn't have to touch this. The default is the github.token if you're on github.com or unauthenticated (rate limited) if you're not on github.com.
+ default: ${{ github.server_url == 'https://github.com' && github.token || '' }}
+
+outputs:
+ cloudflared-version:
+ description: The version of cloudflared that was installed. This will be something like '2023.8.8' or similar.
+ value: ${{ steps.main.outputs.couldflared-version }}
+ cache-hit:
+ description: Whether or not cloudflared was restored from the runner's cache or download anew.
+ value: ${{ steps.main.outputs.cache-hit }}
+
runs:
using: composite
steps:
- - name: Get cloudflared version for Unix-like
- id: version-unix-like
- if: runner.os == 'Linux' || runner.os == 'macOS'
+ - id: main
shell: bash
- run: $GITHUB_ACTION_PATH/scripts/version/Unix-like.sh
+ run: bash "$GITHUB_ACTION_PATH/main.sh"
env:
- version: ${{ inputs.version }}
- GITHUB_TOKEN: ${{ inputs.token }}
-
- - name: Get cloudflared version for Windows
- id: version-windows
- if: runner.os == 'Windows'
- shell: pwsh
- run: '& $env:GITHUB_ACTION_PATH\scripts\version\Windows.ps1'
- env:
- version: ${{ inputs.version }}
- GITHUB_TOKEN: ${{ inputs.token }}
-
- - name: Download cloudflared for Unix-like
- if: runner.os == 'Linux' || runner.os == 'macOS'
- shell: bash
- working-directory: ${{ runner.temp }}
- run: $GITHUB_ACTION_PATH/scripts/download/Unix-like.sh
- env:
- version: ${{ steps.version-unix-like.outputs.version }}
-
- - name: Download cloudflared for Windows
- if: runner.os == 'Windows'
- shell: pwsh
- working-directory: ${{ runner.temp }}
- run: '& $env:GITHUB_ACTION_PATH\scripts\download\Windows.ps1'
- env:
- version: ${{ steps.version-windows.outputs.version }}
-
- - name: Install cloudflared on tool cache
- uses: AnimMouse/tool-cache@v1
- with:
- folder_name: cloudflared
-
- - name: Sign in to cloudflared on Unix-like
- if: runner.os == 'Linux' || runner.os == 'macOS'
- shell: bash
- run: $GITHUB_ACTION_PATH/scripts/sign-in/Unix-like.sh
- env:
- cloudflare_tunnel_credential: ${{ inputs.cloudflare_tunnel_credential }}
- cloudflare_tunnel_configuration: ${{ inputs.cloudflare_tunnel_configuration }}
- cloudflare_tunnel_id: ${{ inputs.cloudflare_tunnel_id }}
-
- - name: Sign in to cloudflared on Windows
- if: runner.os == 'Windows'
- shell: pwsh
- run: '& $env:GITHUB_ACTION_PATH\scripts\sign-in\Windows.ps1'
- env:
- cloudflare_tunnel_credential: ${{ inputs.cloudflare_tunnel_credential }}
- cloudflare_tunnel_configuration: ${{ inputs.cloudflare_tunnel_configuration }}
- cloudflare_tunnel_id: ${{ inputs.cloudflare_tunnel_id }}
-
- - name: Start cloudflared 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
-
- - name: Start cloudflared in the background on Windows
- if: runner.os == 'Windows' && inputs.autostart != 'false'
- shell: pwsh
- run: '& $env:GITHUB_ACTION_PATH\scripts\autostart\Windows.ps1'
\ No newline at end of file
+ INPUT_CLOUDFLARED_VERSION: ${{ inputs.cloudflared-version }}
+ INPUT_CLOUDFLARED_TOKEN: ${{ inputs.cloudflared-token }}
diff --git a/main.sh b/main.sh
new file mode 100644
index 0000000..f1134a0
--- /dev/null
+++ b/main.sh
@@ -0,0 +1,64 @@
+#!/usr/bin/env bash
+set -e
+if [[ $RUNNER_DEBUG == 1 ]]; then set -x; fi
+
+export GH_TOKEN=$INPUT_CLOUDFLARED_TOKEN
+
+temp_dir="$RUNNER_TEMP/$RANDOM"
+mkdir "$temp_dir"
+pushd "$temp_dir"
+
+case $(uname -m) in
+ 'x86_64') node_arch="x64";;
+ 'aarch64' | 'arm64') node_arch="arm64";;
+ *) echo "Unknown arch $(uname -m)"; exit 1;;
+esac
+
+if [[ $INPUT_CLOUDFLARED_VERSION == latest ]]; then
+ base_url="https://github.com/cloudflare/cloudflared/releases/latest/download/"
+else
+ base_url="https://github.com/cloudflare/cloudflared/releases/download/$INPUT_CLOUDFLARED_VERSION/"
+fi
+
+tool_cache_dir="$RUNNER_TOOL_CACHE/cloudflared/$version/$node_arch"
+echo "cache-hit=$(test -d "$tool_cache_dir")" >> "$GITHUB_OUTPUT"
+if [[ ! -d $tool_cache_dir ]]; then
+ if [[ $(uname -sm) == "Darwin x86_64" ]]; then
+ file=cloudflared-darwin-amd64.tgz
+
+ url="$base_url$file"
+ echo "Fetching $file v$version from $url"
+ curl -fsSLO "$url"
+ tar -xzvf "$file"
+ chmod +x cloudflared
+ mkdir -p "$tool_cache_dir"
+ mv cloudflared "$tool_cache_dir/cloudflared"
+ else
+ if [ "$OS" = "Windows_NT" ]; then
+ target="windows-amd64"
+ else
+ case $(uname -sm) in
+ 'Linux x86_64') target="linux-amd64";;
+ 'Linux aarch64' | 'Linux arm64') target="linux-arm64";;
+ *) echo "Unknown OS/arch $(uname -sm)"; exit 1;;
+ esac
+ fi
+
+ if [ "$OS" = "Windows_NT" ]; then
+ exe_ext=".exe"
+ fi
+
+ file="cloudflared-$target$exe_ext"
+
+ url="$base_url$file"
+ echo "Fetching $file v$version from $url"
+ curl -fsSLO "$url"
+ chmod +x "$file"
+ mkdir -p "$tool_cache_dir"
+ mv "$file" "$tool_cache_dir/cloudflared$exe_ext"
+ fi
+fi
+
+echo "$tool_cache_dir" >> "$GITHUB_PATH"
+echo "cloudflared-version=$version" >> "$GITHUB_OUTPUT"
+echo "✅ Cloudflare Tunnel Client v$version installed!"
diff --git a/scripts/autostart/Unix-like.sh b/scripts/autostart/Unix-like.sh
deleted file mode 100755
index c8285a8..0000000
--- a/scripts/autostart/Unix-like.sh
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/bin/sh
-set -eu
-echo ::group::Autostarting cloudflared for $RUNNER_OS
-nohup cloudflared --pidfile $RUNNER_TEMP/cloudflared.pid --logfile $RUNNER_TEMP/cloudflared.log tunnel run &
-echo ::endgroup::
\ No newline at end of file
diff --git a/scripts/autostart/Windows.ps1 b/scripts/autostart/Windows.ps1
deleted file mode 100644
index 8b1261e..0000000
--- a/scripts/autostart/Windows.ps1
+++ /dev/null
@@ -1,5 +0,0 @@
-$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::
\ No newline at end of file
diff --git a/scripts/download/Unix-like.sh b/scripts/download/Unix-like.sh
deleted file mode 100755
index 41c8951..0000000
--- a/scripts/download/Unix-like.sh
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/bin/sh
-set -eu
-echo ::group::Downloading cloudflared $version for $RUNNER_OS
-mkdir -p cloudflared
-if [ $RUNNER_OS = macOS ]
-then
- wget -qO- $GITHUB_SERVER_URL/cloudflare/cloudflared/releases/download/$version/cloudflared-darwin-amd64.tgz | tar -xz -C cloudflared cloudflared
-else
- wget -q -O cloudflared/cloudflared $GITHUB_SERVER_URL/cloudflare/cloudflared/releases/download/$version/cloudflared-linux-amd64
- chmod +x cloudflared/cloudflared
-fi
-echo ::endgroup::
\ No newline at end of file
diff --git a/scripts/download/Windows.ps1 b/scripts/download/Windows.ps1
deleted file mode 100644
index 9ccb33e..0000000
--- a/scripts/download/Windows.ps1
+++ /dev/null
@@ -1,7 +0,0 @@
-$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::
\ No newline at end of file
diff --git a/scripts/sign-in/Unix-like.sh b/scripts/sign-in/Unix-like.sh
deleted file mode 100755
index f310ca6..0000000
--- a/scripts/sign-in/Unix-like.sh
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/bin/sh
-set -eu
-echo ::group::Signing in to Cloudflare Tunnel client
-mkdir ~/.cloudflared
-echo "$cloudflare_tunnel_credential" | base64 -d > ~/.cloudflared/$cloudflare_tunnel_id.json
-echo "$cloudflare_tunnel_configuration" | base64 -d > ~/.cloudflared/config.yaml
-echo ::endgroup::
\ No newline at end of file
diff --git a/scripts/sign-in/Windows.ps1 b/scripts/sign-in/Windows.ps1
deleted file mode 100644
index 0805735..0000000
--- a/scripts/sign-in/Windows.ps1
+++ /dev/null
@@ -1,9 +0,0 @@
-$ErrorActionPreference = 'Stop'
-Set-StrictMode -Version Latest
-Write-Host ::group::Signing in to Cloudflare Tunnel client
-New-Item $env:USERPROFILE\.cloudflared -ItemType Directory -Force
-$cloudflare_tunnel_credential = [Convert]::FromBase64String($env:cloudflare_tunnel_credential)
-$cloudflare_tunnel_configuration = [Convert]::FromBase64String($env:cloudflare_tunnel_configuration)
-[IO.File]::WriteAllBytes("$env:USERPROFILE\.cloudflared\$env:cloudflare_tunnel_id.json", $cloudflare_tunnel_credential)
-[IO.File]::WriteAllBytes("$env:USERPROFILE\.cloudflared\config.yaml", $cloudflare_tunnel_configuration)
-Write-Host ::endgroup::
\ No newline at end of file
diff --git a/scripts/version/Unix-like.sh b/scripts/version/Unix-like.sh
deleted file mode 100755
index 216408b..0000000
--- a/scripts/version/Unix-like.sh
+++ /dev/null
@@ -1,9 +0,0 @@
-#!/bin/sh
-set -eu
-if [ "$version" = latest ]
-then
- latest_version=$(gh api repos/cloudflare/cloudflared/releases/latest -q .tag_name)
- echo "version=$latest_version" >> $GITHUB_OUTPUT
-else
- echo "version=$version" >> $GITHUB_OUTPUT
-fi
\ No newline at end of file
diff --git a/scripts/version/Windows.ps1 b/scripts/version/Windows.ps1
deleted file mode 100644
index f7e9dc0..0000000
--- a/scripts/version/Windows.ps1
+++ /dev/null
@@ -1,9 +0,0 @@
-$ErrorActionPreference = 'Stop'
-Set-StrictMode -Version Latest
-if ($env:version -eq 'latest') {
- $latest_version = (gh api repos/cloudflare/cloudflared/releases/latest -q .tag_name)
- Add-Content $env:GITHUB_OUTPUT version=$latest_version
-}
-else {
- Add-Content $env:GITHUB_OUTPUT version=$env:version
-}
\ No newline at end of file
diff --git a/shutdown/action.yml b/shutdown/action.yml
deleted file mode 100644
index 8b61b53..0000000
--- a/shutdown/action.yml
+++ /dev/null
@@ -1,36 +0,0 @@
-name: Shutdown cloudflared
-description: Shutdown Cloudflare Tunnel autostarted by setup-cloudflared
-branding:
- icon: cloud-off
- color: orange
-
-runs:
- using: composite
- steps:
- - name: Shutdown cloudflared for Unix-like
- if: runner.os == 'Linux' || runner.os == 'macOS'
- shell: bash
- working-directory: ${{ runner.temp }}
- run: |
- 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 cloudflared for Unix-like
- if: runner.os == 'Linux' || runner.os == 'macOS'
- shell: bash
- working-directory: ${{ runner.temp }}
- run: cat cloudflared.log
-
- - name: Shutdown cloudflared for Windows
- if: runner.os == 'Windows'
- shell: pwsh
- working-directory: ${{ runner.temp }}
- run: |
- (Get-Process -Id $(Get-Content cloudflared.pid)).CloseMainWindow()
- 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
\ No newline at end of file
diff --git a/start/action.yml b/start/action.yml
new file mode 100644
index 0000000..0a5d8c0
--- /dev/null
+++ b/start/action.yml
@@ -0,0 +1,20 @@
+inputs:
+ run: {}
+ url:
+ required: true
+
+runs:
+ using: composite
+ steps:
+ - if: runner.os == 'Windows'
+ shell: bash
+ run: pwsh "$GITHUB_ACTION_PATH/main.ps1"
+ env:
+ INPUT_URL: ${{ inputs.url }}
+ INPUT_RUN: ${{ inputs.run }}
+ - if: runner.os != 'Windows'
+ shell: bash
+ run: bash "$GITHUB_ACTION_PATH/main.sh"
+ env:
+ INPUT_URL: ${{ inputs.url }}
+ INPUT_RUN: ${{ inputs.run }}
diff --git a/start/main.ps1 b/start/main.ps1
new file mode 100644
index 0000000..11620e1
--- /dev/null
+++ b/start/main.ps1
@@ -0,0 +1,19 @@
+# Set strict error handling
+Set-StrictMode -Version Latest
+
+# Start cloudflared in the background, capturing output and errors
+Start-Process -FilePath "cloudflared" -ArgumentList @(
+ "--pidfile", "$env:RUNNER_TEMP\cloudflared.pid",
+ "--logfile", "$env:RUNNER_TEMP\cloudflared.log",
+ "tunnel", "--url", "$env:INPUT_URL"
+) -NoNewWindow -Wait -RedirectStandardOutput "$env:RUNNER_TEMP\cloudflared.log" -RedirectStandardError "$env:RUNNER_TEMP\cloudflared.log"
+
+# Run the specified command if provided
+if ($env:INPUT_RUN) {
+ Start-Process -FilePath "powershell.exe" -ArgumentList @(
+ "-Command", "$env:INPUT_RUN"
+ ) -NoNewWindow -Wait -RedirectStandardOutput "$env:RUNNER_TEMP\run.log" -RedirectStandardError "$env:RUNNER_TEMP\run.log"
+ $processId = Get-Process -Id $PID | Select-Object -ExpandProperty ParentProcessId
+ $processId | Out-File "$env:RUNNER_TEMP\run.pid"
+ $env:INPUT_RUN | Out-File "$env:RUNNER_TEMP\run.sh"
+}
diff --git a/start/main.sh b/start/main.sh
new file mode 100644
index 0000000..f4a821d
--- /dev/null
+++ b/start/main.sh
@@ -0,0 +1,13 @@
+#!/usr/bin/env bash
+set -ex
+
+nohup cloudflared \
+ --pidfile "$RUNNER_TEMP/cloudflared.pid" \
+ --logfile "$RUNNER_TEMP/cloudflared.log" \
+ tunnel --url "$INPUT_URL" &
+
+if [[ -n $INPUT_RUN ]]; then
+ bash -ec "$INPUT_RUN" > "$RUNNER_TEMP/run.log" 2>&1 &
+ echo $! > "$RUNNER_TEMP/run.pid"
+ echo "$INPUT_RUN" > "$RUNNER_TEMP/run.sh"
+fi
\ No newline at end of file
diff --git a/stop/action.yml b/stop/action.yml
new file mode 100644
index 0000000..fbddda7
--- /dev/null
+++ b/stop/action.yml
@@ -0,0 +1,9 @@
+runs:
+ using: composite
+ steps:
+ - if: runner.os == 'Windows'
+ shell: bash
+ run: pwsh "$GITHUB_ACTION_PATH/main.ps1"
+ - if: runner.os != 'Windows'
+ shell: bash
+ run: bash "$GITHUB_ACTION_PATH/main.sh"
diff --git a/stop/main.ps1 b/stop/main.ps1
new file mode 100644
index 0000000..9adbb3c
--- /dev/null
+++ b/stop/main.ps1
@@ -0,0 +1,22 @@
+# Set strict error handling
+Set-StrictMode -Version Latest
+
+# Terminate cloudflared process
+$cloudflaredPid = Get-Content "$env:RUNNER_TEMP\cloudflared.pid"
+Stop-Process -Id $cloudflaredPid -Force
+
+# Display cloudflared log
+Write-Host "::group::cloudflared"
+Get-Content "$env:RUNNER_TEMP\cloudflared.log"
+Write-Host "::endgroup::"
+
+# Terminate and display run.sh logs if the file exists
+if (Test-Path "$env:RUNNER_TEMP\run.sh") {
+ $runPid = Get-Content "$env:RUNNER_TEMP\run.pid"
+ Stop-Process -Id $runPid -Force
+
+ $runCommand = Get-Content "$env:RUNNER_TEMP\run.sh" | Select-Object -First 1
+ Write-Host "::group::$runCommand"
+ Get-Content "$env:RUNNER_TEMP\run.log"
+ Write-Host "::endgroup::"
+}
diff --git a/stop/main.sh b/stop/main.sh
new file mode 100644
index 0000000..c06b36c
--- /dev/null
+++ b/stop/main.sh
@@ -0,0 +1,16 @@
+#!/usr/bin/env bash
+set -ex
+
+kill "$(< "$RUNNER_TEMP/cloudflared.pid")"
+
+echo "::group::cloudflared"
+cat "$RUNNER_TEMP/cloudflared.log"
+echo "::endgroup::"
+
+if [[ -f "$RUNNER_TEMP/run.sh" ]]; then
+ kill "$(< "$RUNNER_TEMP/run.pid")"
+
+ echo "::group::$(cat "$RUNNER_TEMP/run.sh" | head -n1)"
+ cat "$RUNNER_TEMP/run.log"
+ echo "::endgroup::"
+fi
\ No newline at end of file