From db362a92bee686338ec2116fe08dbe9cc9cebdef Mon Sep 17 00:00:00 2001 From: Dereck Tu Date: Thu, 4 Dec 2025 10:15:08 -0500 Subject: [PATCH] feat: support sliding prerelease tags Ticket: DX-2438 --- src/parse.ts | 6 +- test/test-parse-target-release.ts | 184 ++++++++++++++++++++++++++++++ 2 files changed, 188 insertions(+), 2 deletions(-) diff --git a/src/parse.ts b/src/parse.ts index 0a7525b..aeb4437 100644 --- a/src/parse.ts +++ b/src/parse.ts @@ -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}/, diff --git a/test/test-parse-target-release.ts b/test/test-parse-target-release.ts index 9ebf56d..59a4c23 100644 --- a/test/test-parse-target-release.ts +++ b/test/test-parse-target-release.ts @@ -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", + 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", + 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, + ), + }, + ]), + ), +);