Connection Tests - Complete #58
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 | |
- ubuntu-20.04 | |
- macos-13 | |
- macos-12 | |
- windows-2022 | |
- windows-2019 | |
profile-server: | |
- gha-automator-dev (dev-team) | |
- dev-team, qa-team | |
vpn-mode: | |
- ovpn | |
- wg | |
client-version: | |
- from-package-manager | |
- 1.3.3814.40 | |
start-connection: | |
- 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 }}" | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- 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: 5 | |
established-connection-timeout: 35 | |
- name: Starting a VPN Connection Manually | |
if: matrix.start-connection == false | |
shell: bash | |
run: | | |
# Start the VPN Connection Manually | |
profile_server_ids_json='${{ steps.pritunl-connection.outputs.client-ids }}' | |
while read -r line; do | |
profile_server_ids_array+=("$line") | |
done < <(echo "$profile_server_ids_json" | jq -c '.[]') | |
for profile_server_item in "${profile_server_ids_array[@]}"; do | |
echo "Starting connection for '$(echo "$profile_server_item" | jq -r ".name")' profile server." | |
profile_id="$(echo "$profile_server_item" | jq -r ".id")" | |
pritunl-client start $profile_id \ | |
--password ${{ secrets.PRITUNL_PROFILE_PIN || '' }} \ | |
--mode ${{ matrix.vpn-mode }} | |
sleep 2 | |
done | |
- name: Show VPN Connection Status Manually | |
if: matrix.start-connection == false | |
shell: bash | |
run: | | |
# Show VPN Connection Status Manually | |
sleep 10 | |
profile_server_ids_json='${{ steps.pritunl-connection.outputs.client-ids }}' | |
profile_server_ids_array=() | |
while read -r line; do | |
profile_server_ids_array+=("$line") | |
done < <(echo "$profile_server_ids_json" | jq -c '.[]') | |
for profile_server_item in "${profile_server_ids_array[@]}"; do | |
echo "Establish connection for '$(echo "$profile_server_item" | jq -r ".name")' profile server." | |
profile_id="$(echo "$profile_server_item" | jq -r ".id")" | |
profile_name="$(echo "$profile_server_item" | jq -r ".name")" | |
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')" | |
echo "Connected as '$profile_name' with a private client address of '$profile_ip'." | |
# Print new line | |
echo -n -e "\n" | |
done | |
- name: Install IP Tooling (IP Calculator) | |
shell: bash | |
run: | | |
# Install IP Calculator | |
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 | |
ping_count_number=5 | |
profile_server_ids_json='${{ steps.pritunl-connection.outputs.client-ids }}' | |
profile_server_ids_array=() | |
while read -r line; do | |
profile_server_ids_array+=("$line") | |
done < <(echo "$profile_server_ids_json" | jq -c '.[]') | |
for profile_server_item in "${profile_server_ids_array[@]}"; do | |
echo "Pinging '$(echo "$profile_server_item" | jq -r ".name")' Gateway." | |
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')" | |
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 VPN Gateway | |
ping $vpn_gateway $ping_flags | |
# Print new line | |
echo -n -e "\n" | |
done | |
- name: Stop VPN Connection Manually | |
if: matrix.start-connection == false | |
shell: bash | |
run: | | |
# Stop Connection Manually | |
profile_server_ids_json='${{ steps.pritunl-connection.outputs.client-ids }}' | |
profile_server_ids_array=() | |
while read -r line; do | |
profile_server_ids_array+=("$line") | |
done < <(echo "$profile_server_ids_json" | jq -c '.[]') | |
for profile_server_item in "${profile_server_ids_array[@]}"; do | |
echo "Stopping connection for '$(echo "$profile_server_item" | jq -r ".name")' profile server." | |
profile_id="$(echo "$profile_server_item" | jq -r ".id")" | |
pritunl-client stop $profile_id | |
sleep 2 | |
done |