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

163 lines
5.3 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: 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
id: recommend-version
if: steps.normalize-version.outputs.value == ''
uses: ../run-vociferate
with:
root: ${{ github.workspace }}
version-file: ${{ inputs.version-file }}
version-pattern: ${{ inputs.version-pattern }}
changelog: ${{ inputs.changelog }}
recommend: 'true'
- name: Finalize version
id: finalize-version
shell: bash
env:
PROVIDED_VERSION: ${{ steps.normalize-version.outputs.value }}
RECOMMENDED_VERSION: ${{ steps.recommend-version.outputs.stdout }}
run: |
set -euo pipefail
provided_version="$PROVIDED_VERSION"
if [[ -z "$provided_version" ]]; then
provided_version="$RECOMMENDED_VERSION"
fi
normalized_version="${provided_version#v}"
tag="v${normalized_version}"
printf 'version=%s\n' "$tag" >> "$GITHUB_OUTPUT"
- name: Resolve release date
id: resolve-date
shell: bash
run: |
set -euo pipefail
printf 'value=%s\n' "$(date -u +%F)" >> "$GITHUB_OUTPUT"
- name: Prepare release files
uses: ../run-vociferate
with:
root: ${{ github.workspace }}
version-file: ${{ inputs.version-file }}
version-pattern: ${{ inputs.version-pattern }}
changelog: ${{ inputs.changelog }}
version: ${{ steps.finalize-version.outputs.version }}
date: ${{ steps.resolve-date.outputs.value }}
- 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"