@o3r/new-version 11.2.0-prerelease.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +26 -0
- package/README.md +11 -0
- package/collection.json +11 -0
- package/package.json +135 -0
- package/schematics/ng-add/index.d.ts +4 -0
- package/schematics/ng-add/index.d.ts.map +1 -0
- package/schematics/ng-add/index.js +25 -0
- package/schematics/ng-add/schema.d.ts +7 -0
- package/schematics/ng-add/schema.d.ts.map +1 -0
- package/schematics/ng-add/schema.js +3 -0
- package/schematics/ng-add/schema.json +23 -0
- package/schematics/package.json +3 -0
- package/src/helpers/index.d.ts +6 -0
- package/src/helpers/index.d.ts.map +1 -0
- package/src/helpers/index.js +13 -0
- package/src/helpers/index.js.map +1 -0
- package/src/index.d.ts +80 -0
- package/src/index.d.ts.map +1 -0
- package/src/index.js +125 -0
- package/src/index.js.map +1 -0
- package/src/public_api.d.ts +3 -0
- package/src/public_api.d.ts.map +1 -0
- package/src/public_api.js +6 -0
- package/src/public_api.js.map +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
Copyright Amadeus SAS
|
|
2
|
+
|
|
3
|
+
Redistribution and use in source and binary forms, with or without modification,
|
|
4
|
+
are permitted provided that the following conditions are met:
|
|
5
|
+
|
|
6
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
7
|
+
list of conditions and the following disclaimer.
|
|
8
|
+
|
|
9
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
10
|
+
this list of conditions and the following disclaimer in the documentation and/or
|
|
11
|
+
other materials provided with the distribution.
|
|
12
|
+
|
|
13
|
+
3. Neither the name of the copyright holder nor the names of its contributors
|
|
14
|
+
may be used to endorse or promote products derived from this software without
|
|
15
|
+
specific prior written permission.
|
|
16
|
+
|
|
17
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
18
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
19
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
20
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
|
21
|
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
22
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
23
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
24
|
+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
25
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
26
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
<h1 align="center">Otter new version</h1>
|
|
2
|
+
<p align="center">
|
|
3
|
+
<img src="https://raw.githubusercontent.com/AmadeusITGroup/otter/main/assets/logo/otter.png" alt="Super cute Otter!" width="40%"/>
|
|
4
|
+
</p>
|
|
5
|
+
|
|
6
|
+
## Description
|
|
7
|
+
|
|
8
|
+
[](https://www.npmjs.com/package/@o3r/new-version)
|
|
9
|
+
[](https://www.npmjs.com/package/@o3r/new-version)
|
|
10
|
+
|
|
11
|
+
This module provides a tool to compute the next version number based on the branch names and tags.
|
package/collection.json
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://raw.githubusercontent.com/angular/angular-cli/main/packages/angular_devkit/schematics/collection-schema.json",
|
|
3
|
+
"schematics": {
|
|
4
|
+
"ng-add": {
|
|
5
|
+
"description": "Add Otter new version to the project.",
|
|
6
|
+
"factory": "./schematics/ng-add/index#ngAdd",
|
|
7
|
+
"schema": "./schematics/ng-add/schema.json",
|
|
8
|
+
"aliases": ["install", "i"]
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@o3r/new-version",
|
|
3
|
+
"version": "11.2.0-prerelease.10",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"description": "Helpers to compute new version",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"otter",
|
|
10
|
+
"otter-module"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"nx": "nx",
|
|
14
|
+
"ng": "yarn nx",
|
|
15
|
+
"build": "yarn nx build new-version",
|
|
16
|
+
"postbuild": "patch-package-json-main",
|
|
17
|
+
"prepare:publish": "prepare-publish ./dist",
|
|
18
|
+
"prepare:build:builders": "yarn cpy 'schematics/**/*.json' dist/schematics && yarn cpy 'collection.json' dist",
|
|
19
|
+
"build:builders": "tsc -b tsconfig.builders.json --pretty && yarn generate-cjs-manifest"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"semver": "^7.5.2",
|
|
23
|
+
"tslib": "^2.6.2"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@angular-devkit/core": "~18.1.0",
|
|
27
|
+
"@angular-devkit/schematics": "~18.1.0",
|
|
28
|
+
"@angular-eslint/eslint-plugin": "~18.1.0",
|
|
29
|
+
"@babel/core": "~7.25.0",
|
|
30
|
+
"@babel/preset-typescript": "~7.24.0",
|
|
31
|
+
"@compodoc/compodoc": "^1.1.19",
|
|
32
|
+
"@nx/eslint-plugin": "~19.5.0",
|
|
33
|
+
"@nx/jest": "~19.5.0",
|
|
34
|
+
"@o3r/build-helpers": "^11.2.0-prerelease.10",
|
|
35
|
+
"@o3r/eslint-plugin": "^11.2.0-prerelease.10",
|
|
36
|
+
"@o3r/test-helpers": "^11.2.0-prerelease.10",
|
|
37
|
+
"@stylistic/eslint-plugin-ts": "~2.4.0",
|
|
38
|
+
"@types/jest": "~29.5.2",
|
|
39
|
+
"@types/node": "^20.0.0",
|
|
40
|
+
"@types/semver": "^7.3.13",
|
|
41
|
+
"@typescript-eslint/eslint-plugin": "^7.14.1",
|
|
42
|
+
"@typescript-eslint/parser": "^7.14.1",
|
|
43
|
+
"@typescript-eslint/utils": "^7.14.1",
|
|
44
|
+
"cpy-cli": "^5.0.0",
|
|
45
|
+
"eslint": "^8.57.0",
|
|
46
|
+
"eslint-import-resolver-node": "^0.3.9",
|
|
47
|
+
"eslint-plugin-jest": "~28.7.0",
|
|
48
|
+
"eslint-plugin-jsdoc": "~48.11.0",
|
|
49
|
+
"eslint-plugin-prefer-arrow": "~1.2.3",
|
|
50
|
+
"eslint-plugin-unicorn": "^54.0.0",
|
|
51
|
+
"jest": "~29.7.0",
|
|
52
|
+
"jest-junit": "~16.0.0",
|
|
53
|
+
"nx": "~19.5.0",
|
|
54
|
+
"semver": "^7.5.2",
|
|
55
|
+
"ts-jest": "~29.2.0",
|
|
56
|
+
"ts-node": "~10.9.2",
|
|
57
|
+
"typescript": "~5.5.4"
|
|
58
|
+
},
|
|
59
|
+
"engines": {
|
|
60
|
+
"node": "^18.19.1 || ^20.11.1 || >=22.0.0"
|
|
61
|
+
},
|
|
62
|
+
"schematics": "./collection.json",
|
|
63
|
+
"main": "./src/public_api.js",
|
|
64
|
+
"type": "commonjs",
|
|
65
|
+
"types": "./src/public_api.d.ts",
|
|
66
|
+
"contributors": [
|
|
67
|
+
{
|
|
68
|
+
"name": "Yannick Adam",
|
|
69
|
+
"url": "https://github.com/yannickadam",
|
|
70
|
+
"email": "yannickadam@users.noreply.github.com"
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"name": "Kilian Panot",
|
|
74
|
+
"url": "https://github.com/kpanot",
|
|
75
|
+
"email": "kpanot@users.noreply.github.com"
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"name": "Jeremy Bourgeois",
|
|
79
|
+
"url": "https://github.com/jbourgeois-1A",
|
|
80
|
+
"email": "jbourgeois-1A@users.noreply.github.com"
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
"name": "Pierre Henri Ginoux",
|
|
84
|
+
"url": "https://github.com/pginoux-1A",
|
|
85
|
+
"email": "pginoux-1A@users.noreply.github.com"
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
"name": "Mircea Vasile Rednic",
|
|
89
|
+
"url": "https://github.com/mrednic-1A",
|
|
90
|
+
"email": "mrednic-1A@users.noreply.github.com"
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
"name": "Stephane Dalle",
|
|
94
|
+
"url": "https://github.com/sdalle-1A",
|
|
95
|
+
"email": "sdalle-1A@users.noreply.github.com"
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"name": "Nicolas Hoffmann",
|
|
99
|
+
"url": "https://github.com/nhoffmann-1A",
|
|
100
|
+
"email": "nhoffmann-1A@users.noreply.github.com"
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
"name": "Victor Scaiceanu",
|
|
104
|
+
"url": "https://github.com/vscaiceanu-1a",
|
|
105
|
+
"email": "vscaiceanu-1A@users.noreply.github.com"
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
"name": "Florian Paul",
|
|
109
|
+
"url": "https://github.com/fpaul-1A",
|
|
110
|
+
"email": "fpaul-1A@users.noreply.github.com"
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
"name": "Corinne Paulve",
|
|
114
|
+
"url": "https://github.com/cpaulve-1A",
|
|
115
|
+
"email": "cpaulve-1A@users.noreply.github.com"
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
"name": "Matthieu Crouzet",
|
|
119
|
+
"url": "https://github.com/matthieu-crouzet",
|
|
120
|
+
"email": "matthieu-crouzet@users.noreply.github.com"
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
"name": "Salome Do",
|
|
124
|
+
"url": "https://github.com/sdo-1A",
|
|
125
|
+
"email": "sdo-1A@users.noreply.github.com"
|
|
126
|
+
}
|
|
127
|
+
],
|
|
128
|
+
"bugs": "https://github.com/AmadeusITGroup/otter/issues",
|
|
129
|
+
"repository": {
|
|
130
|
+
"type": "git",
|
|
131
|
+
"url": "git+https://github.com/AmadeusITGroup/otter.git"
|
|
132
|
+
},
|
|
133
|
+
"license": "BSD-3-Clause",
|
|
134
|
+
"homepage": "https://amadeusitgroup.github.io/otter/"
|
|
135
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../schematics/ng-add/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAsBtD,eAAO,MAAM,KAAK,YAAa,qBAAqB,KAAG,IAGtD,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ngAdd = void 0;
|
|
4
|
+
const path = require("node:path");
|
|
5
|
+
const packageJsonPath = path.resolve(__dirname, '..', '..', 'package.json');
|
|
6
|
+
/**
|
|
7
|
+
* Add Otter new version to an Angular Project
|
|
8
|
+
* @param options
|
|
9
|
+
*/
|
|
10
|
+
function ngAddFn(options) {
|
|
11
|
+
/* ng add rules */
|
|
12
|
+
return async (tree) => {
|
|
13
|
+
const { getPackageInstallConfig, setupDependencies } = await Promise.resolve().then(() => require('@o3r/schematics'));
|
|
14
|
+
return setupDependencies({
|
|
15
|
+
projectName: options.projectName,
|
|
16
|
+
dependencies: getPackageInstallConfig(packageJsonPath, tree, options.projectName, true, !!options.exactO3rVersion)
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
const ngAdd = (options) => async () => {
|
|
21
|
+
const { createSchematicWithMetricsIfInstalled } = await Promise.resolve().then(() => require('@o3r/schematics'));
|
|
22
|
+
return createSchematicWithMetricsIfInstalled(ngAddFn)(options);
|
|
23
|
+
};
|
|
24
|
+
exports.ngAdd = ngAdd;
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../schematics/ng-add/schema.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,qBAAqB;IACpC,mBAAmB;IACnB,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAEjC,8CAA8C;IAC9C,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema",
|
|
3
|
+
"$id": "ngAddSchematicsSchema",
|
|
4
|
+
"title": "Add Otter new-version ",
|
|
5
|
+
"description": "ngAdd Otter new-version ",
|
|
6
|
+
"properties": {
|
|
7
|
+
"projectName": {
|
|
8
|
+
"type": "string",
|
|
9
|
+
"description": "Project name",
|
|
10
|
+
"$default": {
|
|
11
|
+
"$source": "projectName"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"exactO3rVersion": {
|
|
15
|
+
"type": "boolean",
|
|
16
|
+
"description": "Use a pinned version for otter packages",
|
|
17
|
+
"default": false
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"additionalProperties": false,
|
|
21
|
+
"required": [
|
|
22
|
+
]
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/helpers/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,YAIpD"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatGitTagsOutput = formatGitTagsOutput;
|
|
4
|
+
/**
|
|
5
|
+
* Extract the list of tags and remove any spaces or endlines
|
|
6
|
+
* @param gitOutput response from git command to format
|
|
7
|
+
*/
|
|
8
|
+
function formatGitTagsOutput(gitOutput) {
|
|
9
|
+
return gitOutput.split(/[\r\n\s]+/g)
|
|
10
|
+
.map((val) => val.replace('remotes/origin/', ''))
|
|
11
|
+
.filter((val) => !!val);
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/helpers/index.ts"],"names":[],"mappings":";;AAIA,kDAIC;AARD;;;GAGG;AACH,SAAgB,mBAAmB,CAAC,SAAiB;IACnD,OAAO,SAAS,CAAC,KAAK,CAAC,YAAY,CAAC;SACjC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAAC;SAChD,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AAC5B,CAAC"}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/** Describes the minimal interface that a logger need to implement to be used by the Cascading plugin */
|
|
2
|
+
export type BaseLogger = {
|
|
3
|
+
debug: (log: string) => void;
|
|
4
|
+
info: (log: string) => void;
|
|
5
|
+
warning: (log: string) => void;
|
|
6
|
+
error: (log: string) => void;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Options expected by the NewVersion plug-in
|
|
10
|
+
*/
|
|
11
|
+
export interface NewVersionOptions<T extends BaseLogger> {
|
|
12
|
+
/** Logger, you can provide here core from @actions/core for example */
|
|
13
|
+
logger: T;
|
|
14
|
+
/** If the branching model supports a default branch on top of usual release branches, the branch name */
|
|
15
|
+
defaultBranch?: string;
|
|
16
|
+
/** Regexp of versionned branches */
|
|
17
|
+
releaseBranchRegExp: RegExp;
|
|
18
|
+
/**
|
|
19
|
+
* How versions computed from the default branch should be named.
|
|
20
|
+
* - If empty, the branch name will be used. ex: 2.6.0-master.0
|
|
21
|
+
* - If set to 'develop' and defaultBranch is 'master', will output 2.6.0-develop.0
|
|
22
|
+
*/
|
|
23
|
+
defaultBranchPrereleaseName?: string;
|
|
24
|
+
/** Version mask to apply when computing a version for the default branch */
|
|
25
|
+
defaultBranchVersionMask?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Release branch to extract Major.Minor version from.
|
|
28
|
+
* If pull request, the target branch. If not, the branch being built.
|
|
29
|
+
*/
|
|
30
|
+
baseBranch: string;
|
|
31
|
+
/** Authenticated GIT URL, used to fetch tags from the repository */
|
|
32
|
+
authenticatedGitUrl: string;
|
|
33
|
+
/** Whether we are computing a version for a Pull request or a branch build */
|
|
34
|
+
isPullRequest: boolean;
|
|
35
|
+
/** The unique identifier of the build, used to compute pull request versions */
|
|
36
|
+
buildId: string;
|
|
37
|
+
/**
|
|
38
|
+
* To use for local testing, to tell in which folder the git commands should be executed
|
|
39
|
+
*/
|
|
40
|
+
localGitFolder?: string;
|
|
41
|
+
/**
|
|
42
|
+
* Pr pre-release tag
|
|
43
|
+
*/
|
|
44
|
+
prPreReleaseTag: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Class responsible for computing the next version according to options and the GIT tags of the repository
|
|
48
|
+
*/
|
|
49
|
+
export declare class NewVersion {
|
|
50
|
+
private readonly options;
|
|
51
|
+
/** Is the current branch supported by the plug-in to compute a new version */
|
|
52
|
+
isBaseBranchSupported: boolean;
|
|
53
|
+
/** Is the current branch the default branch declared in the options */
|
|
54
|
+
isDefaultBranch: boolean;
|
|
55
|
+
/** Name of the pre-release part of versions computed from the default branch */
|
|
56
|
+
defaultBranchPrereleaseName?: string;
|
|
57
|
+
constructor(options: NewVersionOptions<BaseLogger>);
|
|
58
|
+
/**
|
|
59
|
+
* Computes the next version according to the options and the GIT tags of the repository
|
|
60
|
+
*/
|
|
61
|
+
execute(): Promise<string>;
|
|
62
|
+
/**
|
|
63
|
+
* Performs some GIT operations in order to retrieve a list of tags
|
|
64
|
+
*/
|
|
65
|
+
retrieveGitTags(): Promise<string[]>;
|
|
66
|
+
/**
|
|
67
|
+
* Returns the mask with which expected version should start.
|
|
68
|
+
* - If release branch it will be the second part of the branch name: release/[3.2.0-alpha]
|
|
69
|
+
* - If default branch, it will be empty by default unless a mask is explicitly given as an option (options.defaultBranchVersionMask)
|
|
70
|
+
*/
|
|
71
|
+
getVersionMask(): string;
|
|
72
|
+
/**
|
|
73
|
+
* Compute the next version following the version mask.
|
|
74
|
+
* If your default branch is behind your release branches, the version minor will be bumped
|
|
75
|
+
* @param tags
|
|
76
|
+
* @param versionMask
|
|
77
|
+
*/
|
|
78
|
+
computeNewVersion(tags: string[], versionMask: string): string | null;
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAOA,yGAAyG;AACzG,MAAM,MAAM,UAAU,GAAG;IAAE,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IAAC,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IAAC,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IAAC,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAA;CAAE,CAAC;AAErJ;;GAEG;AACH,MAAM,WAAW,iBAAiB,CAAC,CAAC,SAAS,UAAU;IACrD,uEAAuE;IACvE,MAAM,EAAE,CAAC,CAAC;IAEV,yGAAyG;IACzG,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB,oCAAoC;IACpC,mBAAmB,EAAE,MAAM,CAAC;IAE5B;;;;OAIG;IACH,2BAA2B,CAAC,EAAE,MAAM,CAAC;IAErC,4EAA4E;IAC5E,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAElC;;;OAGG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB,oEAAoE;IACpE,mBAAmB,EAAE,MAAM,CAAC;IAE5B,8EAA8E;IAC9E,aAAa,EAAE,OAAO,CAAC;IAEvB,gFAAgF;IAChF,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;OAEG;IACH,eAAe,EAAE,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,qBAAa,UAAU;IAWT,OAAO,CAAC,QAAQ,CAAC,OAAO;IATpC,8EAA8E;IACvE,qBAAqB,EAAE,OAAO,CAAC;IAEtC,uEAAuE;IAChE,eAAe,EAAE,OAAO,CAAC;IAEhC,gFAAgF;IACzE,2BAA2B,CAAC,EAAE,MAAM,CAAC;gBAEf,OAAO,EAAE,iBAAiB,CAAC,UAAU,CAAC;IAMnE;;OAEG;IACU,OAAO;IAWpB;;OAEG;IACU,eAAe;IAa5B;;;;OAIG;IACI,cAAc;IASrB;;;;;OAKG;IACI,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,WAAW,EAAE,MAAM;CA+D7D"}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NewVersion = void 0;
|
|
4
|
+
const node_child_process_1 = require("node:child_process");
|
|
5
|
+
const node_util_1 = require("node:util");
|
|
6
|
+
const semver = require("semver");
|
|
7
|
+
const index_1 = require("./helpers/index");
|
|
8
|
+
const promisifiedExec = (0, node_util_1.promisify)(node_child_process_1.exec);
|
|
9
|
+
/**
|
|
10
|
+
* Class responsible for computing the next version according to options and the GIT tags of the repository
|
|
11
|
+
*/
|
|
12
|
+
class NewVersion {
|
|
13
|
+
constructor(options) {
|
|
14
|
+
this.options = options;
|
|
15
|
+
this.isDefaultBranch = options.defaultBranch === options.baseBranch;
|
|
16
|
+
this.isBaseBranchSupported = this.isDefaultBranch || options.releaseBranchRegExp.test(options.baseBranch);
|
|
17
|
+
this.defaultBranchPrereleaseName = options.defaultBranchPrereleaseName || options.defaultBranch;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Computes the next version according to the options and the GIT tags of the repository
|
|
21
|
+
*/
|
|
22
|
+
async execute() {
|
|
23
|
+
const versionMask = this.getVersionMask();
|
|
24
|
+
const gitTags = await this.retrieveGitTags();
|
|
25
|
+
const newVersion = this.computeNewVersion(gitTags, versionMask);
|
|
26
|
+
if (!newVersion) {
|
|
27
|
+
throw new Error('Could not compute a new version candidate.');
|
|
28
|
+
}
|
|
29
|
+
this.options.logger.info(`New version: ${newVersion}`);
|
|
30
|
+
return newVersion;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Performs some GIT operations in order to retrieve a list of tags
|
|
34
|
+
*/
|
|
35
|
+
async retrieveGitTags() {
|
|
36
|
+
const fetchCommand = `git fetch --tags ${this.options.authenticatedGitUrl}`;
|
|
37
|
+
this.options.logger.debug(`Executing command: ${fetchCommand}`);
|
|
38
|
+
const fetchOutput = await promisifiedExec(fetchCommand, { cwd: this.options.localGitFolder });
|
|
39
|
+
this.options.logger.debug(JSON.stringify(fetchOutput, null, 2));
|
|
40
|
+
const gitTagCommand = 'git tag --list';
|
|
41
|
+
this.options.logger.info(`Executing command: ${gitTagCommand}`);
|
|
42
|
+
const tagsResult = await promisifiedExec(gitTagCommand, { cwd: this.options.localGitFolder });
|
|
43
|
+
this.options.logger.debug('Git tags result:');
|
|
44
|
+
this.options.logger.debug(JSON.stringify(tagsResult, null, 2));
|
|
45
|
+
return (0, index_1.formatGitTagsOutput)(tagsResult.stdout);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Returns the mask with which expected version should start.
|
|
49
|
+
* - If release branch it will be the second part of the branch name: release/[3.2.0-alpha]
|
|
50
|
+
* - If default branch, it will be empty by default unless a mask is explicitly given as an option (options.defaultBranchVersionMask)
|
|
51
|
+
*/
|
|
52
|
+
getVersionMask() {
|
|
53
|
+
const branchReleaseMatches = this.options.releaseBranchRegExp.exec(this.options.baseBranch);
|
|
54
|
+
if (branchReleaseMatches) {
|
|
55
|
+
this.options.logger.info(JSON.stringify(branchReleaseMatches));
|
|
56
|
+
}
|
|
57
|
+
return this.isDefaultBranch && this.options.defaultBranchVersionMask ||
|
|
58
|
+
branchReleaseMatches?.length && `${branchReleaseMatches[1]}.${branchReleaseMatches[2]}${branchReleaseMatches[3] || ''}` || '';
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Compute the next version following the version mask.
|
|
62
|
+
* If your default branch is behind your release branches, the version minor will be bumped
|
|
63
|
+
* @param tags
|
|
64
|
+
* @param versionMask
|
|
65
|
+
*/
|
|
66
|
+
computeNewVersion(tags, versionMask) {
|
|
67
|
+
// Sort tags in descending order and exclude next major in preparation
|
|
68
|
+
let parsedSortedTags = tags
|
|
69
|
+
.map((tag) => semver.parse(tag.replace('V', 'v')))
|
|
70
|
+
.filter((tag) => !!tag && !!tag.raw.match(`^(?:v)?${versionMask}`))
|
|
71
|
+
.sort((v1, v2) => semver.compare(v2, v1));
|
|
72
|
+
this.options.logger.debug('Parsed and sorted tags:');
|
|
73
|
+
this.options.logger.debug(JSON.stringify(parsedSortedTags));
|
|
74
|
+
this.options.logger.info(`Version mask: ${versionMask}`);
|
|
75
|
+
if (!this.isDefaultBranch) {
|
|
76
|
+
// If release branch, we filter all versions that do not satisfy the branch name to exclude 3.6.0-alpha.2 when building branch release/3.6 for example
|
|
77
|
+
parsedSortedTags = parsedSortedTags.filter((parsedTag) => semver.satisfies(parsedTag, `~${versionMask}`));
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
const releaseTags = [...this.defaultBranchPrereleaseName ? [this.defaultBranchPrereleaseName] : [], 'prerelease', 'rc'];
|
|
81
|
+
parsedSortedTags = parsedSortedTags.filter((parsedTag) => parsedTag.prerelease.length === 0 || releaseTags.includes(`${parsedTag.prerelease[0]}`));
|
|
82
|
+
}
|
|
83
|
+
this.options.logger.debug('Tags after filtering:');
|
|
84
|
+
this.options.logger.debug(JSON.stringify(parsedSortedTags));
|
|
85
|
+
const latest = parsedSortedTags[0];
|
|
86
|
+
let baseVersion;
|
|
87
|
+
// If we're on the default branch
|
|
88
|
+
if (this.isDefaultBranch) {
|
|
89
|
+
if (!latest) {
|
|
90
|
+
// If we couldn't find a label after filtering, create a new one using the version mask given
|
|
91
|
+
baseVersion = `${semver.minVersion(versionMask).version}-${this.defaultBranchPrereleaseName}.0`;
|
|
92
|
+
}
|
|
93
|
+
else if (latest.prerelease.some((releaseTag) => releaseTag === this.defaultBranchPrereleaseName)) {
|
|
94
|
+
// If the latest label is a default branch label, we will simply bump it
|
|
95
|
+
this.options.logger.info(`Bumping patch ${this.defaultBranchPrereleaseName || ''}`);
|
|
96
|
+
baseVersion = latest.raw;
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
// If the latest label is a release, it means that we need to create a default branch tag for the next minor version
|
|
100
|
+
const sanitizedLatest = latest.prerelease.length > 0 ? `${latest.major}.${latest.minor}.${latest.patch}` : latest.raw;
|
|
101
|
+
baseVersion = `${semver.inc(sanitizedLatest, 'minor')}-${this.defaultBranchPrereleaseName}.0`;
|
|
102
|
+
}
|
|
103
|
+
// If we're on a release branch
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
// If we found a tag, we use it as a base. Otherwise, we create a new version using the information from the branch, eg. release/3.6.0-alpha
|
|
107
|
+
// will create 3.6.0-alpha.0
|
|
108
|
+
baseVersion = latest ? latest.raw : `${versionMask}.0`;
|
|
109
|
+
}
|
|
110
|
+
this.options.logger.info(`Latest version from tags: ${latest?.version}`);
|
|
111
|
+
this.options.logger.info(`Base version computed: ${baseVersion}`);
|
|
112
|
+
if (this.options.isPullRequest) {
|
|
113
|
+
// If it's a pull-request build, we do not increment but instead add the 'pr' flag and build number to the version
|
|
114
|
+
return `${baseVersion}${this.options.prPreReleaseTag ? '-' + this.options.prPreReleaseTag : ''}.${this.options.buildId}`;
|
|
115
|
+
}
|
|
116
|
+
if (!latest || this.isDefaultBranch && latest.prerelease.every((releaseTag) => releaseTag !== this.defaultBranchPrereleaseName)) {
|
|
117
|
+
// If this is a new release or a new minor of a default branch, we don't bump since they are initialised as .0
|
|
118
|
+
return baseVersion;
|
|
119
|
+
}
|
|
120
|
+
// We bump either the patch or prerelease version depending on what we have.
|
|
121
|
+
return semver.inc(latest, latest.prerelease.length > 0 ? 'prerelease' : 'patch');
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
exports.NewVersion = NewVersion;
|
|
125
|
+
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,2DAAwC;AACxC,yCAAoC;AACpC,iCAAiC;AACjC,2CAAoD;AAEpD,MAAM,eAAe,GAAG,IAAA,qBAAS,EAAC,yBAAI,CAAC,CAAC;AAsDxC;;GAEG;AACH,MAAa,UAAU;IAWrB,YAA6B,OAAsC;QAAtC,YAAO,GAAP,OAAO,CAA+B;QACjE,IAAI,CAAC,eAAe,GAAG,OAAO,CAAC,aAAa,KAAK,OAAO,CAAC,UAAU,CAAC;QACpE,IAAI,CAAC,qBAAqB,GAAG,IAAI,CAAC,eAAe,IAAI,OAAO,CAAC,mBAAmB,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAC1G,IAAI,CAAC,2BAA2B,GAAG,OAAO,CAAC,2BAA2B,IAAI,OAAO,CAAC,aAAa,C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QAElE,IAAI,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC;YAC/B,kHAAkH;YAClH,OAAO,GAAG,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;QAC3H,CAAC;QACD,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,eAAe,IAAI,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,KAAK,IAAI,CAAC,2BAA2B,CAAC,EAAE,CAAC;YAChI,8GAA8G;YAC9G,OAAO,WAAW,CAAC;QACrB,CAAC;QAED,4EAA4E;QAC5E,OAAO,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;IACnF,CAAC;CACF;AAlID,gCAkIC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"public_api.d.ts","sourceRoot":"","sources":["../../src/public_api.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"public_api.js","sourceRoot":"","sources":["../../src/public_api.ts"],"names":[],"mappings":";;;AAAA,0DAAgC;AAChC,kDAAwB"}
|