Skip to content

Commit 6cae46e

Browse files
authored
Merge pull request #195 from tailscale/max/test-target-connectivity-check
Added argument to test targets connectivity
2 parents 0263d9e + 2208a5a commit 6cae46e

File tree

2 files changed

+94
-33
lines changed

2 files changed

+94
-33
lines changed

README.md

Lines changed: 53 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ This GitHub Action connects to your [Tailscale network](https://tailscale.com)
44
by adding a step to your workflow.
55

66
```yaml
7-
- name: Tailscale
8-
uses: tailscale/github-action@v3
9-
with:
10-
oauth-client-id: ${{ secrets.TS_OAUTH_CLIENT_ID }}
11-
oauth-secret: ${{ secrets.TS_OAUTH_SECRET }}
12-
tags: tag:ci
7+
- name: Tailscale
8+
uses: tailscale/github-action@v3
9+
with:
10+
oauth-client-id: ${{ secrets.TS_OAUTH_CLIENT_ID }}
11+
oauth-secret: ${{ secrets.TS_OAUTH_SECRET }}
12+
tags: tag:ci
1313
```
1414
1515
Subsequent steps in the Action can then access nodes in your Tailnet.
@@ -29,6 +29,28 @@ be automatically removed by the coordination server a short time after they
2929
finish their run. The nodes are also [marked Preapproved](https://tailscale.com/kb/1085/auth-keys/)
3030
on tailnets which use [Device Approval](https://tailscale.com/kb/1099/device-approval/)
3131

32+
## Eventual consistency
33+
34+
Propagating information about new peers - such as the node created by this action - across your tailnet
35+
is an eventually consistent process, and brief delays are expected. Until the GitHub workflow node
36+
becomes visible, other peers will not accept connections. It is best to verify connectivity to the
37+
intended nodes before executing steps that rely on them.
38+
39+
You can do this by adding a list of targets to the action configuration:
40+
41+
```yaml
42+
- name: Tailscale
43+
uses: tailscale/github-action@v3
44+
with:
45+
targets: 100.x.y.z,my-machine.my-tailnet.ts.net
46+
```
47+
48+
or with the [tailscale ping](https://tailscale.com/kb/1080/cli#ping) command if you do not know the targets at the time of installing Tailscale in the workflow:
49+
50+
```bash
51+
tailscale ping my-target.my-tailnet.ts.net
52+
```
53+
3254
## Tailnet Lock
3355

3456
If you are using this Action in a [Tailnet
@@ -42,37 +64,37 @@ Lock](https://tailscale.com/kb/1226/tailnet-lock) enabled network, you need to:
4264
client to store the Tailnet Key Authority data in.
4365

4466
```yaml
45-
- name: Tailscale
46-
uses: tailscale/github-action@v3
47-
with:
48-
authkey: tskey-auth-...
49-
statedir: /tmp/tailscale-state/
67+
- name: Tailscale
68+
uses: tailscale/github-action@v3
69+
with:
70+
authkey: tskey-auth-...
71+
statedir: /tmp/tailscale-state/
5072
```
5173

5274
## Defining Tailscale version
5375

5476
Which Tailscale version to use can be set like this:
5577

5678
```yaml
57-
- name: Tailscale
58-
uses: tailscale/github-action@v3
59-
with:
60-
oauth-client-id: ${{ secrets.TS_OAUTH_CLIENT_ID }}
61-
oauth-secret: ${{ secrets.TS_OAUTH_SECRET }}
62-
tags: tag:ci
63-
version: 1.52.0
79+
- name: Tailscale
80+
uses: tailscale/github-action@v3
81+
with:
82+
oauth-client-id: ${{ secrets.TS_OAUTH_CLIENT_ID }}
83+
oauth-secret: ${{ secrets.TS_OAUTH_SECRET }}
84+
tags: tag:ci
85+
version: 1.52.0
6486
```
6587

6688
If you'd like to specify the latest version, simply set the version as `latest`
6789

6890
```yaml
69-
- name: Tailscale
70-
uses: tailscale/github-action@v3
71-
with:
72-
oauth-client-id: ${{ secrets.TS_OAUTH_CLIENT_ID }}
73-
oauth-secret: ${{ secrets.TS_OAUTH_SECRET }}
74-
tags: tag:ci
75-
version: latest
91+
- name: Tailscale
92+
uses: tailscale/github-action@v3
93+
with:
94+
oauth-client-id: ${{ secrets.TS_OAUTH_CLIENT_ID }}
95+
oauth-secret: ${{ secrets.TS_OAUTH_SECRET }}
96+
tags: tag:ci
97+
version: latest
7698
```
7799

78100
You can find the latest Tailscale stable version number at
@@ -86,10 +108,10 @@ Caching can reduce download times and download failures on runners with slower n
86108
You can opt in to caching Tailscale binaries by passing `'true'` to the `use-cache` input:
87109

88110
```yaml
89-
- name: Tailscale
90-
uses: tailscale/github-action@v3
91-
with:
92-
oauth-client-id: ${{ secrets.TS_OAUTH_CLIENT_ID }}
93-
oauth-secret: ${{ secrets.TS_OAUTH_SECRET }}
94-
use-cache: 'true'
111+
- name: Tailscale
112+
uses: tailscale/github-action@v3
113+
with:
114+
oauth-client-id: ${{ secrets.TS_OAUTH_CLIENT_ID }}
115+
oauth-secret: ${{ secrets.TS_OAUTH_SECRET }}
116+
use-cache: 'true'
95117
```

action.yml

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ inputs:
5656
description: 'Whether to cache the Tailscale binaries (Linux/macOS) or installer (Windows)'
5757
required: false
5858
default: 'false'
59+
targets:
60+
description: 'Comma separated list of targets (Tailscale IP addresses or machine names if MagicDNS is enabled on the tailnet) to `tailscale ping` for connectivity verification after `tailscale up` completes'
61+
required: false
62+
default: ''
5963
runs:
6064
using: 'composite'
6165
steps:
@@ -150,7 +154,7 @@ runs:
150154
URL="https://pkgs.tailscale.com/unstable/tailscale_${RESOLVED_VERSION}_${TS_ARCH}.tgz"
151155
fi
152156
echo "Downloading $URL"
153-
curl -H user-agent:tailscale-github-action -L "$URL" -o tailscale.tgz --max-time 300 --fail
157+
curl -H user-agent:tailscale-github-action -L "$URL" -o tailscale.tgz --max-time 300 --retry 3 --retry-all-errors --fail
154158
echo "Expected sha256: $SHA256SUM"
155159
echo "Actual sha256: $(sha256sum tailscale.tgz)"
156160
echo "$SHA256SUM tailscale.tgz" | sha256sum -c
@@ -209,7 +213,7 @@ runs:
209213
URL="https://pkgs.tailscale.com/unstable/tailscale-setup-${RESOLVED_VERSION}-${TS_ARCH}.msi"
210214
fi
211215
echo "Downloading $URL"
212-
curl -H user-agent:tailscale-github-action -L "$URL" -o tailscale.msi --max-time 300 --fail
216+
curl -H user-agent:tailscale-github-action -L "$URL" -o tailscale.msi --max-time 300 --retry 3 --retry-all-errors --fail
213217
echo "Expected sha256: $SHA256SUM"
214218
echo "Actual sha256: $(sha256sum tailscale.msi)"
215219
echo "$SHA256SUM tailscale.msi" | sha256sum -c
@@ -353,3 +357,38 @@ runs:
353357
echo "Tailscale up failed. Retrying in $((i * 5)) seconds..."
354358
sleep $((i * 5))
355359
done
360+
- name: Verify Target Connectivity
361+
if: ${{ inputs.targets != '' }}
362+
shell: bash
363+
env:
364+
TARGETS: ${{ inputs.targets }}
365+
run: |
366+
IFS=',' read -ra TARGET_ARRAY <<< "$TARGETS"
367+
368+
if [ "${{ runner.os }}" != "Windows" ]; then
369+
MAYBE_SUDO="sudo -E"
370+
fi
371+
372+
failed_targets=()
373+
for target in "${TARGET_ARRAY[@]}"; do
374+
target=$(echo "$target" | xargs) # trim whitespace
375+
if [ -n "$target" ]; then
376+
output=$(${MAYBE_SUDO} tailscale ping --c=36 $target 2>&1)
377+
exit_code=$?
378+
379+
if [ $exit_code -eq 0 ]; then
380+
echo "Successfully reached $target"
381+
elif echo "$output" | grep -q "direct connection not established"; then
382+
echo "::warning title=Target Connectivity Warning::Failed to establish direct connection to $target but was able to connect via DERP"
383+
else
384+
# Regular failure case
385+
echo "Failed to reach $target"
386+
failed_targets+=("$target")
387+
fi
388+
fi
389+
done
390+
391+
if [ ${#failed_targets[@]} -gt 0 ]; then
392+
echo "::error title=Target Connectivity Failed::Failed to reach the following targets: ${failed_targets[*]}"
393+
exit 1
394+
fi

0 commit comments

Comments
 (0)