Skip to content

Connection Tests - Manual Control #1

Connection Tests - Manual Control

Connection Tests - Manual Control #1

name: Connection Tests - Manual Control
on:
workflow_dispatch:
jobs:
connection-tests:
strategy:
fail-fast: false
matrix:
os:
- ubuntu-22.04
- macos-13
- windows-2022
runs-on: ${{ matrix.os }}
name: "run:${{ matrix.os }}"
steps:
- name: Checkout
uses: actions/checkout@v4 # Checkout the code to run tests
- name: Setup Pritunl Profile
id: pritunl-connection # A `Setup Step ID` has been added as a reference identifier for the output `client-id`.
uses: ./ # Use `nathanielvarona/pritunl-client-github-action@v1` for your GitHub Action workflow.
with:
profile-file: ${{ secrets.PRITUNL_PROFILE_FILE }}
start-connection: false # Do not establish a connection in this step.
# Example of Our CI/CD Core Logic
# This step demonstrates our core CI/CD logic, which includes:
# 1. Installing IP Calculator
# 2. Start VPN Connection Manually
# 3. Show VPN Connection Status Manually
# 4. Pinging the VPN gateway
# 5. Stop VPN Connection Manually
# This is a simple example of how to test VPN gateway connectivity
# Start VPN connection using stored client ID and password (if available)
- name: Start VPN Connection Manually
shell: bash
run: |
pritunl-client start ${{ steps.pritunl-connection.outputs.client-id }} \
--password ${{ secrets.PRITUNL_PROFILE_PIN || '' }}
# Wait for 10 seconds to allow the connection to establish
sleep 10
# Display VPN connection status
- name: Show VPN Connection Status Manually
shell: bash
run: |
pritunl-client list -j | jq 'sort_by(.name) | .[0] | { "Profile Name": .name, "Client Address": .client_address }'
# Show the profile name and client address
- name: Install IP Calculator
shell: bash
run: |
# Install IP Calculator based on the runner OS
if [ "$RUNNER_OS" == "Linux" ]; then
sudo apt-get install -qq -o=Dpkg::Use-Pty=0 -y ipcalc
elif [ "$RUNNER_OS" == "macOS" ]; then
brew install -q ipcalc
elif [ "$RUNNER_OS" == "Windows" ]; then
# Retry up to 3 times in case of failure
for attempt in $(seq 3); do
if curl -sSL "https://raw.githubusercontent.com/kjokjo/ipcalc/0.51/ipcalc" \
-o $HOME/bin/ipcalc && chmod +x $HOME/bin/ipcalc; then
break
else
echo "Attempt $attempt failed. Retrying..." && sleep 1
# If all retries fail, exit with an error
if [ $attempt -eq 3 ]; then
echo "Failed to install ipcalc after 3 attempts." && exit 1
fi
fi
done
fi
# Validate the IP Calculator Installation
echo "ipcalc version $(ipcalc --version)"
- name: Ping VPN Gateway
shell: bash
run: |
# Set the ping count
ping_count_number=5
# Get the Profile ID Details
profile_ip=$(pritunl-client list -j | jq -r 'sort_by(.name) | .[0].client_address')
vpn_gateway="$(ipcalc $profile_ip | awk 'NR==6{print $2}')"
# Construct the Ping Flags
ping_flags="$([[ "$RUNNER_OS" == "Windows" ]] && echo "-n $ping_count_number" || echo "-c $ping_count_number")"
# Ping the VPN gateway
ping $vpn_gateway $ping_flags
# Stop VPN connection using stored client ID (always run, even on failure)
- name: Stop VPN Connection Manually
if: ${{ always() }}
shell: bash
run: |
pritunl-client stop ${{ steps.pritunl-connection.outputs.client-id }}
# Stop the VPN connection