Files
vociferate/prepare/action.yml
2026-03-21 14:34:00 +00:00

280 lines
9.8 KiB
YAML

name: vociferate/prepare
description: >
Download vociferate, prepare release files, then commit, tag, and push.
The repository must be checked out before this action runs.
inputs:
version:
description: >
Optional semantic version override (with or without leading v). When
omitted, the recommended next version is derived from the changelog.
required: false
default: ''
version-file:
description: >
Path to version file relative to repository root. When omitted, the
current version is derived from the most recent released section in
the changelog.
required: false
default: ''
version-pattern:
description: >
Regular expression with one capture group containing the version value.
Only required when version-file is set.
required: false
default: ''
changelog:
description: Path to changelog file relative to repository root.
required: false
default: CHANGELOG.md
git-user-name:
description: Name for the release commit author.
required: false
default: 'gitea-actions[bot]'
git-user-email:
description: Email for the release commit author.
required: false
default: 'gitea-actions[bot]@users.noreply.local'
git-add-files:
description: >
Space-separated list of file paths to stage for the release commit.
Defaults to CHANGELOG.md and release-version. Adjust when using a
custom version-file.
required: false
default: 'CHANGELOG.md release-version'
outputs:
version:
description: >
The resolved version tag (e.g. v1.2.3) that was committed and pushed.
value: ${{ steps.finalize-version.outputs.version }}
runs:
using: composite
steps:
- 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 }}
API_URL: ${{ github.api_url }}
TOKEN: ${{ github.token }}
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: '1.26.1'
cache: true
cache-dependency-path: ${{ steps.resolve-binary.outputs.source_root }}/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.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
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: Normalize version input
id: normalize-version
shell: bash
env:
INPUT_VERSION: ${{ inputs.version }}
run: |
set -euo pipefail
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")
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="$($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="$RECOMMENDED_BINARY"
fi
if [[ -z "$provided_version" ]]; then
provided_version="$RECOMMENDED_SOURCE"
fi
normalized_version="${provided_version#v}"
tag="v${normalized_version}"
printf 'version=%s\n' "$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
env:
TOKEN: ${{ github.token }}
GIT_USER_NAME: ${{ inputs.git-user-name }}
GIT_USER_EMAIL: ${{ inputs.git-user-email }}
GIT_ADD_FILES: ${{ inputs.git-add-files }}
RELEASE_TAG: ${{ steps.finalize-version.outputs.version }}
GITHUB_SERVER_URL: ${{ github.server_url }}
GITHUB_REPOSITORY: ${{ github.repository }}
run: |
set -euo pipefail
case "$GITHUB_SERVER_URL" in
https://*)
authed_remote="https://oauth2:${TOKEN}@${GITHUB_SERVER_URL#https://}/${GITHUB_REPOSITORY}.git"
;;
http://*)
authed_remote="http://oauth2:${TOKEN}@${GITHUB_SERVER_URL#http://}/${GITHUB_REPOSITORY}.git"
;;
*)
echo "Unsupported GITHUB_SERVER_URL: ${GITHUB_SERVER_URL}" >&2
exit 1
;;
esac
git config user.name "$GIT_USER_NAME"
git config user.email "$GIT_USER_EMAIL"
git remote set-url origin "$authed_remote"
if git rev-parse "$RELEASE_TAG" >/dev/null 2>&1 || git ls-remote --exit-code --tags origin "refs/tags/${RELEASE_TAG}" >/dev/null 2>&1; then
echo "Tag ${RELEASE_TAG} already exists; no new tag can be pushed, so tag-triggered release publication will not run." >&2
echo "Choose a new version (or update changelog content so recommendation advances) and run Prepare Release again." >&2
exit 1
fi
for f in $GIT_ADD_FILES; do
git add "$f"
done
if git diff --cached --quiet; then
echo "No staged release file changes; tagging current HEAD as ${RELEASE_TAG}."
else
git commit -m "release: prepare ${RELEASE_TAG}"
fi
git tag "$RELEASE_TAG"
git push origin HEAD
git push origin "$RELEASE_TAG"