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:
67
action.yml
67
action.yml
@@ -62,42 +62,44 @@ runs:
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
release_tag="$ACTION_REF"
|
if [[ "$ACTION_REF" == v* ]]; then
|
||||||
if [[ -z "$release_tag" || "$release_tag" == refs/* || "$release_tag" != v* ]]; then
|
release_tag="$ACTION_REF"
|
||||||
release_tag="$(curl -fsSL \
|
normalized_version="${release_tag#v}"
|
||||||
-H "Authorization: token ${TOKEN}" \
|
asset_name="vociferate_${normalized_version}_linux_${arch}"
|
||||||
-H "Content-Type: application/json" \
|
cache_dir="${RUNNER_TEMP}/vociferate/${release_tag}/linux-${arch}"
|
||||||
"${API_URL}/repos/aether/vociferate/releases/latest" | sed -n 's/.*"tag_name"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' | head -n 1)"
|
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
|
fi
|
||||||
|
|
||||||
if [[ -z "$release_tag" ]]; then
|
- name: Setup Go
|
||||||
echo "Unable to resolve a vociferate release tag for binary download" >&2
|
if: steps.resolve-binary.outputs.use_binary != 'true'
|
||||||
exit 1
|
uses: actions/setup-go@v5
|
||||||
fi
|
with:
|
||||||
|
go-version: '1.26.1'
|
||||||
normalized_version="${release_tag#v}"
|
cache: true
|
||||||
asset_name="vociferate_${normalized_version}_linux_${arch}"
|
cache-dependency-path: ${{ github.action_path }}/go.sum
|
||||||
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
|
- 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)"
|
||||||
|
|||||||
@@ -80,42 +80,44 @@ runs:
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
release_tag="$ACTION_REF"
|
if [[ "$ACTION_REF" == v* ]]; then
|
||||||
if [[ -z "$release_tag" || "$release_tag" == refs/* || "$release_tag" != v* ]]; then
|
release_tag="$ACTION_REF"
|
||||||
release_tag="$(curl -fsSL \
|
normalized_version="${release_tag#v}"
|
||||||
-H "Authorization: token ${TOKEN}" \
|
asset_name="vociferate_${normalized_version}_linux_${arch}"
|
||||||
-H "Content-Type: application/json" \
|
cache_dir="${RUNNER_TEMP}/vociferate/${release_tag}/linux-${arch}"
|
||||||
"${API_URL}/repos/aether/vociferate/releases/latest" | sed -n 's/.*"tag_name"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' | head -n 1)"
|
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
|
fi
|
||||||
|
|
||||||
if [[ -z "$release_tag" ]]; then
|
- name: Setup Go
|
||||||
echo "Unable to resolve a vociferate release tag for binary download" >&2
|
if: steps.resolve-binary.outputs.use_binary != 'true'
|
||||||
exit 1
|
uses: actions/setup-go@v5
|
||||||
fi
|
with:
|
||||||
|
go-version: '1.26.1'
|
||||||
normalized_version="${release_tag#v}"
|
cache: true
|
||||||
asset_name="vociferate_${normalized_version}_linux_${arch}"
|
cache-dependency-path: ${{ github.action_path }}/../go.sum
|
||||||
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
|
- 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"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user