-
Notifications
You must be signed in to change notification settings - Fork 1
/
action.yml
65 lines (58 loc) · 2.22 KB
/
action.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
name: "OpenVPN 3 Action"
description: "Using OpenVPN 3 to start a VPN session"
branding:
icon: 'shield'
color: 'yellow'
inputs:
vpn-client-config:
description: |
VPN Client Config is the OpenVPN profile file (.ovpn or .conf).
The value should be encoded on Base 64.
required: true
vpn-autoload-config:
description: |
VPN Autoload Config is the username and password file (.autoload) to support auth-user-pass
The value should be encoded on Base 64.
required: false
default: ""
script:
description: |
The script to run. The should use POSIX format as bash script.
required: true
runs:
using: "composite"
steps:
- name: Install OpenVPN 3
id: vpn-setup
run: |
export DISTRO=$(lsb_release --codename | cut -f2)
sudo apt-get install -y apt-transport-https
sudo wget https://swupdate.openvpn.net/repos/openvpn-repo-pkg-key.pub
sudo apt-key add openvpn-repo-pkg-key.pub
sudo wget -O /etc/apt/sources.list.d/openvpn3.list https://swupdate.openvpn.net/community/openvpn3/repos/openvpn3-$DISTRO.list
sudo apt-get update -y && sudo apt-get install -y openvpn3
shell: bash
- name: Setup VPN
run: |
export VPN_CLIENT_DIR=$HOME/.openvpn3/client
export VPN_CLIENT_CONFIG_PATH=$VPN_CLIENT_DIR/config.ovpn
export VPN_CLIENT_AUTOLOAD_PATH=$VPN_CLIENT_DIR/config.autoload
mkdir -m700 -p $VPN_CLIENT_DIR
echo "${{ inputs.vpn-client-config}}" | base64 --decode >> $VPN_CLIENT_CONFIG_PATH
echo "${{ inputs.vpn-autoload-config }}" | base64 --decode >> $VPN_CLIENT_AUTOLOAD_PATH
shell: bash
- name: Connect to VPN
run: |
export VPN_CLIENT_DIR=$HOME/.openvpn3/client
sudo openvpn3-autoload --directory $VPN_CLIENT_DIR
while [ -z "$(sudo openvpn3 sessions-list | grep -io 'client connected')" ]; do
sleep 0.1;
done
shell: bash
- run: sh -c "${{ inputs.script }}"
shell: bash
- name: Disconnect from VPN
run: |
sudo openvpn3 session-manage --session-path $(sudo openvpn3 sessions-list | grep -io /net/openvpn/v3/sessions/[a-z0-9]*) --disconnect
sudo rm -rf $HOME/.openvpn3
shell: bash