Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,18 @@ The ZeroTier Github Action allows users to easily integrate
ZeroTier into their CI/CD workflows by temporarily joining and
authorizing runners onto private ZeroTier networks.

Optional tags and capabilities can be specified depending on the
configuration of your flow rules. The tags and capabilities
must be already defined on ZeroTier Central.

```yaml
- name: ZeroTier
uses: zerotier/github-action@v1.0.1
with:
network_id: ${{ secrets.ZEROTIER_NETWORK_ID }}
auth_token: ${{ secrets.ZEROTIER_CENTRAL_TOKEN }}
tags: 1000=8 2000=0
capabilities: 10 20
```

`ZEROTIER_CENTRAL_TOKEN` can be provisioned from `Account` section in the [ZeroTier Central](https://my.zerotier.com) admin panel.
Expand All @@ -33,7 +39,8 @@ It then uses the supplied `auth_token` to authorize the runner onto the network.
with:
network_id: ${{ secrets.ZEROTIER_NETWORK_ID }}
auth_token: ${{ secrets.ZEROTIER_CENTRAL_TOKEN }}

tags: 1000=8 2000=0
capabilities: 10 20
- name: ping host
shell: bash
run: |
Expand Down
14 changes: 14 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ inputs:
description: "ZeroTier Central API URL"
required: false
default: "https://my.zerotier.com/api/v1"
tags:
description: >
When provided, set tags for the network member (space-separated list of numeric "key=value" pairs).
The tags must be already defined on ZeroTier Central.
required: false
default: ""
capabilities:
description: >
When provided, set capabilities for the network member (space-separated numeric list).
The capabilities must be already defined on ZeroTier Central.
required: false
default: ""

runs:
using: "composite"
Expand All @@ -28,6 +40,8 @@ runs:
API_URL: ${{ inputs.api_url }}
AUTH_TOKEN: ${{ inputs.auth_token }}
NETWORK_ID: ${{ inputs.network_id }}
TAGS: ${{ inputs.tags }}
CAPABILITIES: ${{ inputs.capabilities }}
with:
main: $GITHUB_ACTION_PATH/main.sh
post: $GITHUB_ACTION_PATH/post.sh
13 changes: 12 additions & 1 deletion main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,21 @@ echo "⏁ Authorizing Runner to ZeroTier network"
MAX_RETRIES=10
RETRY_COUNT=0

f_tags=""
f_capabilities=""

if [ -n "$TAGS" ]; then
f_tags=$(echo "$TAGS" | awk '{ gsub(/ /, "], [", $0); gsub(/=/, ", ", $0); printf ", \"tags\": [ [%s] ]", $0; }')
fi

if [ -n "$CAPABILITIES" ]; then
f_capabilities=$(echo "$CAPABILITIES" | awk '{ gsub(/ /, ", "); printf ", \"capabilities\": [%s]", $0 }')
fi

while ! curl -s -X POST \
-H "Authorization: token $AUTH_TOKEN" \
-H "Content-Type: application/json" \
-d '{"name":"Zerotier GitHub Member '"${GITHUB_SHA::7}"'", "description": "Member created by '"${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"'", "config":{"authorized":true}}' \
-d '{"name":"Zerotier GitHub Member '"${GITHUB_SHA::7}"'", "description": "Member created by '"${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"'", "config":{"authorized":true'"${f_tags}${f_capabilities}"'}}' \
"$API_URL/network/$NETWORK_ID/member/${member_id}" | grep '"authorized":true'; do
RETRY_COUNT=$((RETRY_COUNT + 1))

Expand Down