feat: cache release binary in action
This commit is contained in:
88
action.yml
88
action.yml
@@ -2,6 +2,10 @@ name: vociferate
|
||||
description: Prepare release files or recommend a next semantic version tag.
|
||||
|
||||
inputs:
|
||||
token:
|
||||
description: Optional token used to download the cached vociferate release binary. When omitted, the workflow token is used.
|
||||
required: false
|
||||
default: ''
|
||||
version:
|
||||
description: Optional semantic version override. When omitted, the recommended version is used.
|
||||
required: false
|
||||
@@ -32,13 +36,87 @@ runs:
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: actions/setup-go@v5
|
||||
- name: Resolve vociferate binary metadata
|
||||
id: resolve-binary
|
||||
shell: bash
|
||||
env:
|
||||
ACTION_REF: ${{ github.action_ref }}
|
||||
SERVER_URL: ${{ github.server_url }}
|
||||
API_URL: ${{ github.api_url }}
|
||||
TOKEN: ${{ inputs.token != '' && inputs.token || github.token }}
|
||||
RUNNER_ARCH: ${{ runner.arch }}
|
||||
RUNNER_TEMP: ${{ runner.temp }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
case "$RUNNER_ARCH" in
|
||||
X64)
|
||||
arch="amd64"
|
||||
;;
|
||||
ARM64)
|
||||
arch="arm64"
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported runner architecture: $RUNNER_ARCH" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
release_tag="$ACTION_REF"
|
||||
if [[ -z "$release_tag" || "$release_tag" == refs/* || "$release_tag" != v* ]]; then
|
||||
release_tag="$(curl -fsSL \
|
||||
-H "Authorization: token ${TOKEN}" \
|
||||
-H "Content-Type: application/json" \
|
||||
"${API_URL}/repos/aether/vociferate/releases/latest" | sed -n 's/.*"tag_name"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' | head -n 1)"
|
||||
fi
|
||||
|
||||
if [[ -z "$release_tag" ]]; then
|
||||
echo "Unable to resolve a vociferate release tag for binary download" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
normalized_version="${release_tag#v}"
|
||||
asset_name="vociferate_${normalized_version}_linux_${arch}"
|
||||
cache_dir="${RUNNER_TEMP}/vociferate/${release_tag}/linux-${arch}"
|
||||
binary_path="${cache_dir}/vociferate"
|
||||
asset_url="${SERVER_URL}/aether/vociferate/releases/download/${release_tag}/${asset_name}"
|
||||
|
||||
mkdir -p "$cache_dir"
|
||||
|
||||
echo "release_tag=$release_tag" >> "$GITHUB_OUTPUT"
|
||||
echo "asset_name=$asset_name" >> "$GITHUB_OUTPUT"
|
||||
echo "asset_url=$asset_url" >> "$GITHUB_OUTPUT"
|
||||
echo "cache_dir=$cache_dir" >> "$GITHUB_OUTPUT"
|
||||
echo "binary_path=$binary_path" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Restore cached vociferate binary
|
||||
id: cache-vociferate
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
go-version: '1.26.1'
|
||||
path: ${{ steps.resolve-binary.outputs.cache_dir }}
|
||||
key: vociferate-${{ steps.resolve-binary.outputs.release_tag }}-linux-${{ runner.arch }}
|
||||
|
||||
- name: Download vociferate binary
|
||||
if: steps.cache-vociferate.outputs.cache-hit != 'true'
|
||||
shell: bash
|
||||
env:
|
||||
TOKEN: ${{ inputs.token != '' && inputs.token || github.token }}
|
||||
ASSET_URL: ${{ steps.resolve-binary.outputs.asset_url }}
|
||||
BINARY_PATH: ${{ steps.resolve-binary.outputs.binary_path }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
curl --fail --location \
|
||||
-H "Authorization: token ${TOKEN}" \
|
||||
-o "$BINARY_PATH" \
|
||||
"$ASSET_URL"
|
||||
chmod +x "$BINARY_PATH"
|
||||
|
||||
- name: Run vociferate
|
||||
id: run-vociferate
|
||||
shell: bash
|
||||
env:
|
||||
VOCIFERATE_BIN: ${{ steps.resolve-binary.outputs.binary_path }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
@@ -57,16 +135,16 @@ runs:
|
||||
fi
|
||||
|
||||
if [[ "${{ inputs.recommend }}" == "true" ]]; then
|
||||
resolved_version="$(go run git.hrafn.xyz/aether/vociferate/cmd/vociferate@latest "${common_args[@]}" --recommend)"
|
||||
resolved_version="$("$VOCIFERATE_BIN" "${common_args[@]}" --recommend)"
|
||||
echo "$resolved_version"
|
||||
echo "version=$resolved_version" >> "$GITHUB_OUTPUT"
|
||||
exit 0
|
||||
else
|
||||
resolved_version="$(printf '%s' "${{ inputs.version }}" | sed 's/^[[:space:]]\+//; s/[[:space:]]\+$//')"
|
||||
if [[ -z "$resolved_version" ]]; then
|
||||
resolved_version="$(go run git.hrafn.xyz/aether/vociferate/cmd/vociferate@latest "${common_args[@]}" --recommend)"
|
||||
resolved_version="$("$VOCIFERATE_BIN" "${common_args[@]}" --recommend)"
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "version=$resolved_version" >> "$GITHUB_OUTPUT"
|
||||
go run git.hrafn.xyz/aether/vociferate/cmd/vociferate@latest "${common_args[@]}" --version "$resolved_version" --date "$(date -u +%F)"
|
||||
"$VOCIFERATE_BIN" "${common_args[@]}" --version "$resolved_version" --date "$(date -u +%F)"
|
||||
|
||||
Reference in New Issue
Block a user