chore(go): centralize action runtime selection

This commit is contained in:
Micheal Wilkinson
2026-03-21 14:34:00 +00:00
parent 92f76fd19f
commit 3eb814a3d5
3 changed files with 306 additions and 138 deletions

View File

@@ -47,7 +47,7 @@ outputs:
version:
description: >
The resolved version tag (e.g. v1.2.3) that was committed and pushed.
value: ${{ steps.run-vociferate.outputs.version }}
value: ${{ steps.finalize-version.outputs.version }}
runs:
using: composite
@@ -65,51 +65,15 @@ runs:
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
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}"
provided_cache_token="$(printf '%s' "${CACHE_TOKEN:-}" | sed 's/^[[:space:]]\+//; s/[[:space:]]\+$//')"
if [[ -n "$provided_cache_token" ]]; then
cache_token="$provided_cache_token"
else
cache_token="${ACTION_REPOSITORY:-aether/vociferate}-${release_tag}"
fi
mkdir -p "$cache_dir"
echo "use_binary=true" >> "$GITHUB_OUTPUT"
echo "release_tag=$release_tag" >> "$GITHUB_OUTPUT"
echo "cache_token=$cache_token" >> "$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
bash "$GITHUB_ACTION_PATH/../script/resolve-vociferate-runtime.sh"
- name: Setup Go
if: steps.resolve-binary.outputs.use_binary != 'true'
uses: actions/setup-go@v5
with:
go-version: '1.26.1'
cache: false
cache: true
cache-dependency-path: ${{ steps.resolve-binary.outputs.source_root }}/go.sum
- name: Restore cached vociferate binary
id: cache-vociferate
@@ -127,31 +91,27 @@ runs:
ASSET_URL: ${{ steps.resolve-binary.outputs.asset_url }}
BINARY_PATH: ${{ steps.resolve-binary.outputs.binary_path }}
run: |
set -euo pipefail
bash "${{ steps.resolve-binary.outputs.source_root }}/script/download-vociferate-binary.sh"
curl --fail --location \
-H "Authorization: token ${TOKEN}" \
-o "$BINARY_PATH" \
"$ASSET_URL"
chmod +x "$BINARY_PATH"
- name: Run vociferate
id: run-vociferate
- name: Normalize version input
id: normalize-version
shell: bash
env:
VOCIFERATE_BIN: ${{ steps.resolve-binary.outputs.binary_path }}
USE_BINARY: ${{ steps.resolve-binary.outputs.use_binary }}
INPUT_VERSION: ${{ inputs.version }}
VOCIFERATE_REPOSITORY_URL: ${{ vars.VOCIFERATE_REPOSITORY_URL }}
run: |
set -euo pipefail
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
provided_version="$(printf '%s' "${INPUT_VERSION:-}" | sed 's/^[[:space:]]\+//; s/[[:space:]]\+$//')"
printf 'value=%s\n' "$provided_version" >> "$GITHUB_OUTPUT"
- name: Recommend version from binary
id: recommend-binary
if: steps.normalize-version.outputs.value == '' && steps.resolve-binary.outputs.use_binary == 'true'
shell: bash
env:
VOCIFERATE_BIN: ${{ steps.resolve-binary.outputs.binary_path }}
run: |
set -euo pipefail
common_args=(--root "$GITHUB_WORKSPACE")
@@ -167,17 +127,106 @@ runs:
common_args+=(--changelog "${{ inputs.changelog }}")
fi
provided_version="$(printf '%s' "${INPUT_VERSION:-}" | sed 's/^[[:space:]]\+//; s/[[:space:]]\+$//')"
provided_version="$($VOCIFERATE_BIN "${common_args[@]}" --recommend)"
printf 'version=%s\n' "$provided_version" >> "$GITHUB_OUTPUT"
- name: Recommend version from source
id: recommend-source
if: steps.normalize-version.outputs.value == '' && steps.resolve-binary.outputs.use_binary != 'true'
shell: bash
working-directory: ${{ steps.resolve-binary.outputs.source_root }}
run: |
set -euo pipefail
common_args=(--root "$GITHUB_WORKSPACE")
if [[ -n "${{ inputs.version-file }}" ]]; then
common_args+=(--version-file "${{ inputs.version-file }}")
fi
if [[ -n "${{ inputs.version-pattern }}" ]]; then
common_args+=(--version-pattern "${{ inputs.version-pattern }}")
fi
if [[ -n "${{ inputs.changelog }}" ]]; then
common_args+=(--changelog "${{ inputs.changelog }}")
fi
provided_version="$(go run ./cmd/vociferate "${common_args[@]}" --recommend)"
printf 'version=%s\n' "$provided_version" >> "$GITHUB_OUTPUT"
- name: Finalize version
id: finalize-version
shell: bash
env:
PROVIDED_VERSION: ${{ steps.normalize-version.outputs.value }}
RECOMMENDED_BINARY: ${{ steps.recommend-binary.outputs.version }}
RECOMMENDED_SOURCE: ${{ steps.recommend-source.outputs.version }}
run: |
set -euo pipefail
provided_version="$PROVIDED_VERSION"
if [[ -z "$provided_version" ]]; then
provided_version="$(run_vociferate "${common_args[@]}" --recommend)"
provided_version="$RECOMMENDED_BINARY"
fi
if [[ -z "$provided_version" ]]; then
provided_version="$RECOMMENDED_SOURCE"
fi
normalized_version="${provided_version#v}"
tag="v${normalized_version}"
run_vociferate "${common_args[@]}" --version "$provided_version" --date "$(date -u +%F)"
printf 'version=%s\n' "$tag" >> "$GITHUB_OUTPUT"
echo "version=$tag" >> "$GITHUB_OUTPUT"
- name: Prepare release files with binary
if: steps.resolve-binary.outputs.use_binary == 'true'
shell: bash
env:
VOCIFERATE_BIN: ${{ steps.resolve-binary.outputs.binary_path }}
VOCIFERATE_REPOSITORY_URL: ${{ vars.VOCIFERATE_REPOSITORY_URL }}
run: |
set -euo pipefail
common_args=(--root "$GITHUB_WORKSPACE")
if [[ -n "${{ inputs.version-file }}" ]]; then
common_args+=(--version-file "${{ inputs.version-file }}")
fi
if [[ -n "${{ inputs.version-pattern }}" ]]; then
common_args+=(--version-pattern "${{ inputs.version-pattern }}")
fi
if [[ -n "${{ inputs.changelog }}" ]]; then
common_args+=(--changelog "${{ inputs.changelog }}")
fi
"$VOCIFERATE_BIN" "${common_args[@]}" --version "${{ steps.finalize-version.outputs.version }}" --date "$(date -u +%F)"
- name: Prepare release files with source
if: steps.resolve-binary.outputs.use_binary != 'true'
shell: bash
working-directory: ${{ steps.resolve-binary.outputs.source_root }}
env:
VOCIFERATE_REPOSITORY_URL: ${{ vars.VOCIFERATE_REPOSITORY_URL }}
run: |
set -euo pipefail
common_args=(--root "$GITHUB_WORKSPACE")
if [[ -n "${{ inputs.version-file }}" ]]; then
common_args+=(--version-file "${{ inputs.version-file }}")
fi
if [[ -n "${{ inputs.version-pattern }}" ]]; then
common_args+=(--version-pattern "${{ inputs.version-pattern }}")
fi
if [[ -n "${{ inputs.changelog }}" ]]; then
common_args+=(--changelog "${{ inputs.changelog }}")
fi
go run ./cmd/vociferate "${common_args[@]}" --version "${{ steps.finalize-version.outputs.version }}" --date "$(date -u +%F)"
- name: Commit and push release
shell: bash
@@ -186,7 +235,7 @@ runs:
GIT_USER_NAME: ${{ inputs.git-user-name }}
GIT_USER_EMAIL: ${{ inputs.git-user-email }}
GIT_ADD_FILES: ${{ inputs.git-add-files }}
RELEASE_TAG: ${{ steps.run-vociferate.outputs.version }}
RELEASE_TAG: ${{ steps.finalize-version.outputs.version }}
GITHUB_SERVER_URL: ${{ github.server_url }}
GITHUB_REPOSITORY: ${{ github.repository }}
run: |