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 1 commit
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
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ 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-').
required: false
default: ''

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

# `prefix` is used as part of a regular expression, but it's a literal string,
# so escape any regex special characters first
prefix="$(printf '%s' "$prefix" | sed 's/[]\\.$*{}|+?()[^-]/\\&/g')"
hawkw marked this conversation as resolved.
Show resolved Hide resolved

if [[ -z "${GITHUB_TOKEN:-}" ]]; then
error "GITHUB_TOKEN not set"
Expand All @@ -29,15 +34,14 @@ 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 [[ ! "${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}"
title="${title/\$tag/${tag}}"
title="${title/\$version/${version}}"
hawkw marked this conversation as resolved.
Show resolved Hide resolved

Expand Down