feat: use go run from source when action ref is @main

When github.action_ref is not a semver tag (e.g. main), skip binary
download and run vociferate directly via 'go run ./cmd/vociferate' from
the action's own source directory (GITHUB_ACTION_PATH). A conditional
Setup Go step installs the toolchain only on that path.

When pinned to a semver tag (v*), the existing prebuilt binary download
and cache behaviour is unchanged.

This makes the prepare-release workflow self-contained on main — it no
longer requires a published release to bootstrap itself.
This commit is contained in:
Micheal Wilkinson
2026-03-20 20:34:46 +00:00
parent 55a067973e
commit b793e1b289
2 changed files with 76 additions and 57 deletions

View File

@@ -62,19 +62,8 @@ runs:
;; ;;
esac esac
if [[ "$ACTION_REF" == v* ]]; then
release_tag="$ACTION_REF" 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}" normalized_version="${release_tag#v}"
asset_name="vociferate_${normalized_version}_linux_${arch}" asset_name="vociferate_${normalized_version}_linux_${arch}"
cache_dir="${RUNNER_TEMP}/vociferate/${release_tag}/linux-${arch}" cache_dir="${RUNNER_TEMP}/vociferate/${release_tag}/linux-${arch}"
@@ -83,21 +72,34 @@ runs:
mkdir -p "$cache_dir" mkdir -p "$cache_dir"
echo "use_binary=true" >> "$GITHUB_OUTPUT"
echo "release_tag=$release_tag" >> "$GITHUB_OUTPUT" echo "release_tag=$release_tag" >> "$GITHUB_OUTPUT"
echo "asset_name=$asset_name" >> "$GITHUB_OUTPUT" echo "asset_name=$asset_name" >> "$GITHUB_OUTPUT"
echo "asset_url=$asset_url" >> "$GITHUB_OUTPUT" echo "asset_url=$asset_url" >> "$GITHUB_OUTPUT"
echo "cache_dir=$cache_dir" >> "$GITHUB_OUTPUT" echo "cache_dir=$cache_dir" >> "$GITHUB_OUTPUT"
echo "binary_path=$binary_path" >> "$GITHUB_OUTPUT" echo "binary_path=$binary_path" >> "$GITHUB_OUTPUT"
else
echo "use_binary=false" >> "$GITHUB_OUTPUT"
fi
- name: Setup Go
if: steps.resolve-binary.outputs.use_binary != 'true'
uses: actions/setup-go@v5
with:
go-version: '1.26.1'
cache: true
cache-dependency-path: ${{ github.action_path }}/go.sum
- name: Restore cached vociferate binary - name: Restore cached vociferate binary
id: cache-vociferate id: cache-vociferate
if: steps.resolve-binary.outputs.use_binary == 'true'
uses: actions/cache@v4 uses: actions/cache@v4
with: with:
path: ${{ steps.resolve-binary.outputs.cache_dir }} path: ${{ steps.resolve-binary.outputs.cache_dir }}
key: vociferate-${{ steps.resolve-binary.outputs.release_tag }}-linux-${{ runner.arch }} key: vociferate-${{ steps.resolve-binary.outputs.release_tag }}-linux-${{ runner.arch }}
- name: Download vociferate binary - name: Download vociferate binary
if: steps.cache-vociferate.outputs.cache-hit != 'true' if: steps.resolve-binary.outputs.use_binary == 'true' && steps.cache-vociferate.outputs.cache-hit != 'true'
shell: bash shell: bash
env: env:
TOKEN: ${{ inputs.token != '' && inputs.token || github.token }} TOKEN: ${{ inputs.token != '' && inputs.token || github.token }}
@@ -117,10 +119,17 @@ runs:
shell: bash shell: bash
env: env:
VOCIFERATE_BIN: ${{ steps.resolve-binary.outputs.binary_path }} VOCIFERATE_BIN: ${{ steps.resolve-binary.outputs.binary_path }}
USE_BINARY: ${{ steps.resolve-binary.outputs.use_binary }}
run: | run: |
set -euo pipefail set -euo pipefail
common_args=(--root .) if [[ "$USE_BINARY" == "true" ]]; then
run_vociferate() { "$VOCIFERATE_BIN" "$@"; }
else
run_vociferate() { (cd "$GITHUB_ACTION_PATH" && go run ./cmd/vociferate "$@"); }
fi
common_args=(--root "$GITHUB_WORKSPACE")
if [[ -n "${{ inputs.version-file }}" ]]; then if [[ -n "${{ inputs.version-file }}" ]]; then
common_args+=(--version-file "${{ inputs.version-file }}") common_args+=(--version-file "${{ inputs.version-file }}")
@@ -135,16 +144,16 @@ runs:
fi fi
if [[ "${{ inputs.recommend }}" == "true" ]]; then if [[ "${{ inputs.recommend }}" == "true" ]]; then
resolved_version="$("$VOCIFERATE_BIN" "${common_args[@]}" --recommend)" resolved_version="$(run_vociferate "${common_args[@]}" --recommend)"
echo "$resolved_version" echo "$resolved_version"
echo "version=$resolved_version" >> "$GITHUB_OUTPUT" echo "version=$resolved_version" >> "$GITHUB_OUTPUT"
exit 0 exit 0
else else
resolved_version="$(printf '%s' "${{ inputs.version }}" | sed 's/^[[:space:]]\+//; s/[[:space:]]\+$//')" resolved_version="$(printf '%s' "${{ inputs.version }}" | sed 's/^[[:space:]]\+//; s/[[:space:]]\+$//')"
if [[ -z "$resolved_version" ]]; then if [[ -z "$resolved_version" ]]; then
resolved_version="$("$VOCIFERATE_BIN" "${common_args[@]}" --recommend)" resolved_version="$(run_vociferate "${common_args[@]}" --recommend)"
fi fi
fi fi
echo "version=$resolved_version" >> "$GITHUB_OUTPUT" echo "version=$resolved_version" >> "$GITHUB_OUTPUT"
"$VOCIFERATE_BIN" "${common_args[@]}" --version "$resolved_version" --date "$(date -u +%F)" run_vociferate "${common_args[@]}" --version "$resolved_version" --date "$(date -u +%F)"

View File

@@ -80,19 +80,8 @@ runs:
;; ;;
esac esac
if [[ "$ACTION_REF" == v* ]]; then
release_tag="$ACTION_REF" 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}" normalized_version="${release_tag#v}"
asset_name="vociferate_${normalized_version}_linux_${arch}" asset_name="vociferate_${normalized_version}_linux_${arch}"
cache_dir="${RUNNER_TEMP}/vociferate/${release_tag}/linux-${arch}" cache_dir="${RUNNER_TEMP}/vociferate/${release_tag}/linux-${arch}"
@@ -101,21 +90,34 @@ runs:
mkdir -p "$cache_dir" mkdir -p "$cache_dir"
echo "use_binary=true" >> "$GITHUB_OUTPUT"
echo "release_tag=$release_tag" >> "$GITHUB_OUTPUT" echo "release_tag=$release_tag" >> "$GITHUB_OUTPUT"
echo "asset_name=$asset_name" >> "$GITHUB_OUTPUT" echo "asset_name=$asset_name" >> "$GITHUB_OUTPUT"
echo "asset_url=$asset_url" >> "$GITHUB_OUTPUT" echo "asset_url=$asset_url" >> "$GITHUB_OUTPUT"
echo "cache_dir=$cache_dir" >> "$GITHUB_OUTPUT" echo "cache_dir=$cache_dir" >> "$GITHUB_OUTPUT"
echo "binary_path=$binary_path" >> "$GITHUB_OUTPUT" echo "binary_path=$binary_path" >> "$GITHUB_OUTPUT"
else
echo "use_binary=false" >> "$GITHUB_OUTPUT"
fi
- name: Setup Go
if: steps.resolve-binary.outputs.use_binary != 'true'
uses: actions/setup-go@v5
with:
go-version: '1.26.1'
cache: true
cache-dependency-path: ${{ github.action_path }}/../go.sum
- name: Restore cached vociferate binary - name: Restore cached vociferate binary
id: cache-vociferate id: cache-vociferate
if: steps.resolve-binary.outputs.use_binary == 'true'
uses: actions/cache@v4 uses: actions/cache@v4
with: with:
path: ${{ steps.resolve-binary.outputs.cache_dir }} path: ${{ steps.resolve-binary.outputs.cache_dir }}
key: vociferate-${{ steps.resolve-binary.outputs.release_tag }}-linux-${{ runner.arch }} key: vociferate-${{ steps.resolve-binary.outputs.release_tag }}-linux-${{ runner.arch }}
- name: Download vociferate binary - name: Download vociferate binary
if: steps.cache-vociferate.outputs.cache-hit != 'true' if: steps.resolve-binary.outputs.use_binary == 'true' && steps.cache-vociferate.outputs.cache-hit != 'true'
shell: bash shell: bash
env: env:
TOKEN: ${{ inputs.token != '' && inputs.token || github.token }} TOKEN: ${{ inputs.token != '' && inputs.token || github.token }}
@@ -135,11 +137,19 @@ runs:
shell: bash shell: bash
env: env:
VOCIFERATE_BIN: ${{ steps.resolve-binary.outputs.binary_path }} VOCIFERATE_BIN: ${{ steps.resolve-binary.outputs.binary_path }}
USE_BINARY: ${{ steps.resolve-binary.outputs.use_binary }}
INPUT_VERSION: ${{ inputs.version }} INPUT_VERSION: ${{ inputs.version }}
run: | run: |
set -euo pipefail set -euo pipefail
common_args=(--root .) if [[ "$USE_BINARY" == "true" ]]; then
run_vociferate() { "$VOCIFERATE_BIN" "$@"; }
else
action_root="$(realpath "$GITHUB_ACTION_PATH/..")"
run_vociferate() { (cd "$action_root" && go run ./cmd/vociferate "$@"); }
fi
common_args=(--root "$GITHUB_WORKSPACE")
if [[ -n "${{ inputs.version-file }}" ]]; then if [[ -n "${{ inputs.version-file }}" ]]; then
common_args+=(--version-file "${{ inputs.version-file }}") common_args+=(--version-file "${{ inputs.version-file }}")
@@ -155,13 +165,13 @@ runs:
provided_version="$(printf '%s' "${INPUT_VERSION:-}" | sed 's/^[[:space:]]\+//; s/[[:space:]]\+$//')" provided_version="$(printf '%s' "${INPUT_VERSION:-}" | sed 's/^[[:space:]]\+//; s/[[:space:]]\+$//')"
if [[ -z "$provided_version" ]]; then if [[ -z "$provided_version" ]]; then
provided_version="$("$VOCIFERATE_BIN" "${common_args[@]}" --recommend)" provided_version="$(run_vociferate "${common_args[@]}" --recommend)"
fi fi
normalized_version="${provided_version#v}" normalized_version="${provided_version#v}"
tag="v${normalized_version}" tag="v${normalized_version}"
"$VOCIFERATE_BIN" "${common_args[@]}" --version "$provided_version" --date "$(date -u +%F)" run_vociferate "${common_args[@]}" --version "$provided_version" --date "$(date -u +%F)"
echo "version=$tag" >> "$GITHUB_OUTPUT" echo "version=$tag" >> "$GITHUB_OUTPUT"