mirror of
https://github.com/zerotier/github-action.git
synced 2026-05-22 16:27:40 -07:00
puttin on the bits
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
name: zerotier
|
||||
on: [ push ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ ubuntu-latest, macos-latest, windows-latest ]
|
||||
# os: [ windows-latest ]
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- name: checkout
|
||||
uses: actions/checkout@v3.2.0
|
||||
|
||||
- name: zerotier
|
||||
uses: ./
|
||||
with:
|
||||
network_id: ${{ secrets.ZEROTIER_NETWORK_ID }}
|
||||
auth_token: ${{ secrets.ZEROTIER_CENTRAL_TOKEN }}
|
||||
|
||||
- name: ping host
|
||||
shell: bash
|
||||
run: |
|
||||
count=10
|
||||
while ! ping -c 1 ${{ secrets.ZEROTIER_HOST_IP }} ; do
|
||||
echo "waiting..." ;
|
||||
sleep 1 ;
|
||||
let count=count-1
|
||||
done
|
||||
echo "ping success"
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
name: "ZeroTier"
|
||||
description: "Connect your Github Action workflow to ZeroTier"
|
||||
branding:
|
||||
icon: 'globe'
|
||||
color: 'gray-dark'
|
||||
|
||||
on:
|
||||
workflow_call:
|
||||
|
||||
inputs:
|
||||
network_id:
|
||||
description: "The ZeroTier network ID to connect to"
|
||||
required: true
|
||||
auth_token:
|
||||
description: "Your ZeroTier Central API Access Token"
|
||||
required: true
|
||||
api_url:
|
||||
description: "ZeroTier Central API URL"
|
||||
required: false
|
||||
default: "https://my.zerotier.com/api/v1"
|
||||
|
||||
runs:
|
||||
using: 'composite'
|
||||
steps:
|
||||
- name: zerotier
|
||||
uses: ./util/post
|
||||
with:
|
||||
main: |
|
||||
set -euo pipefail
|
||||
IFS=$'\n\t'
|
||||
|
||||
echo "⏁ Installing ZeroTier"
|
||||
|
||||
case $(uname -s) in
|
||||
MINGW64_NT?*)
|
||||
pwsh ./util/install.ps1
|
||||
ztcli="/c/Program Files (x86)/ZeroTier/One/zerotier-cli.bat"
|
||||
member_id=$("${ztcli}" info | awk '{ print $3 }')
|
||||
;;
|
||||
*)
|
||||
. ./util/install.sh &>/dev/null
|
||||
member_id=$(sudo zerotier-cli info | awk '{ print $3 }')
|
||||
;;
|
||||
esac
|
||||
|
||||
echo "⏁ Authorizing Runner to ZeroTier network"
|
||||
curl -s -X POST -H "Authorization: token ${{ inputs.auth_token }}" -d '{"config":{"authorized":true}}' "${{ inputs.api_url }}/network/${{ inputs.network_id }}/member/${member_id}"
|
||||
|
||||
echo "⏁ Joining ZeroTier Network ID: ${{ inputs.network_id }}"
|
||||
case $(uname -s) in
|
||||
MINGW64_NT?*)
|
||||
"${ztcli}" join ${{ inputs.network_id }}
|
||||
while ! "${ztcli}" listnetworks | grep ${{ inputs.network_id }} | grep OK ; do sleep 0.5 ; done
|
||||
;;
|
||||
*)
|
||||
sudo zerotier-cli join ${{ inputs.network_id }}
|
||||
while ! sudo zerotier-cli listnetworks | grep ${{ inputs.network_id }} | grep OK ; do sleep 0.5 ; done
|
||||
;;
|
||||
esac
|
||||
|
||||
post: |
|
||||
set -euo pipefail
|
||||
IFS=$'\n\t'
|
||||
|
||||
case $(uname -s) in
|
||||
MINGW64_NT?*)
|
||||
ztcli="/c/Program Files (x86)/ZeroTier/One/zerotier-cli.bat"
|
||||
member_id=$("${ztcli}" info | awk '{ print $3 }')
|
||||
;;
|
||||
*)
|
||||
member_id=$(sudo zerotier-cli info | awk '{ print $3 }')
|
||||
;;
|
||||
esac
|
||||
|
||||
echo "⏁ Removing Runner from ZeroTier network"
|
||||
curl -s -X DELETE -H "Authorization: token ${{ inputs.auth_token }}" "${{ inputs.api_url }}/network/${{ inputs.network_id }}/member/${member_id}"
|
||||
Executable
+10
@@ -0,0 +1,10 @@
|
||||
$uri="https://download.zerotier.com/dist/ZeroTierOne.msi"
|
||||
$out="ZeroTierOne.msi"
|
||||
Invoke-WebRequest -uri $uri -OutFile $out
|
||||
|
||||
$file = "ZeroTierOne.msi"
|
||||
$log = "install.log"
|
||||
$procMain = Start-Process "msiexec" "/i `"$file`" /qn /l*! `"$log`"" -NoNewWindow -PassThru
|
||||
# $procLog = Start-Process "powershell" "Get-Content -Path `"$log`" -Wait" -NoNewWindow -PassThru
|
||||
$procMain.WaitForExit()
|
||||
# $procLog.Kill()
|
||||
@@ -0,0 +1 @@
|
||||
curl -s https://install.zerotier.com/ | sudo bash
|
||||
@@ -0,0 +1,42 @@
|
||||
# ==================================================================================================================== #
|
||||
# Authors: #
|
||||
# Patrick Lehmann #
|
||||
# Unai Martinez-Corral #
|
||||
# #
|
||||
# ==================================================================================================================== #
|
||||
# Copyright 2020-2022 The pyTooling Authors #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); #
|
||||
# you may not use this file except in compliance with the License. #
|
||||
# You may obtain a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
# #
|
||||
# SPDX-License-Identifier: Apache-2.0 #
|
||||
# ==================================================================================================================== #
|
||||
name: With post step
|
||||
|
||||
description: 'Generic JS Action to execute a main command and set a command as a post step.'
|
||||
|
||||
inputs:
|
||||
main:
|
||||
description: 'Main command/script.'
|
||||
required: true
|
||||
post:
|
||||
description: 'Post command/script.'
|
||||
required: true
|
||||
key:
|
||||
description: 'Name of the state variable used to detect the post step.'
|
||||
required: false
|
||||
default: POST
|
||||
|
||||
runs:
|
||||
using: 'node16'
|
||||
main: 'main.js'
|
||||
post: 'main.js'
|
||||
@@ -0,0 +1,45 @@
|
||||
/* ================================================================================================================== *
|
||||
* Authors: *
|
||||
* Unai Martinez-Corral *
|
||||
* *
|
||||
* ================================================================================================================== *
|
||||
* Copyright 2021-2022 Unai Martinez-Corral <unai.martinezcorral@ehu.eus> *
|
||||
* Copyright 2022 Unai Martinez-Corral <umartinezcorral@antmicro.com> *
|
||||
* *
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); *
|
||||
* you may not use this file except in compliance with the License. *
|
||||
* You may obtain a copy of the License at *
|
||||
* *
|
||||
* http://www.apache.org/licenses/LICENSE-2.0 *
|
||||
* *
|
||||
* Unless required by applicable law or agreed to in writing, software *
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, *
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
|
||||
* See the License for the specific language governing permissions and *
|
||||
* limitations under the License. *
|
||||
* *
|
||||
* SPDX-License-Identifier: Apache-2.0 *
|
||||
* ================================================================================================================== *
|
||||
* *
|
||||
* Context: *
|
||||
* * https://github.com/docker/login-action/issues/72 *
|
||||
* * https://github.com/actions/runner/issues/1478 *
|
||||
* ================================================================================================================== */
|
||||
const { spawn } = require("child_process");
|
||||
const fs = require('fs');
|
||||
|
||||
function run(cmd) {
|
||||
const subprocess = spawn(cmd, { stdio: "inherit", shell: "bash" });
|
||||
subprocess.on("exit", (exitCode) => {
|
||||
process.exitCode = exitCode;
|
||||
});
|
||||
}
|
||||
|
||||
const key = process.env.INPUT_KEY.toUpperCase();
|
||||
|
||||
if ( process.env[`STATE_${key}`] !== undefined ) { // Are we in the 'post' step?
|
||||
run(process.env.INPUT_POST);
|
||||
} else { // Otherwise, this is the main step
|
||||
fs.appendFileSync(process.env.GITHUB_STATE, `${key}=true`);
|
||||
run(process.env.INPUT_MAIN);
|
||||
}
|
||||
Reference in New Issue
Block a user