Skip to content

Commit

Permalink
Merge pull request #11 from nathanielvarona/improvements/setup-scripts
Browse files Browse the repository at this point in the history
Improve Setup Step Script
  • Loading branch information
nathanielvarona authored May 5, 2023
2 parents e113f45 + bde542d commit 26a317a
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 32 deletions.
54 changes: 34 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,54 @@ The configuration is declarative and relatively simple to use.
```yaml
- uses: nathanielvarona/pritunl-client-github-action@v1
with:
# Pritunl Profile File in `base64` format.
# Pritunl Profile File (Required)
# Type: Multiline String (Base64 format)
profile-file: ''

# The Profile Pin (Optional)
# If not supplied, which defaults no PIN
# Profile Pin (Optional)
# Type: String (Numerical value)
# If not supplied, which defaults no Pin.
profile-pin: ''

# VPN Connection Mode (Optional)
# The choices are `ovpn` or `wg`. If not supplied, which defaults to `ovpn`.
# Type: String (Choices ['ovpn' or 'wg'])
# If not supplied, which defaults to 'ovpn'.
vpn-mode: ''

# Pritunl Client Version (Optional)
# Type: String (Numerical dot separated identifiers)
# For example, using the later version `1.3.3477.58`.
# If not supplied, which defaults to the latest version from Prebuilt Apt Repository.
client-version: ''

# Start the connection (Optional)
# Boolean Type. If not supplied, which defaults to `true`
# If `true,` the VPN connection starts within the setup step.
# Start the Connection (Optional)
# Type: Boolean
# If not supplied, which defaults to `true`.
# If `true` the VPN connection starts within the setup step.
start-connection: ''


###
# Then your other steps down below.
###

- name: Your CI/CD Core Logic
run: |
##
# EXAMPLES:
# * Integration Test,
# * End-to-End Test,
# * Endpoint Reachability Test,
# * Backup Tasks,
# * And more.
##
- name: Example Cypress E2E Test
uses: cypress-io/github-action@v5
working-directory: e2e
```
> Kindly check the section [Working with Pritunl Profile File](#working-with-pritunl-profile-file) on converting `tar` binary to `base64` file format for the `pritunl-file` input.
> Kindly check the section [Working with Pritunl Profile File](#working-with-pritunl-profile-file) on converting `tar` binary to `base64` file format for the `profile-file` input.

## Examples

Expand All @@ -46,17 +71,6 @@ We have different example scenarios; any combination is possible as long the req
uses: nathanielvarona/pritunl-client-github-action@v1
with:
profile-file: ${{ secrets.PRITUNL_PROFILE_FILE }}
- name: Your CI/CD Core Logic Here
run: |
##
# EXAMPLES:
# * Integration Test,
# * End-to-End Test,
# * Endpoint Reachability Test,
# * Backup Tasks,
# * And more.
##
```

### The connection requires Pin or Password
Expand Down Expand Up @@ -102,7 +116,7 @@ We have different example scenarios; any combination is possible as long the req
sleep 10
pritunl-client list
- name: Your CI/CD Core Logic Here
- name: Your CI/CD Core Logic
run: |
##
# Below is our simple example for VPN connectivity test.
Expand Down
33 changes: 21 additions & 12 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,48 +53,57 @@ runs:
sudo apt-get --assume-yes install gnupg
gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys 7568D9BB55FF9E5287D586017AE645C0CF8E292A
gpg --armor --export 7568D9BB55FF9E5287D586017AE645C0CF8E292A | sudo tee /etc/apt/trusted.gpg.d/pritunl.asc
sudo apt-get update
sudo apt-get install pritunl-client
sudo apt-get --assume-yes update
sudo apt-get --assume-yes install pritunl-client
shell: bash

- name: Install Pritunl Client from GitHub Releases (for Version Specific)
if: ${{ inputs.client-version != 'prebuilt-apt-repo' }}
run: |
curl -s -L -o ${{ env.TEMPDIR }}/pritunl-client.deb https://github.com/pritunl/pritunl-client-electron/releases/download/${{ inputs.client-version }}/pritunl-client_${{ inputs.client-version }}-0ubuntu1.$(lsb_release -cs)_amd64.deb
sudo apt-get install -f ${{ env.TEMPDIR }}/pritunl-client.deb
sudo apt-get --assume-yes install -f ${{ env.TEMPDIR }}/pritunl-client.deb
shell: bash

- name: Install OpenVPN Dependencies for `ovpn` VPN Mode
if: ${{ inputs.vpn-mode == 'ovpn' }}
run: |
sudo apt-get install -y openvpn-systemd-resolved
sudo apt-get --assume-yes install openvpn-systemd-resolved
shell: bash

- name: Install WireGuard Dependencies for `wg` VPN Mode
if: ${{ inputs.vpn-mode == 'wg' }}
run: |
sudo apt-get install -y wireguard-tools
sudo apt-get --assume-yes install wireguard-tools
shell: bash

- name: Add Pritunl Profile to Client
id: pritunl-client
run: |
# Save the `base64` file format and convert back to `tar` binary
echo "${{ inputs.profile-file }}" > ${{ env.TEMPDIR }}/profile-file.base64
base64 --decode ${{ env.TEMPDIR }}/profile-file.base64 > ${{ env.TEMPDIR }}/profile-file.tar
# Add the Profile File to Pritunl Client
pritunl-client add ${{ env.TEMPDIR }}/profile-file.tar
echo "client-id=$(pritunl-client list | awk -F'|' 'NR==4{print $2}' | sed -E 's/^[[:space:]]+//' | sed -E 's/[[:space:]]+$//')" >> $GITHUB_OUTPUT
# Set `client-id` as step output
client_id=$(pritunl-client list | awk -F'|' 'NR==4{print $2}' | sed -E 's/^[[:space:]]+//' | sed -E 's/[[:space:]]+$//')
echo "client-id=$client_id" >> $GITHUB_OUTPUT
# Disable autotart option
pritunl-client disable $client_id
shell: bash

- name: Starting a Connection
if: ${{ inputs.start-connection == 'true' }}
run: |
# Start the Connection
pritunl-client start ${{ steps.pritunl-client.outputs.client-id }} --mode ${{ inputs.vpn-mode }} $(pritunl_pin='${{ inputs.profile-pin }}'; if [[ "$pritunl_pin" ]]; then echo "--password $pritunl_pin"; else echo ""; fi)
echo "Waiting for Connection to Active "
until pritunl-client list | awk -F '|' 'NR==4{print $8}' | sed -E 's/^[[:space:]]+//' | sed -E 's/[[:space:]]+$//' | grep -E "^([0-9]{1,3}\.){3}[0-9]{1,3}(\/[0-9]{1,2})?$"; do printf '.'; sleep 2; done
shell: bash
- name: Show the Connection
if: ${{ inputs.start-connection == 'true' }}
run: |
# Connection Probe
echo "Waiting for your IP and connection to be fully active"
sec=0;until pritunl-client list | awk -F '|' 'NR==4{print $8}' | sed -E 's/^[[:space:]]+//' | sed -E 's/[[:space:]]+$//' | grep --color=never -E "^([0-9]{1,3}\.){3}[0-9]{1,3}(\/[0-9]{1,2})?$"; do sec=$((sec+1)); echo "$sec sec."; sleep 1; done
# Show the Connection
pritunl-client list
shell: bash

0 comments on commit 26a317a

Please sign in to comment.