pascalgn / npm-publish-action

GitHub action to automatically publish packages to npm
MIT License
221 stars 29 forks source link

Support for npm tags #4

Open chuckdumont opened 4 years ago

chuckdumont commented 4 years ago

It would be nice if this action could support tagged releases. You could key off of the commit message for package.json. For example, "TaggedRelease beta" or "TaggedRelease next 1.2.3-rc2". With these commit messages, the action would use the --tag option with the second token in the message. For example:

npm publish --tag next
pascalgn commented 4 years ago

Do you maybe want to create a PR for this? 🙏

endel commented 4 years ago

Hi guys, has anyone been working on this? I'm also interested in releasing with --tag, I'm wondering if we could use the --tag automatically in case there is a dash in the version name?

Examples:

The RegExp to get the tag name could simply extract a-z characters from the version string (/([a-zA-Z]+)/) and use it for the tag name. What do you think?

endel commented 4 years ago

If we go for the RegExp approach, in case the a-zA-Z characters are found we can consider using --tag:

const version = "1.2.3-alpha.0";
const tagName = version.match(/([a-zA-Z]+)/);

if (tagName) {
  // need to publish with `--tag ${tagName[1]}`
} else {
  // no need to use --tag
}
pascalgn commented 4 years ago

I am thinking -- could we let the user provide a regex, for example /([0-9.]+)-(.+)/ and if the result after matching the commit message contains 1 (non-empty) group, we assume non-tagged, and with 2 groups, we assume tagged release? Alternatively, but maybe harder to implement, would be to let the users provide 2 regexes, one for normal releases, one for tagged? WDYT?