Skip to content

Commit

Permalink
Merge pull request #125 from minrk/loose-parse
Browse files Browse the repository at this point in the history
use loose semver parsing to accept more prerelease formats
  • Loading branch information
consideRatio authored Sep 26, 2021
2 parents 0cfbca0 + 1c22ca7 commit 6f187f2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
10 changes: 10 additions & 0 deletions __tests__/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,16 @@ test("Unsupported prerelease tag", async () => {
expect(tags).toEqual(["2.0.0-rc1"]);
});

test("Unsupported prerelease tag, loose parsing", async () => {
const tags = await calculateTags({
token: "TOKEN",
owner: "owner",
repo: "repo",
ref: "refs/tags/2.0.0b1",
});
expect(tags).toEqual(["2.0.0b1"]);
});

test("Not a tag", async () => {
await expect(
calculateTags({
Expand Down
11 changes: 7 additions & 4 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.

11 changes: 7 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,14 @@ async function calculateTags({

const currentTag = ref.substring(10);
core.debug(`currentTag: ${currentTag}`);
if (!semver.valid(currentTag)) {
if (!semver.valid(currentTag, { loose: true })) {
throw new Error(`Invalid semver tag: ${currentTag}`);
}

const current = semver.parse(currentTag, { includePrerelease: true });
const current = semver.parse(currentTag, {
includePrerelease: true,
loose: true,
});
if (!supportedPrerelease(current.prerelease)) {
core.warning(`Tag prerelease ${currentTag} is not supported`);
return [`${prefix}${currentTag}`];
Expand All @@ -83,8 +86,8 @@ async function calculateTags({
repo: repo,
});
const parsedTagrefs = tagrefs
.filter((a) => semver.valid(a.name))
.map((a) => semver.parse(a.name, { includePrerelease: true }));
.filter((a) => semver.valid(a.name, { loose: true }))
.map((a) => semver.parse(a.name, { includePrerelease: true, loose: true }));

const tags = parsedTagrefs
.filter((t) => supportedPrerelease(t.prerelease))
Expand Down

0 comments on commit 6f187f2

Please sign in to comment.