Connection Tests - Complete #66
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Connection Tests - Complete | |
on: | |
workflow_dispatch: | |
jobs: | |
connection-tests: | |
strategy: | |
fail-fast: false | |
matrix: | |
os: | |
- ubuntu-22.04 | |
- macos-13 # macOS Arm64 connection test examples in '.github/workflows/connection-tests-arm64.yml' | |
- windows-2022 | |
profile-server: | |
- dev-team | |
- gha-automator-dev (dev-team), gha-automator-dev (qa-team) | |
vpn-mode: | |
- ovpn | |
- wg | |
client-version: | |
- from-package-manager | |
- 1.3.3814.40 | |
start-connection: | |
- true | |
- false | |
ready-profile-timeout: | |
- 5 | |
established-connection-timeout: | |
- 35 | |
concealed-outputs: | |
- true | |
- false | |
runs-on: ${{ matrix.os }} | |
name: "run:${{ matrix.os }}, ps:'${{ matrix.profile-server }}', vpn:${{ matrix.vpn-mode }}, cv:${{ matrix.client-version }}, sc:${{ matrix.start-connection }}, rpt:${{ matrix.ready-profile-timeout }}, ect:${{ matrix.established-connection-timeout }}, co:${{ matrix.concealed-outputs }}" | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 # Checkout the code to run tests | |
- name: Setup Pritunl Profile | |
id: pritunl-connection | |
uses: ./ # Use `nathanielvarona/pritunl-client-github-action@v1` for your GitHub Action workflow. | |
with: | |
profile-file: ${{ secrets.PRITUNL_PROFILE_FILE }} | |
profile-pin: ${{ secrets.PRITUNL_PROFILE_PIN }} | |
profile-server: ${{ matrix.profile-server }} | |
vpn-mode: ${{ matrix.vpn-mode }} | |
client-version: ${{ matrix.client-version }} | |
start-connection: ${{ matrix.start-connection }} | |
ready-profile-timeout: ${{ matrix.ready-profile-timeout }} | |
established-connection-timeout: ${{ matrix.established-connection-timeout }} | |
concealed-outputs: ${{ matrix.concealed-outputs }} | |
# Example of Our CI/CD Core Logic | |
# This step demonstrates our core CI/CD logic, which includes: | |
# 1. Starting a VPN connection manually (if matrix.start-connection == false) | |
# 2. Showing the VPN connection status (if matrix.start-connection == false) | |
# 3. Installing IP Calculator | |
# 4. Pinging the VPN gateway | |
# 5. Stopping the VPN connection manually (if matrix.start-connection == false) | |
# This is a simple example of how to test VPN gateway connectivity, with conditional steps for starting and stopping the VPN connection | |
- name: Starting a VPN Connection Manually | |
if: matrix.start-connection == false | |
shell: bash | |
run: | | |
# Start the VPN connection manually | |
# Get the client IDs from the previous step | |
profile_server_ids_json='${{ steps.pritunl-connection.outputs.client-ids }}' | |
# Loop through each client ID | |
while read -r line; do | |
profile_server_ids_array+=("$line") | |
done < <(echo "$profile_server_ids_json" | jq -c '.[]') | |
# Start the VPN connection for each profile server | |
for profile_server_item in "${profile_server_ids_array[@]}"; do | |
echo "Starting connection for '$(echo "$profile_server_item" | jq -r ".name")' profile server." | |
# Get the ID of the profile server | |
profile_id="$(echo "$profile_server_item" | jq -r ".id")" | |
# Start the VPN connection using the pritunl-client command | |
pritunl-client start $profile_id \ | |
--password ${{ secrets.PRITUNL_PROFILE_PIN || '' }} \ | |
--mode ${{ matrix.vpn-mode }} | |
# Wait for 2 seconds | |
sleep 2 | |
done | |
- name: Show VPN Connection Status Manually | |
if: matrix.start-connection == false | |
shell: bash | |
run: | | |
# Show VPN connection status manually | |
# Wait for 10 seconds | |
sleep 10 | |
profile_server_ids_json='${{ steps.pritunl-connection.outputs.client-ids }}' | |
profile_server_ids_array=() | |
# Loop through each client ID | |
while read -r line; do | |
profile_server_ids_array+=("$line") | |
done < <(echo "$profile_server_ids_json" | jq -c '.[]') | |
# Show the VPN connection status for each profile server | |
for profile_server_item in "${profile_server_ids_array[@]}"; do | |
echo "Establish connection for '$(echo "$profile_server_item" | jq -r ".name")' profile server." | |
# Get the ID of the profile server | |
profile_id="$(echo "$profile_server_item" | jq -r ".id")" | |
profile_name="$(echo "$profile_server_item" | jq -r ".name")" | |
# Get the VPN connection status | |
profile_server=$(pritunl-client list -j) | |
profile_ip="$(echo "$profile_server" | jq --arg profile_id "$profile_id" '.[] | select(.id == $profile_id)' | jq -r '.client_address')" | |
# Print the VPN connection status | |
echo "Connected as '$profile_name' with a private client address of '$profile_ip'." | |
# Print a new line | |
echo -n -e "\n" | |
done | |
- name: Install IP Tooling (IP Calculator) | |
shell: bash | |
run: | | |
# Install IP Calculator | |
# 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: VPN Gateway Reachability Test | |
shell: bash | |
run: | | |
# VPN Gateway Reachability Test | |
# Set the ping count | |
ping_count_number=5 | |
# Get the client IDs from the previous step | |
profile_server_ids_json='${{ steps.pritunl-connection.outputs.client-ids }}' | |
profile_server_ids_array=() | |
# Loop through each client ID | |
while read -r line; do | |
profile_server_ids_array+=("$line") | |
done < <(echo "$profile_server_ids_json" | jq -c '.[]') | |
# Ping the VPN gateway for each profile server | |
for profile_server_item in "${profile_server_ids_array[@]}"; do | |
echo "Pinging '$(echo "$profile_server_item" | jq -r ".name")' Gateway." | |
# Get the ID of the profile server | |
profile_id="$(echo "$profile_server_item" | jq -r ".id")" | |
profile_ip="$(pritunl-client list -j | jq --arg profile_id "$profile_id" '.[] | select(.id == $profile_id)' | jq -r '.client_address')" | |
# Get the VPN gateway IP | |
vpn_gateway="$(ipcalc $profile_ip | awk 'NR==6{print $2}')" | |
ping_flags="$([[ "$RUNNER_OS" == "Windows" ]] && echo "-n $ping_count_number" || echo "-c $ping_count_number")" | |
# Ping the VPN gateway | |
ping $vpn_gateway $ping_flags | |
# Print a new line | |
echo -n -e "\n" | |
done | |
- name: Stop VPN Connection Manually | |
if: matrix.start-connection == false | |
shell: bash | |
run: | | |
# Stop VPN Connection Manually | |
# Get the client IDs from the previous step | |
profile_server_ids_json='${{ steps.pritunl-connection.outputs.client-ids }}' | |
profile_server_ids_array=() | |
# Loop through each client ID | |
while read -r line; do | |
profile_server_ids_array+=("$line") | |
done < <(echo "$profile_server_ids_json" | jq -c '.[]') | |
# Stop the VPN connection for each profile server | |
for profile_server_item in "${profile_server_ids_array[@]}"; do | |
echo "Stopping connection for '$(echo "$profile_server_item" | jq -r ".name")' profile server." | |
# Get the ID of the profile server | |
profile_id="$(echo "$profile_server_item" | jq -r ".id")" | |
# Stop the VPN connection using the pritunl-client command | |
pritunl-client stop $profile_id | |
# Wait for 2 seconds | |
sleep 2 | |
done |