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

Conversation

hawkw
Copy link
Contributor

@hawkw hawkw commented Dec 17, 2021

This branch adds support for specifiying a tag prefix before the version
number. The prefix is specified as a bash regular expression; the string
matching that regular expression is available in the $prefix variable
that can be interpolated into the changelog path and title string.

Additionally, since I was adding support for interpolating $prefix
into the changelog path anyway, I went ahead and allowed $version and
$tag to be interpolated into the changelog path as well. This might
be useful in cases where the changelog for each version is stored in its
own text file...though I don't think this is a particularly common
pattern.

Closes #1

This branch adds support for specifiying a tag prefix before the version
number. It turns out that this was actually pretty simple to add. We
simply interpolate the passed-in prefix to the regular expression for
detecting tags, and then strip the prefix when generating the version
number.

Currently, the prefix is interpreted as a fixed string; if it contains
regular expression characters, we escape them before adding it to the
pattern that's matched to detect tags that should generate releases.
It's possible that maybe we'd actually _prefer_ to allow interpreting it
as a pattern, so I'd be happy to change that if so.
Copy link
Owner

@taiki-e taiki-e left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!


It's possible that maybe we'd actually prefer to allow interpreting it
as a pattern, so I'd be happy to change that if so.

I was originally thinking of a use case where tags exist for each crate, such as crossbeam, so I think eventually supporting regular expressions might be preferable.
However, in such a use case, there is a changelog for each crate, so supporting regular expressions in the tag prefix is likely to be insufficient.
So, I don't believe that regular expression support will block this PR.

main.sh Outdated Show resolved Hide resolved
main.sh Outdated Show resolved Hide resolved
@hawkw hawkw requested a review from taiki-e December 18, 2021 20:16
@hawkw
Copy link
Contributor Author

hawkw commented Dec 18, 2021

I was originally thinking of a use case where tags exist for each crate, such as crossbeam, so I think eventually supporting regular expressions might be preferable.

That was also what I was imagining, actually --- my goal was to be able to use the action for the tokio-rs/console repository, which contains three crates and separate release tags for each crate. I was actually planning to use my own regex, anyway, though, to extract the names of the subdirectories for the changelog path; the prefix can then just be a regular string, because I've already extracted the name of the crate: https://github.com/tokio-rs/console/blob/3da945d13cfa7fc95cb643a896006667f0da9972/.github/workflows/release.yaml#L3-L42

It would be even nicer if this action could handle extracting the crate name based on a regex prefix, but that would be a bit more work, I think...we'd then also need a way to express that a variable (the prefix) should be interpolated into the changelog path, the way we currently do for release titles.

@hawkw
Copy link
Contributor Author

hawkw commented Dec 18, 2021

After thinking about it a bit more, we should probably just make prefix: a regex, make $prefix get set to the part of the tag that matched the regex, and allow interpolating $prefix into the changelog path...

@taiki-e
Copy link
Owner

taiki-e commented Dec 19, 2021

After thinking about it a bit more, we should probably just make prefix: a regex, make $prefix get set to the part of the tag that matched the regex, and allow interpolating $prefix into the changelog path...

Sounds good to me.

main.sh Outdated Show resolved Hide resolved
Also, allow interpolating the prefix (as well as version and tag) into
the changelog path. This way, we can easily support multi-crate
workspaces and other repositories with multiple changelog files.

Signed-off-by: Eliza Weisman <[email protected]>
@hawkw hawkw requested a review from taiki-e December 19, 2021 20:43
@hawkw
Copy link
Contributor Author

hawkw commented Dec 19, 2021

Okay, the prefix is now matched as a pattern, and $prefix, which contains the portion of the tag matching that pattern, can be interpolated into the title and changelog path.

Copy link
Owner

@taiki-e taiki-e left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

main.sh Outdated Show resolved Hide resolved
main.sh Outdated Show resolved Hide resolved
@hawkw
Copy link
Contributor Author

hawkw commented Dec 20, 2021

I've replaced the use of expr with grep as you suggested. Let me know if there's anything else I need to do?

main.sh Outdated Show resolved Hide resolved
@taiki-e taiki-e merged commit 5dc2f64 into taiki-e:main Dec 21, 2021
@taiki-e
Copy link
Owner

taiki-e commented Dec 21, 2021

Published in 1.3.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support custom prefix of tags
2 participants