Files
Christopher Britton 292543a68a Add ref build and LTS line selectors to setup-cli action (#3962)
* Add main-branch source build to setup-cli action

* Add active-lts/maint-lts selectors to setup-cli action

* Build from source via dedicated ref input instead of version: main for  setup-cli action
2026-06-10 16:07:10 -04:00

129 lines
4.7 KiB
YAML

name: ziti-cli
description: Get ziti binary and add it to the PATH
inputs:
version:
required: false
default: stable
description: |
which released ziti CLI to download, one of:
- 'stable' (default): the release GitHub marks `latest`
- 'active-lts': latest release on the active LTS line (lts-versions.json)
- 'maint-lts': latest release on the maintenance LTS line (lts-versions.json)
- a tag or tag-regex (like 'v1.6' or '2.0.[0-9]+$'): latest release matching it
ignored when 'ref' is set.
ref:
required: false
default: ""
description: |
branch, tag, or commit of openziti/ziti to build the CLI from source
instead of downloading a release. overrides 'version' when set.
outputs:
version:
value: ${{ steps.version.outputs.ZITI_VERSION || steps.build.outputs.ZITI_VERSION }}
description: version of ziti CLI that was downloaded or built
runs:
using: composite
steps:
- name: process version
if: inputs.ref == ''
shell: bash
id: version
run: |
ver=${{ inputs.version }}
if [[ ${{ inputs.version }} == "stable" ]]; then
echo "fetching stable version"
ver=$(gh release view --repo openziti/ziti | awk '/^tag/{ print $2 }')
elif [[ ${{ inputs.version }} == "active-lts" || ${{ inputs.version }} == "maint-lts" ]]; then
key=active; [[ ${{ inputs.version }} == "maint-lts" ]] && key=maintenance
echo "resolving ${{ inputs.version }} from lts-versions.json"
minor=$(gh api repos/openziti/ziti/contents/lts-versions.json -H "Accept: application/vnd.github.raw" | jq -r ".${key} // empty")
if [[ -z "$minor" ]]; then
echo "::error ::No ${key} entry in lts-versions.json"
exit 1
fi
echo "${{ inputs.version }} is ${minor}, fetching its latest release"
ver=$(gh release list --repo openziti/ziti --limit 200 --json "tagName,isPrerelease,publishedAt" --jq 'sort_by(.publishedAt) | .[] | select(.isPrerelease==false) | .tagName' | grep -E "^v${minor}\." | tail -1)
else
echo "computing specified[${ver}] version"
ver=$(gh release list --repo openziti/ziti --limit 200 --json "tagName,publishedAt" --jq "sort_by(.publishedAt) | .[].tagName" | grep -E "^${ver}" | tail -1)
fi
if [[ -z "$ver" ]]; then
echo "::error ::Failed to find version matching ${{ inputs.version }}"
exit 1
fi
echo "using version = $ver"
echo "ZITI_VERSION=$ver" >> $GITHUB_ENV
echo "ZITI_VERSION=$ver" >> $GITHUB_OUTPUT
- name: download ziti CLI
if: inputs.ref == ''
shell: bash
run: |
os=${{ runner.os }}
case ${os} in
Linux) os=linux
;;
macOS) os=darwin
;;
Windows) os=windows
;;
esac
arch=$(uname -m)
if [[ "${arch}" == "x86_64" ]]; then
arch="amd64"
fi
echo "downloading ziti-${os}-${arch} ${ZITI_VERSION} tarball"
mkdir -p '${{ runner.temp }}'
cd '${{ runner.temp }}'
gh release download ${ZITI_VERSION} --repo openziti/ziti --pattern "ziti-${os}-${arch}-*" --output ziti.bundle
- name: extract ziti CLI and add to PATH
if: inputs.ref == ''
shell: bash
run: |
cd '${{ runner.temp }}'
mkdir -p ziti-cli/bin
if [[ ${{ runner.os }} == "Windows" ]]; then
mkdir -p ziti-cli/bin
unzip -d 'ziti-cli\bin' ziti.bundle
else
tar -xpf ziti.bundle -C ziti-cli/bin
fi
./ziti-cli/bin/ziti version
echo "${{ runner.temp }}/ziti-cli/bin" >> $GITHUB_PATH
- name: checkout ziti source
if: inputs.ref != ''
uses: actions/checkout@v6
with:
repository: openziti/ziti
ref: ${{ inputs.ref }}
path: ziti-src
fetch-depth: 0
- name: set up go
if: inputs.ref != ''
uses: actions/setup-go@v5
with:
go-version-file: ziti-src/go.mod
- name: install ziti-ci
if: inputs.ref != ''
uses: openziti/ziti-ci@v1
- name: build ziti from source and add to PATH
if: inputs.ref != ''
id: build
shell: bash
run: |
ext=""; [ "${{ runner.os }}" = "Windows" ] && ext=".exe"
bindir='${{ runner.temp }}/ziti-cli/bin'
mkdir -p "$bindir"
cd ziti-src
export CGO_ENABLED=1
go build -ldflags "$($(go env GOPATH)/bin/ziti-ci -q go-build-flags -n)" -o "$bindir/ziti$ext" ./ziti
"$bindir/ziti$ext" version
echo "ZITI_VERSION=$($(go env GOPATH)/bin/ziti-ci -q get-current-version)" >> "$GITHUB_OUTPUT"
echo "$bindir" >> $GITHUB_PATH