-
Notifications
You must be signed in to change notification settings - Fork 5
221 lines (181 loc) · 8.43 KB
/
connection-tests-complete.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
name: Connection Tests - Complete
on:
workflow_dispatch:
jobs:
connection-tests:
strategy:
fail-fast: false
matrix:
os:
- ubuntu-22.04
- macos-13
- 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.3883.60
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 }}
# The steps below demonstrate how to verify VPN gateway connectivity, including:
# 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, ensuring a stable and secure 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