From 3eb814a3d58b6821ae505fc64515d07709860b06 Mon Sep 17 00:00:00 2001 From: Micheal Wilkinson Date: Sat, 21 Mar 2026 14:34:00 +0000 Subject: [PATCH] chore(go): centralize action runtime selection --- action.yml | 185 +++++++++++++++++++++++++---------------- decorate-pr/action.yml | 84 +++++++++++++++++-- prepare/action.yml | 175 ++++++++++++++++++++++++-------------- 3 files changed, 306 insertions(+), 138 deletions(-) diff --git a/action.yml b/action.yml index 2107c2e..fdb4c54 100644 --- a/action.yml +++ b/action.yml @@ -25,7 +25,7 @@ inputs: outputs: version: description: Resolved version used for prepare mode, or the emitted recommended version for recommend mode. - value: ${{ steps.run-vociferate.outputs.version }} + value: ${{ steps.finalize-version.outputs.version }} runs: using: composite @@ -45,48 +45,7 @@ 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' @@ -94,7 +53,7 @@ runs: with: go-version: '1.26.1' cache: true - cache-dependency-path: ${{ github.action_path }}/go.sum + cache-dependency-path: ${{ steps.resolve-binary.outputs.source_root }}/go.sum - name: Restore cached vociferate binary id: cache-vociferate @@ -112,29 +71,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 }} - VOCIFERATE_REPOSITORY_URL: ${{ vars.VOCIFERATE_REPOSITORY_URL }} + INPUT_VERSION: ${{ inputs.version }} run: | set -euo pipefail - if [[ "$USE_BINARY" == "true" ]]; then - run_vociferate() { "$VOCIFERATE_BIN" "$@"; } - else - run_vociferate() { (cd "$GITHUB_ACTION_PATH" && go run ./cmd/vociferate "$@"); } - fi + resolved_version="$(printf '%s' "${INPUT_VERSION:-}" | sed 's/^[[:space:]]\+//; s/[[:space:]]\+$//')" + printf 'value=%s\n' "$resolved_version" >> "$GITHUB_OUTPUT" + + - name: Recommend version from binary + id: recommend-binary + if: (inputs.recommend == 'true' || 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") @@ -150,17 +107,105 @@ runs: common_args+=(--changelog "${{ inputs.changelog }}") fi - if [[ "${{ inputs.recommend }}" == "true" ]]; then - resolved_version="$(run_vociferate "${common_args[@]}" --recommend)" - echo "$resolved_version" - echo "version=$resolved_version" >> "$GITHUB_OUTPUT" - exit 0 + resolved_version="$($VOCIFERATE_BIN "${common_args[@]}" --recommend)" + printf 'version=%s\n' "$resolved_version" >> "$GITHUB_OUTPUT" + + - name: Recommend version from source + id: recommend-source + if: (inputs.recommend == 'true' || 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 + + resolved_version="$(go run ./cmd/vociferate "${common_args[@]}" --recommend)" + printf 'version=%s\n' "$resolved_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 + + if [[ -n "$PROVIDED_VERSION" ]] && [[ "${{ inputs.recommend }}" != 'true' ]]; then + resolved_version="$PROVIDED_VERSION" else - resolved_version="$(printf '%s' "${{ inputs.version }}" | sed 's/^[[:space:]]\+//; s/[[:space:]]\+$//')" + resolved_version="$RECOMMENDED_BINARY" if [[ -z "$resolved_version" ]]; then - resolved_version="$(run_vociferate "${common_args[@]}" --recommend)" + resolved_version="$RECOMMENDED_SOURCE" fi fi - echo "version=$resolved_version" >> "$GITHUB_OUTPUT" - run_vociferate "${common_args[@]}" --version "$resolved_version" --date "$(date -u +%F)" + if [[ "${{ inputs.recommend }}" == 'true' ]]; then + echo "$resolved_version" + fi + + printf 'version=%s\n' "$resolved_version" >> "$GITHUB_OUTPUT" + + - name: Prepare release files with binary + if: inputs.recommend != 'true' && 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: inputs.recommend != 'true' && 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)" diff --git a/decorate-pr/action.yml b/decorate-pr/action.yml index ce3fb53..5be2ef9 100644 --- a/decorate-pr/action.yml +++ b/decorate-pr/action.yml @@ -147,15 +147,70 @@ runs: -H "Content-Type: application/json" \ "$comments_url" >/dev/null - - name: Setup Go for vociferate + - name: Resolve vociferate binary metadata + id: resolve-binary + shell: bash + env: + ACTION_REF: ${{ github.action_ref }} + ACTION_REPOSITORY: ${{ github.action_repository }} + CACHE_TOKEN: ${{ env.VOCIFERATE_CACHE_TOKEN }} + SERVER_URL: ${{ github.server_url }} + RUNNER_ARCH: ${{ runner.arch }} + RUNNER_TEMP: ${{ runner.temp }} + run: | + 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-file: ${{ github.action_path }}/../go.mod + go-version: '1.26.1' + cache: true + cache-dependency-path: ${{ steps.resolve-binary.outputs.source_root }}/go.sum - - name: Extract changelog unreleased entries - id: extract-changelog + - 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.cache_token }}-linux-${{ runner.arch }} + + - name: Download vociferate binary + if: steps.resolve-binary.outputs.use_binary == 'true' && steps.cache-vociferate.outputs.cache-hit != 'true' shell: bash - working-directory: ${{ github.action_path }}/.. + env: + TOKEN: ${{ github.token }} + ASSET_URL: ${{ steps.resolve-binary.outputs.asset_url }} + BINARY_PATH: ${{ steps.resolve-binary.outputs.binary_path }} + run: | + bash "${{ steps.resolve-binary.outputs.source_root }}/script/download-vociferate-binary.sh" + + - name: Extract changelog unreleased entries from binary + id: extract-changelog-binary + if: steps.resolve-binary.outputs.use_binary == 'true' + shell: bash + env: + VOCIFERATE_BIN: ${{ steps.resolve-binary.outputs.binary_path }} + CHANGELOG: ${{ inputs.changelog }} + run: | + set -euo pipefail + + if [[ ! -f "$CHANGELOG" ]]; then + printf 'unreleased_entries=%s\n' "" >> "$GITHUB_OUTPUT" + exit 0 + fi + + delimiter="EOF_CHANGELOG" + printf 'unreleased_entries<<%s\n' "$delimiter" >> "$GITHUB_OUTPUT" + "$VOCIFERATE_BIN" --print-unreleased --root "$GITHUB_WORKSPACE" --changelog "$CHANGELOG" >> "$GITHUB_OUTPUT" + printf '%s\n' "$delimiter" >> "$GITHUB_OUTPUT" + + - name: Extract changelog unreleased entries from source + id: extract-changelog-source + if: steps.resolve-binary.outputs.use_binary != 'true' + shell: bash + working-directory: ${{ steps.resolve-binary.outputs.source_root }} env: CHANGELOG: ${{ inputs.changelog }} run: | @@ -171,6 +226,25 @@ runs: go run ./cmd/vociferate --print-unreleased --root "$GITHUB_WORKSPACE" --changelog "$CHANGELOG" >> "$GITHUB_OUTPUT" printf '%s\n' "$delimiter" >> "$GITHUB_OUTPUT" + - name: Finalize changelog extraction + id: extract-changelog + shell: bash + env: + UNRELEASED_BINARY: ${{ steps.extract-changelog-binary.outputs.unreleased_entries }} + UNRELEASED_SOURCE: ${{ steps.extract-changelog-source.outputs.unreleased_entries }} + run: | + set -euo pipefail + + unreleased="$UNRELEASED_BINARY" + if [[ -z "$unreleased" ]]; then + unreleased="$UNRELEASED_SOURCE" + fi + + delimiter="EOF_CHANGELOG" + printf 'unreleased_entries<<%s\n' "$delimiter" >> "$GITHUB_OUTPUT" + printf '%s\n' "$unreleased" >> "$GITHUB_OUTPUT" + printf '%s\n' "$delimiter" >> "$GITHUB_OUTPUT" + - name: Validate changelog gate id: changelog-gate shell: bash diff --git a/prepare/action.yml b/prepare/action.yml index 39cfc6c..79291d7 100644 --- a/prepare/action.yml +++ b/prepare/action.yml @@ -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: |