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:
@@ -80,42 +80,44 @@ runs:
|
||||
;;
|
||||
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)"
|
||||
if [[ "$ACTION_REF" == v* ]]; then
|
||||
release_tag="$ACTION_REF"
|
||||
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 "use_binary=true" >> "$GITHUB_OUTPUT"
|
||||
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"
|
||||
else
|
||||
echo "use_binary=false" >> "$GITHUB_OUTPUT"
|
||||
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: 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
|
||||
id: cache-vociferate
|
||||
if: steps.resolve-binary.outputs.use_binary == 'true'
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
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'
|
||||
if: steps.resolve-binary.outputs.use_binary == 'true' && steps.cache-vociferate.outputs.cache-hit != 'true'
|
||||
shell: bash
|
||||
env:
|
||||
TOKEN: ${{ inputs.token != '' && inputs.token || github.token }}
|
||||
@@ -135,11 +137,19 @@ runs:
|
||||
shell: bash
|
||||
env:
|
||||
VOCIFERATE_BIN: ${{ steps.resolve-binary.outputs.binary_path }}
|
||||
USE_BINARY: ${{ steps.resolve-binary.outputs.use_binary }}
|
||||
INPUT_VERSION: ${{ inputs.version }}
|
||||
run: |
|
||||
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
|
||||
common_args+=(--version-file "${{ inputs.version-file }}")
|
||||
@@ -155,13 +165,13 @@ runs:
|
||||
|
||||
provided_version="$(printf '%s' "${INPUT_VERSION:-}" | sed 's/^[[:space:]]\+//; s/[[:space:]]\+$//')"
|
||||
if [[ -z "$provided_version" ]]; then
|
||||
provided_version="$("$VOCIFERATE_BIN" "${common_args[@]}" --recommend)"
|
||||
provided_version="$(run_vociferate "${common_args[@]}" --recommend)"
|
||||
fi
|
||||
|
||||
normalized_version="${provided_version#v}"
|
||||
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"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user