-
Notifications
You must be signed in to change notification settings - Fork 10
/
action.yml
53 lines (46 loc) · 1.56 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
name: 'Connect to Twingate'
description: 'Connects to Twingate protected resources from your Github Action workflow'
branding:
icon: 'arrow-right-circle'
color: 'black'
inputs:
service-key:
description: 'Twingate Service Key'
required: true
runs:
using: "composite"
steps:
- name: Install Twingate
shell: bash
run: |
echo "deb [trusted=yes] https://packages.twingate.com/apt/ /" | sudo tee /etc/apt/sources.list.d/twingate.list
sudo apt-get update -o Dir::Etc::sourcelist="sources.list.d/twingate.list" -o Dir::Etc::sourceparts="-" -o APT::Get::List-Cleanup="0"
sudo apt install -yq twingate
- name: Setup and start Twingate
shell: bash
run: |
echo '${{ inputs.service-key }}' | sudo twingate setup --headless=-
MAX_RETRIES=5
WAIT_TIME=5
n=0
while [ $n -lt $MAX_RETRIES ]; do
echo "Starting Twingate service..."
sudo twingate start
echo "Waiting $WAIT_TIME seconds for Twingate service to start..."
sleep $WAIT_TIME
status=$(sudo twingate status)
if [ "$status" = "online" ]; then
echo "Twingate service is connected."
break
else
sudo twingate stop
fi
# Increment the retry counter and wait time
n=$((n+1))
WAIT_TIME=$((WAIT_TIME+5))
echo "Twingate service is not connected. Retrying ..."
done
if [ $n -eq $MAX_RETRIES ]; then
echo "Twingate service failed to connect."
exit 1
fi