From 9e3539fe5fef28372c1b4698fec5a87e7dce9131 Mon Sep 17 00:00:00 2001 From: Matthias Radig Date: Fri, 16 Jul 2021 10:53:18 +0200 Subject: [PATCH] Remove the hyphen in PR major versions The hyphen can be problematic, e.g. when using the version for an RPM. --- README.md | 4 ++-- test/testVersion.js | 6 +++--- version.js | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 48ac09b..56e2027 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ The general idea is to generate a unique version string from the job context tha | ------------ | ------- | ------- | | Git tag | \ | v1.3.2 | Branch | \-\-\ | main-9-f025368a | -| Pull request | pr-\-\-\ | pr-9-1-89d735ed | +| Pull request | pr\-\-\ | pr9-1-89d735ed | Tags are assumed to already satisfy these goals and are taken as-is. For other cases, the first part (branch name or PR number) tells whether two version can be compared, the second part (build number) allows to quickly tell versions apart, and the commit hash uniquely identifies the revision of the source that was build. @@ -31,7 +31,7 @@ Tags are assumed to already satisfy these goals and are taken as-is. For other c | refs/tags/1.2.3.4| 9| a52f| 1.2.3.4| 1.2.3.4| 1| 2| 3.4| | refs/heads/main| 9| a52f| main-9-a52f| main-9-a52f| main| 9| a52f| | refs/heads/stable| 9| a52f| stable-9-a52f| stable-9-a52f| stable| 9| a52f| -| refs/pull/1/merge| 9| a52f| pr-1-9-a52f| pr-1-9-a52f| pr-1| 9| a52f| +| refs/pull/1/merge| 9| a52f| pr1-9-a52f| pr1-9-a52f| pr1| 9| a52f| ## Example Usage ``` diff --git a/test/testVersion.js b/test/testVersion.js index 0f5bfe7..ee40bb4 100644 --- a/test/testVersion.js +++ b/test/testVersion.js @@ -4,8 +4,8 @@ let version = require('../version'); let testData = [ ['refs/heads/main', '1', 'abcd', 'main-1-abcd', 'main', '1', 'abcd'], - ['refs/pull/1/merge', '2', 'abcd', 'pr-1-2-abcd', 'pr-1', '2', 'abcd'], - ['refs/pull/1/base', '2', 'abcd', 'pr-1-2-abcd', 'pr-1', '2', 'abcd'], + ['refs/pull/1/merge', '2', 'abcd', 'pr1-2-abcd', 'pr1', '2', 'abcd'], + ['refs/pull/1/base', '2', 'abcd', 'pr1-2-abcd', 'pr1', '2', 'abcd'], ['refs/tags/v1', '2', 'abcd', 'v1', '1', '', ''], ['refs/tags/1.0', '2', 'abcd', '1.0', '1', '0', ''], ['refs/tags/1.0.0', '2', 'abcd', '1.0.0', '1', '0', '0'], @@ -20,7 +20,7 @@ let testDataWithoutV = [ // do nothing for branches ['refs/heads/main', '1', 'abcd', 'main-1-abcd'], ['refs/heads/v100', '1', 'abcd', 'v100-1-abcd'], - ['refs/pull/1/merge', '2', 'abcd', 'pr-1-2-abcd'], + ['refs/pull/1/merge', '2', 'abcd', 'pr1-2-abcd'], // strip leading v from version numbers ['refs/tags/1.0.0', '2', 'abcd', '1.0.0'], diff --git a/version.js b/version.js index 33fa353..9a17235 100644 --- a/version.js +++ b/version.js @@ -20,7 +20,7 @@ function fromTag(tag) { function fromRefRunSha(ref, run, sha) { sha = sha.substr(0, 8); if (ref.startsWith('refs/pull/')) { - ref = ref.replace(/^refs\/pull\/(\d+)\/.*/, 'pr-$1'); + ref = ref.replace(/^refs\/pull\/(\d+)\/.*/, 'pr$1'); } else { ref = ref.replace(/^refs\/heads\//, ''); }