Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for a custom tag prefix #8

Merged
merged 7 commits into from
Dec 21, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ inputs:
description: Path to changelog
required: false
title:
description: Format of title (variables `$tag`, `$version`, and any string)
description: Format of title (variables `$tag`, `$version`, `$prefix`, and any string)
required: false
default: '$tag'
draft:
Expand All @@ -16,6 +16,19 @@ inputs:
branch:
description: Reject releases from commits not contained in branches that match the specified pattern (regular expression)
required: false
prefix:
description: >
A prefix for the release tag, before the version number (for
example, 'my-crate-v0.1.2' has the prefix 'my-crate-').

The prefix may not contain regular expression characters such as `\`, `.`,
`(`, `)`, `[`, `]`, `{` and `}`.

If the prefix ends in a trailing '-', it will be stripped before
interpolating the prefix into the title, if `$prefix` appears in the title
format.
required: false
default: ''

runs:
using: node12
Expand Down
18 changes: 14 additions & 4 deletions main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ title="${INPUT_TITLE:?}"
changelog="${INPUT_CHANGELOG:-}"
draft="${INPUT_DRAFT:-}"
branch="${INPUT_BRANCH:-}"
prefix="${INPUT_PREFIX:-}"

if [[ -z "${GITHUB_TOKEN:-}" ]]; then
error "GITHUB_TOKEN not set"
Expand All @@ -29,17 +30,26 @@ if [[ "${GITHUB_REF:?}" != "refs/tags/"* ]]; then
fi
tag="${GITHUB_REF#refs/tags/}"

# TODO: Support custom prefix of tags https://github.com/taiki-e/create-gh-release-action/issues/1
if [[ ! "${tag}" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z_0-9\.-]+)?(\+[a-zA-Z_0-9\.-]+)?$ ]]; then
if [[ "${prefix}" =~ (\\|\$|\[|\]|\*|\||\{|\}|\+|\?|\^|\(|\)|\.)+ ]]; then
error "prefix '${prefix}' contained regular expression characters"
exit 1
fi

taiki-e marked this conversation as resolved.
Show resolved Hide resolved
if [[ ! "${tag}" =~ ^${prefix}v?[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z_0-9\.-]+)?(\+[a-zA-Z_0-9\.-]+)?$ ]]; then
error "invalid tag format: '${tag}'"
exit 1
fi
if [[ "${tag}" =~ ^v?[0-9\.]+-[a-zA-Z_0-9\.-]+(\+[a-zA-Z_0-9\.-]+)?$ ]]; then
if [[ "${tag}" =~ ^${prefix}v?[0-9\.]+-[a-zA-Z_0-9\.-]+(\+[a-zA-Z_0-9\.-]+)?$ ]]; then
prerelease="--prerelease"
fi
version="${tag#v}"
version="${tag#${prefix}v}"
# if the prefix has a trailing slash, strip it so that the prefix can be used in
# the title.
prefix="${prefix#-}"
title="${title/\$tag/${tag}}"
title="${title/\$version/${version}}"
title="${title/\$prefix/${prefix}}"

taiki-e marked this conversation as resolved.
Show resolved Hide resolved

case "${draft}" in
true) draft_option="--draft" ;;
Expand Down