-
Notifications
You must be signed in to change notification settings - Fork 105
/
Copy pathaction.yml
205 lines (205 loc) · 8.29 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
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
# Copyright (c) Tailscale Inc & AUTHORS
# SPDX-License-Identifier: BSD-3-Clause
#
name: 'Connect Tailscale'
description: 'Connect your GitHub Action workflow to Tailscale'
branding:
icon: 'arrow-right-circle'
color: 'gray-dark'
inputs:
authkey:
description: 'Your Tailscale authentication key, from the admin panel.'
required: false
deprecationMessage: 'An OAuth API client https://tailscale.com/s/oauth-clients is recommended instead of an authkey'
oauth-client-id:
description: 'Your Tailscale OAuth Client ID.'
required: false
oauth-secret:
description: 'Your Tailscale OAuth Client Secret.'
required: false
tags:
description: 'Comma separated list of Tags to be applied to nodes. The OAuth client must have permission to apply these tags.'
required: false
version:
description: 'Tailscale version to use. Specify `latest` to use the latest stable version.'
required: true
default: '1.78.1'
sha256sum:
description: 'Expected SHA256 checksum of the tarball.'
required: false
default: ''
args:
description: 'Optional additional arguments to `tailscale up`'
required: false
default: ''
tailscaled-args:
description: 'Optional additional arguments to `tailscaled`'
required: false
default: ''
hostname:
description: 'Fixed hostname to use.'
required: false
default: ''
statedir:
description: 'Optional state directory to use (if unset, memory state is used)'
required: false
default: ''
timeout:
description: 'Timeout for `tailscale up`'
required: false
default: '2m'
runs:
using: 'composite'
steps:
- name: Check Runner OS
if: ${{ runner.os != 'Linux' && runner.os != 'Windows' && runner.os != 'macOS'}}
shell: bash
run: |
echo "::error title=⛔ error hint::Support Linux, Windows, and macOS Only"
exit 1
- name: Check Auth Info Empty
if: ${{ inputs.authkey == '' && (inputs['oauth-secret'] == '' || inputs.tags == '') }}
shell: bash
run: |
echo "::error title=⛔ error hint::OAuth identity empty, Maybe you need to populate it in the Secrets for your workflow, see more in https://docs.github.com/en/actions/security-guides/encrypted-secrets and https://tailscale.com/s/oauth-clients"
exit 1
- name: Set Resolved Version
shell: bash
run: |
VERSION=${{ inputs.version }}
if [ "$VERSION" = "latest" ]; then
RESOLVED_VERSION=$(curl -H user-agent:tailscale-github-action -s "https://pkgs.tailscale.com/stable/?mode=json" | jq -r .Version)
else
RESOLVED_VERSION=$VERSION
fi
echo "RESOLVED_VERSION=$RESOLVED_VERSION" >> $GITHUB_ENV
echo "Resolved Tailscale version: $RESOLVED_VERSION"
- name: Download Tailscale - Linux
if: ${{ runner.os == 'Linux' }}
shell: bash
env:
SHA256SUM: ${{ inputs.sha256sum }}
run: |
if [ ${{ runner.arch }} = "ARM64" ]; then
TS_ARCH="arm64"
elif [ ${{ runner.arch }} = "ARM" ]; then
TS_ARCH="arm"
elif [ ${{ runner.arch }} = "X86" ]; then
TS_ARCH="386"
else
TS_ARCH="amd64"
fi
MINOR=$(echo "$RESOLVED_VERSION" | awk -F '.' {'print $2'})
if [ $((MINOR % 2)) -eq 0 ]; then
URL="https://pkgs.tailscale.com/stable/tailscale_${RESOLVED_VERSION}_${TS_ARCH}.tgz"
else
URL="https://pkgs.tailscale.com/unstable/tailscale_${RESOLVED_VERSION}_${TS_ARCH}.tgz"
fi
echo "Downloading $URL"
curl -H user-agent:tailscale-github-action -L "$URL" -o tailscale.tgz --max-time 300 --fail
if ! [[ "$SHA256SUM" ]] ; then
SHA256SUM="$(curl -H user-agent:tailscale-github-action -L "${URL}.sha256" --fail)"
fi
echo "Expected sha256: $SHA256SUM"
echo "Actual sha256: $(sha256sum tailscale.tgz)"
echo "$SHA256SUM tailscale.tgz" | sha256sum -c
tar -C /tmp -xzf tailscale.tgz
rm tailscale.tgz
TSPATH=/tmp/tailscale_${RESOLVED_VERSION}_${TS_ARCH}
sudo mv "${TSPATH}/tailscale" "${TSPATH}/tailscaled" /usr/bin
- name: Download Tailscale - Windows
if: ${{ runner.os == 'Windows' }}
shell: bash
env:
SHA256SUM: ${{ inputs.sha256sum }}
run: |
if [ ${{ runner.arch }} = "ARM64" ]; then
TS_ARCH="arm64"
elif [ ${{ runner.arch }} = "X86" ]; then
TS_ARCH="x86"
else
TS_ARCH="amd64"
fi
MINOR=$(echo "$RESOLVED_VERSION" | awk -F '.' {'print $2'})
if [ $((MINOR % 2)) -eq 0 ]; then
URL="https://pkgs.tailscale.com/stable/tailscale-setup-${RESOLVED_VERSION}-${TS_ARCH}.msi"
else
URL="https://pkgs.tailscale.com/unstable/tailscale-setup-${RESOLVED_VERSION}-${TS_ARCH}.msi"
fi
echo "Downloading $URL"
curl -H user-agent:tailscale-github-action -L "$URL" -o tailscale.msi --max-time 300 --fail
if ! [[ "$SHA256SUM" ]] ; then
SHA256SUM="$(curl -H user-agent:tailscale-github-action -L "${URL}.sha256" --fail)"
fi
echo "Expected sha256: $SHA256SUM"
echo "Actual sha256: $(sha256sum tailscale.msi)"
echo "$SHA256SUM tailscale.msi" | sha256sum -c
- name: Install Tailscale - Windows
if: ${{ runner.os == 'Windows' }}
shell: pwsh
run: |
Start-Process "C:\Windows\System32\msiexec.exe" -Wait -ArgumentList @('/quiet', '/l*v tailscale.log', '/i', 'tailscale.msi')
Add-Content $env:GITHUB_PATH "C:\Program Files\Tailscale\"
Remove-Item tailscale.msi -Force;
- name: Checkout Tailscale repo - macOS
if: ${{ runner.os == 'macOS' }}
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
repository: tailscale/tailscale
path: ${{ github.workspace }}/tailscale
ref: v${{ env.RESOLVED_VERSION }}
- name: Build Tailscale binaries - macOS
if: ${{ runner.os == 'macOS' }}
shell: bash
run: |
cd tailscale
export TS_USE_TOOLCHAIN=1
./build_dist.sh ./cmd/tailscale
./build_dist.sh ./cmd/tailscaled
sudo mv tailscale tailscaled /usr/local/bin
- name: Install timeout - macOS
if: ${{ runner.os == 'macOS' }}
shell: bash
run:
brew install coreutils # for 'timeout'
- name: Start Tailscale Daemon - non-Windows
if: ${{ runner.os != 'Windows' }}
shell: bash
env:
ADDITIONAL_DAEMON_ARGS: ${{ inputs.tailscaled-args }}
STATEDIR: ${{ inputs.statedir }}
run: |
if [ "$STATEDIR" == "" ]; then
STATE_ARGS="--state=mem:"
else
STATE_ARGS="--statedir=${STATEDIR}"
mkdir -p "$STATEDIR"
fi
sudo -E tailscaled ${STATE_ARGS} ${ADDITIONAL_DAEMON_ARGS} 2>~/tailscaled.log &
# And check that tailscaled came up. The CLI will block for a bit waiting
# for it. And --json will make it exit with status 0 even if we're logged
# out (as we will be). Without --json it returns an error if we're not up.
sudo -E tailscale status --json >/dev/null
- name: Connect to Tailscale
shell: bash
env:
ADDITIONAL_ARGS: ${{ inputs.args }}
HOSTNAME: ${{ inputs.hostname }}
TAILSCALE_AUTHKEY: ${{ inputs.authkey }}
TIMEOUT: ${{ inputs.timeout }}
run: |
if [ -z "${HOSTNAME}" ]; then
if [ "${{ runner.os }}" == "Windows" ]; then
HOSTNAME="github-$COMPUTERNAME"
else
HOSTNAME="github-$(hostname)"
fi
fi
if [ -n "${{ inputs['oauth-secret'] }}" ]; then
TAILSCALE_AUTHKEY="${{ inputs['oauth-secret'] }}?preauthorized=true&ephemeral=true"
TAGS_ARG="--advertise-tags=${{ inputs.tags }}"
fi
if [ "${{ runner.os }}" != "Windows" ]; then
MAYBE_SUDO="sudo -E"
fi
timeout --verbose --kill-after=1s ${TIMEOUT} ${MAYBE_SUDO} tailscale up ${TAGS_ARG} --authkey=${TAILSCALE_AUTHKEY} --hostname=${HOSTNAME} --accept-routes ${ADDITIONAL_ARGS}