mirror of https://github.com/tailscale/tailscale/
.github: use cigocacher for windows
Change-Id: I0d0e9b670e49e0f9abf01ff3d605cd660dd85ebb Signed-off-by: Tom Proctor <tomhjp@users.noreply.github.com>tomhjp/cigocacher-windows
parent
411cee0dc9
commit
d25c2f3aa5
@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# This script sets up cigocacher, but should never fail the build if unsuccessful.
|
||||
# It expects to run on a GitHub-hosted runner, and connects to cigocached over a
|
||||
# private Azure network that is configured at the runner group level in GitHub.
|
||||
#
|
||||
# Usage: ./action.sh
|
||||
# Inputs:
|
||||
# URL: The cigocached server URL.
|
||||
# Outputs:
|
||||
# success: Whether cigocacher was set up successfully.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
if [ -z "${GITHUB_ACTIONS:-}" ]; then
|
||||
echo "This script is intended to run within GitHub Actions"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$URL" ]; then
|
||||
echo "No cigocached URL is set, skipping cigocacher setup"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
JWT="$(curl -sSL -H "Authorization: Bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "${ACTIONS_ID_TOKEN_REQUEST_URL}&audience=gocached" | jq -r .value)"
|
||||
# cigocached serves a TLS cert with an FQDN, but DNS is based on VM name.
|
||||
HOST_AND_PORT="${URL#http*://}"
|
||||
FIRST_LABEL="${HOST_AND_PORT/.*/}"
|
||||
BODY="$(jq -n --arg jwt "$JWT" '{"jwt": $jwt}')"
|
||||
CIGOCACHER_TOKEN="$(curl -sSL --connect-to "$HOST_AND_PORT:$FIRST_LABEL:" -H "Content-Type: application/json" "$URL/auth/exchange-token" -d "$BODY" | jq -r .access_token)"
|
||||
if [ -z "$CIGOCACHER_TOKEN" ]; then
|
||||
echo "Failed token exchange with cigocached, skipping cigocacher setup"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Wait until we successfully auth before building cigocacher to ensure we know
|
||||
# it's worth building.
|
||||
# TODO(tomhjp): bake cigocacher into runner image and use it for auth.
|
||||
echo "Fetched cigocacher token successfully"
|
||||
echo "::add-mask::${CIGOCACHER_TOKEN}"
|
||||
|
||||
BIN_NAME="cigocacher"
|
||||
if [[ "${RUNNER_OS:-}" == "Windows" ]]; then
|
||||
BIN_NAME="cigocacher.exe"
|
||||
fi
|
||||
BIN_PATH="${RUNNER_TEMP:-/tmp}/$BIN_NAME"
|
||||
|
||||
./tool/go build -o "$BIN_PATH" ./cmd/cigocacher
|
||||
echo "GOCACHEPROG=$BIN_PATH --cigocached-url $URL --token ${CIGOCACHER_TOKEN}" >> "$GITHUB_ENV"
|
||||
echo "success=true" >> "$GITHUB_OUTPUT"
|
||||
@ -0,0 +1,26 @@
|
||||
name: go-cache
|
||||
description: Set up build to use cigocacher
|
||||
|
||||
inputs:
|
||||
cigocached-url:
|
||||
description: URL of the cigocached server
|
||||
required: true
|
||||
checkout-path:
|
||||
description: Path to cloned repository
|
||||
required: true
|
||||
|
||||
outputs:
|
||||
success:
|
||||
description: Whether cigocacher was set up successfully
|
||||
value: ${{ steps.setup.outputs.success }}
|
||||
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: Setup cigocacher
|
||||
id: setup
|
||||
shell: bash
|
||||
env:
|
||||
URL: ${{ inputs.cigocached-url }}
|
||||
working-directory: ${{ inputs.checkout-path }}
|
||||
run: .github/actions/go-cache/action.sh
|
||||
Loading…
Reference in New Issue