Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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: 4 additions & 2 deletions src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ const regexes = {
owner: /[^\s\/]+/,
repository: /[^\s\/]+/,
binaryName: /[^\s@]+/,
majorSemanticVersion: /v(?:0|[1-9]\d*)/,
majorMinorSemanticVersion: /v(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)/,
majorSemanticVersion:
/v(?: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-]+)*))?/,
majorMinorSemanticVersion:
/v(?: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-]+)*))?/,
exactSemanticVersion:
/v(?: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-]+)*))?/,
sha256Hash: /[a-fA-F0-9]{64}/,
Expand Down
184 changes: 184 additions & 0 deletions test/test-parse-target-release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,187 @@ test(
]),
),
);

test(
"should parse a major version with prerelease",
check(
"foo/bar@v1-beta",
ok([
{
slug: {
owner: "foo",
repository: "bar",
},
binaryName: none(),
tag: "v1-beta" as SemanticVersion,
checksum: none(),
},
]),
),
);

test(
"should parse a major version with prerelease and number",
check(
"foo/bar@v1-beta.123",

Choose a reason for hiding this comment

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

Is this a format we use?

Copy link
Author

Choose a reason for hiding this comment

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

Mmm maybe not? I'm not too sure 🤔.

Now that I think about it, I don't even know what version this would point to

ok([
{
slug: {
owner: "foo",
repository: "bar",
},
binaryName: none(),
tag: "v1-beta.123" as SemanticVersion,
checksum: none(),
},
]),
),
);

test(
"should parse a major.minor version with prerelease",
check(
"foo/bar@v1.1-beta",
ok([
{
slug: {
owner: "foo",
repository: "bar",
},
binaryName: none(),
tag: "v1.1-beta" as SemanticVersion,
checksum: none(),
},
]),
),
);

test(
"should parse a major.minor version with prerelease and number",
check(
"foo/bar@v1.1-beta.123",
ok([
{
slug: {
owner: "foo",
repository: "bar",
},
binaryName: none(),
tag: "v1.1-beta.123" as SemanticVersion,
checksum: none(),
},
]),
),
);

test(
"should parse a major.minor.patch version with prerelease",
check(
"foo/bar@v1.2.3-alpha.1",
ok([
{
slug: {
owner: "foo",
repository: "bar",
},
binaryName: none(),
tag: "v1.2.3-alpha.1" as SemanticVersion,
checksum: none(),
},
]),
),
);

test(
"should parse a major version with build metadata",
check(
"foo/bar@v1+build.123",
ok([
{
slug: {
owner: "foo",
repository: "bar",
},
binaryName: none(),
tag: "v1+build.123" as SemanticVersion,
checksum: none(),
},
]),
),
);

test(
"should parse a major.minor version with build metadata",
check(
"foo/bar@v1.1+build.123",

Choose a reason for hiding this comment

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

Not positive this case is necessary?

ok([
{
slug: {
owner: "foo",
repository: "bar",
},
binaryName: none(),
tag: "v1.1+build.123" as SemanticVersion,
checksum: none(),
},
]),
),
);

test(
"should parse a major.minor.patch version with prerelease and build metadata",
check(
"foo/bar@v1.2.3-rc.1+build.456",
ok([
{
slug: {
owner: "foo",
repository: "bar",
},
binaryName: none(),
tag: "v1.2.3-rc.1+build.456" as SemanticVersion,
checksum: none(),
},
]),
),
);

test(
"should parse a major version with prerelease and checksum",
check(
"foo/bar@v1-beta:sha256-8a4600be96d2ec013209042458ce97a9652fcc46c1c855d0217aa42e330fc06e",
ok([
{
slug: {
owner: "foo",
repository: "bar",
},
binaryName: none(),
tag: "v1-beta" as SemanticVersion,
checksum: some(
"8a4600be96d2ec013209042458ce97a9652fcc46c1c855d0217aa42e330fc06e" as Sha256Hash,
),
},
]),
),
);

test(
"should parse a major.minor version with prerelease and checksum",
check(
"foo/bar@v1.1-beta.123:sha256-8a4600be96d2ec013209042458ce97a9652fcc46c1c855d0217aa42e330fc06e",
ok([
{
slug: {
owner: "foo",
repository: "bar",
},
binaryName: none(),
tag: "v1.1-beta.123" as SemanticVersion,
checksum: some(
"8a4600be96d2ec013209042458ce97a9652fcc46c1c855d0217aa42e330fc06e" as Sha256Hash,
),
},
]),
),
);