Skip to content

Commit

Permalink
Adapt semver regex & throw errors accordingly
Browse files Browse the repository at this point in the history
  • Loading branch information
medallyon committed Aug 12, 2021
1 parent 07e3399 commit 3047868
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
15 changes: 10 additions & 5 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

15 changes: 10 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,21 @@ async function run()
{
try
{
const payload = github.context.payload
, tag = payload.release.tag_name;
const payload = github.context.payload;
let tag = payload.release.tag_name;

if (!/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/gm.test(tag))
core.setFailed("Release Tag does not match semantic versioning.");
if (tag.startsWith("v"))
tag = tag.replace("v", "");

if (!/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/gm.test(tag))
{
throw new Error("Release Tag does not match semantic versioning.");
}

const pkg = await fs.readJson("./package.json")
, originalVersion = pkg.version;

pkg.version = tag.replace("v", "");
pkg.version = tag;
await fs.outputJson("./package.json", pkg, {
spaces: 2
});
Expand Down

0 comments on commit 3047868

Please sign in to comment.