polyci 0.0.35 → 0.0.37
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/dist/main.js +29 -15
- package/package.json +1 -1
- package/readme.md +1 -0
package/dist/main.js
CHANGED
|
@@ -7,7 +7,8 @@ const log = pino(pretty());
|
|
|
7
7
|
const DEFAULT_TAG_TEMPLATE = "{module}-v{version}";
|
|
8
8
|
const DEFAULT_VERSION_TEMPLATE = "{version}";
|
|
9
9
|
const DEFAULT_BRANCH_VERSION_TEMPLATE = "{version}-{branch}-{increment}";
|
|
10
|
-
const DEFAULT_TAG_PATTERN = "^$PLI_MODULE_NAME-v(?<version>\\d+(\\.\\d+)*)
|
|
10
|
+
const DEFAULT_TAG_PATTERN = "^$PLI_MODULE_NAME-v(?<version>\\d+(\\.\\d+)*)$";
|
|
11
|
+
const DEFAULT_BRANCH_TAG_PATTERN = "^$PLI_MODULE_NAME-v(?<version>\\d+(\\.\\d+)*)(-$CI_COMMIT_BRANCH-(?<increment>\\d+(\\.\\d+)*))?$";
|
|
11
12
|
const ALLOWED_TAG_PLACEHOLDERS = new Set(["module", "version"]);
|
|
12
13
|
const ALLOWED_VERSION_PLACEHOLDERS = new Set(["branch", "version", "increment"]);
|
|
13
14
|
function applyVersionTemplate(template) {
|
|
@@ -53,7 +54,8 @@ function parseArgs() {
|
|
|
53
54
|
.option("--version-template <template>", "Template for primary branch module version; placeholders {version}, {branch}, {increment}", DEFAULT_VERSION_TEMPLATE)
|
|
54
55
|
.option("--branch-version-template <template>", "Template for non-primary branch module version; placeholders {version}, {branch}, {increment}", DEFAULT_BRANCH_VERSION_TEMPLATE)
|
|
55
56
|
.option("--tag-template <template>", "Template for non-primary branch tags; use placeholders {module}, {version}", DEFAULT_TAG_TEMPLATE)
|
|
56
|
-
.option("--tag-pattern <pattern>", "Tag pattern passed to semalease
|
|
57
|
+
.option("--tag-pattern <pattern>", "Tag pattern for main branch (passed to semalease)", DEFAULT_TAG_PATTERN)
|
|
58
|
+
.option("--branch-tag-pattern <pattern>", "Tag pattern for non-main branches (with ?<increment> for branch releases)", DEFAULT_BRANCH_TAG_PATTERN)
|
|
57
59
|
.option("--cwd <path>", "Working directory", process.cwd())
|
|
58
60
|
.parse();
|
|
59
61
|
const options = program.opts();
|
|
@@ -65,6 +67,7 @@ function parseArgs() {
|
|
|
65
67
|
const branchVersionTemplate = options.branchVersionTemplate;
|
|
66
68
|
const tagTemplate = options.tagTemplate;
|
|
67
69
|
const tagPattern = options.tagPattern;
|
|
70
|
+
const branchTagPattern = options.branchTagPattern;
|
|
68
71
|
const invalidVersionTemplate = getInvalidVersionTemplatePlaceholders(versionTemplate);
|
|
69
72
|
if (invalidVersionTemplate.length > 0) {
|
|
70
73
|
program.error(`Invalid --version-template placeholders: ${invalidVersionTemplate
|
|
@@ -92,6 +95,7 @@ function parseArgs() {
|
|
|
92
95
|
branchVersionTemplate,
|
|
93
96
|
tagTemplate,
|
|
94
97
|
tagPattern,
|
|
98
|
+
branchTagPattern,
|
|
95
99
|
};
|
|
96
100
|
}
|
|
97
101
|
function toPosixPath(p) {
|
|
@@ -181,6 +185,7 @@ function appendModuleBuildJob(lines, module) {
|
|
|
181
185
|
lines.push(` - ${module.modulePath}/**/*`);
|
|
182
186
|
lines.push(` image: $IMAGE_NODE`);
|
|
183
187
|
lines.push(` script:`);
|
|
188
|
+
lines.push(` - set -euo pipefail`);
|
|
184
189
|
lines.push(` - cp -r ci "${module.modulePath}/ci"`);
|
|
185
190
|
lines.push(` - cd ${module.modulePath}`);
|
|
186
191
|
lines.push(` - echo "PLI_MODULE_NAME=${module.moduleName}" > polyci.env`);
|
|
@@ -206,6 +211,7 @@ function appendModuleTestJob(lines, module) {
|
|
|
206
211
|
lines.push(` - job: ${module.moduleName}-build`);
|
|
207
212
|
lines.push(` image: $IMAGE_LINUX`);
|
|
208
213
|
lines.push(` script:`);
|
|
214
|
+
lines.push(` - set -euo pipefail`);
|
|
209
215
|
lines.push(` - cp -r ci "${module.modulePath}/ci"`);
|
|
210
216
|
lines.push(` - cd ${module.modulePath}`);
|
|
211
217
|
lines.push(` - cat polyci.env`);
|
|
@@ -217,7 +223,7 @@ function appendModuleTestJob(lines, module) {
|
|
|
217
223
|
lines.push(` - ${module.modulePath}/polyci.env`);
|
|
218
224
|
lines.push(``);
|
|
219
225
|
}
|
|
220
|
-
function appendModuleReleaseJob(lines, module, tagPattern, mainBranch, versionTemplate, branchVersionTemplate, tagTemplate) {
|
|
226
|
+
function appendModuleReleaseJob(lines, module, tagPattern, branchTagPattern, mainBranch, versionTemplate, branchVersionTemplate, tagTemplate) {
|
|
221
227
|
lines.push(`${module.moduleName}-release:`);
|
|
222
228
|
lines.push(` stage: release`);
|
|
223
229
|
lines.push(` rules:`);
|
|
@@ -228,11 +234,17 @@ function appendModuleReleaseJob(lines, module, tagPattern, mainBranch, versionTe
|
|
|
228
234
|
lines.push(` - job: ${module.moduleName}-test`);
|
|
229
235
|
lines.push(` image: $IMAGE_NODE`);
|
|
230
236
|
lines.push(` script:`);
|
|
237
|
+
lines.push(` - set -euo pipefail`);
|
|
231
238
|
lines.push(` - apk update`);
|
|
232
239
|
lines.push(` - apk add $GIT_PACKAGE`);
|
|
233
240
|
lines.push(` - cat "${module.modulePath}/polyci.env"`);
|
|
234
241
|
lines.push(` - source "${module.modulePath}/polyci.env"`);
|
|
235
|
-
lines.push(` -
|
|
242
|
+
lines.push(` - |`);
|
|
243
|
+
lines.push(` if [ "$CI_COMMIT_BRANCH" = "${mainBranch}" ]; then`);
|
|
244
|
+
lines.push(` npx semalease --cwd "${module.modulePath}" --tag-pattern "${tagPattern}" ${module.modulePath}/semalease.env`);
|
|
245
|
+
lines.push(` else`);
|
|
246
|
+
lines.push(` npx semalease --cwd "${module.modulePath}" --tag-pattern "${branchTagPattern}" ${module.modulePath}/semalease.env`);
|
|
247
|
+
lines.push(` fi`);
|
|
236
248
|
lines.push(` - |`);
|
|
237
249
|
lines.push(` if [ -f "${module.modulePath}/semalease.env" ]; then`);
|
|
238
250
|
lines.push(` source "${module.modulePath}/semalease.env"`);
|
|
@@ -241,19 +253,19 @@ function appendModuleReleaseJob(lines, module, tagPattern, mainBranch, versionTe
|
|
|
241
253
|
lines.push(` PLI_MODULE_VERSION="${applyVersionTemplate(versionTemplate)}"`);
|
|
242
254
|
lines.push(` PLI_MODULE_TAG="${applyTagTemplate(tagTemplate, module.moduleName)}"`);
|
|
243
255
|
lines.push(` else`);
|
|
244
|
-
lines.push(` echo "
|
|
256
|
+
lines.push(` echo "No commits affecting ${module.moduleName} version on branch $CI_COMMIT_BRANCH."`);
|
|
245
257
|
lines.push(` fi`);
|
|
246
258
|
lines.push(` else`);
|
|
247
259
|
lines.push(` if [ "\${NEXT_VERSION:-}" != "\${LATEST_VERSION:-}" ] || [ "\${NEXT_INCREMENT:-}" != "\${LATEST_INCREMENT:-}" ]; then`);
|
|
248
260
|
lines.push(` PLI_MODULE_VERSION="${applyVersionTemplate(branchVersionTemplate)}"`);
|
|
249
261
|
lines.push(` PLI_MODULE_TAG="${applyTagTemplate(tagTemplate, module.moduleName)}"`);
|
|
250
262
|
lines.push(` else`);
|
|
251
|
-
lines.push(` echo "
|
|
263
|
+
lines.push(` echo "No commits affecting ${module.moduleName} version on branch $CI_COMMIT_BRANCH."`);
|
|
252
264
|
lines.push(` fi`);
|
|
253
265
|
lines.push(` fi`);
|
|
254
266
|
lines.push(` fi`);
|
|
255
267
|
lines.push(` - |`);
|
|
256
|
-
lines.push(` if [ -n "
|
|
268
|
+
lines.push(` if [ -n "\${PLI_MODULE_VERSION:-}" ] && [ -n "\${PLI_MODULE_TAG:-}" ]; then`);
|
|
257
269
|
lines.push(` echo "PLI_MODULE_VERSION=$PLI_MODULE_VERSION" >> ${module.modulePath}/polyci.env`);
|
|
258
270
|
lines.push(` echo "PLI_MODULE_TAG=$PLI_MODULE_TAG" >> ${module.modulePath}/polyci.env`);
|
|
259
271
|
lines.push(` fi`);
|
|
@@ -274,9 +286,9 @@ function appendGlobalReleaseJob(lines, modules) {
|
|
|
274
286
|
}
|
|
275
287
|
lines.push(` image: $IMAGE_NODE`);
|
|
276
288
|
lines.push(` script:`);
|
|
289
|
+
lines.push(` - set -euo pipefail`);
|
|
277
290
|
lines.push(` - apk update`);
|
|
278
291
|
lines.push(` - apk add $GIT_PACKAGE`);
|
|
279
|
-
lines.push(` - set -euo pipefail`);
|
|
280
292
|
lines.push(` - git config user.email "polyci@anarun.net"`);
|
|
281
293
|
lines.push(` - git config user.name "polyci"`);
|
|
282
294
|
lines.push(` - git remote set-url origin "https://oauth2:\${POLYCI_TOKEN}@\${CI_SERVER_HOST}/\${CI_PROJECT_PATH}.git"`);
|
|
@@ -289,7 +301,7 @@ function appendGlobalReleaseJob(lines, modules) {
|
|
|
289
301
|
lines.push(` unset PLI_MODULE_TAG`);
|
|
290
302
|
lines.push(` cat "${module.modulePath}/polyci.env"`);
|
|
291
303
|
lines.push(` source "${module.modulePath}/polyci.env"`);
|
|
292
|
-
lines.push(` if [ -n "
|
|
304
|
+
lines.push(` if [ -n "\${PLI_MODULE_VERSION:-}" ] && [ -n "\${PLI_MODULE_TAG:-}" ]; then`);
|
|
293
305
|
lines.push(` cp -r ci "${module.modulePath}/ci"`);
|
|
294
306
|
lines.push(` ROOT_REPO_DIR="\${PWD}"`);
|
|
295
307
|
lines.push(` cd "${module.modulePath}"`);
|
|
@@ -331,8 +343,9 @@ function appendModulePublishJob(lines, module) {
|
|
|
331
343
|
lines.push(` needs:`);
|
|
332
344
|
lines.push(` - job: ${module.moduleName}-test`);
|
|
333
345
|
lines.push(` - job: release`);
|
|
334
|
-
lines.push(` image: $
|
|
346
|
+
lines.push(` image: $IMAGE_NODE`);
|
|
335
347
|
lines.push(` script:`);
|
|
348
|
+
lines.push(` - set -euo pipefail`);
|
|
336
349
|
lines.push(` - cp -r ci "${module.modulePath}/ci"`);
|
|
337
350
|
lines.push(` - cd ${module.modulePath}`);
|
|
338
351
|
lines.push(` - cat polyci.env`);
|
|
@@ -352,8 +365,9 @@ function appendModuleDeployJob(lines, module) {
|
|
|
352
365
|
lines.push(` - ${module.modulePath}/**/*`);
|
|
353
366
|
lines.push(` needs:`);
|
|
354
367
|
lines.push(` - job: ${module.moduleName}-publish`);
|
|
355
|
-
lines.push(` image: $
|
|
368
|
+
lines.push(` image: $IMAGE_NODE`);
|
|
356
369
|
lines.push(` script:`);
|
|
370
|
+
lines.push(` - set -euo pipefail`);
|
|
357
371
|
lines.push(` - cp -r ci "${module.modulePath}/ci"`);
|
|
358
372
|
lines.push(` - cd ${module.modulePath}`);
|
|
359
373
|
lines.push(` - cat polyci.env`);
|
|
@@ -361,13 +375,13 @@ function appendModuleDeployJob(lines, module) {
|
|
|
361
375
|
lines.push(` - source "ci/${module.moduleType}/deploy.sh"`);
|
|
362
376
|
lines.push(``);
|
|
363
377
|
}
|
|
364
|
-
function buildPipeline(modules, mainBranch, versionTemplate, branchVersionTemplate, tagTemplate, tagPattern) {
|
|
378
|
+
function buildPipeline(modules, mainBranch, versionTemplate, branchVersionTemplate, tagTemplate, tagPattern, branchTagPattern) {
|
|
365
379
|
const lines = [];
|
|
366
380
|
appendGlobalVariables(lines);
|
|
367
381
|
for (const module of modules) {
|
|
368
382
|
appendModuleBuildJob(lines, module);
|
|
369
383
|
appendModuleTestJob(lines, module);
|
|
370
|
-
appendModuleReleaseJob(lines, module, tagPattern, mainBranch, versionTemplate, branchVersionTemplate, tagTemplate);
|
|
384
|
+
appendModuleReleaseJob(lines, module, tagPattern, branchTagPattern, mainBranch, versionTemplate, branchVersionTemplate, tagTemplate);
|
|
371
385
|
}
|
|
372
386
|
appendGlobalReleaseJob(lines, modules);
|
|
373
387
|
for (const module of modules) {
|
|
@@ -377,7 +391,7 @@ function buildPipeline(modules, mainBranch, versionTemplate, branchVersionTempla
|
|
|
377
391
|
return `${lines.join("\n").trimEnd()}\n`;
|
|
378
392
|
}
|
|
379
393
|
function main() {
|
|
380
|
-
const { cwd, output, modulesRoot, mainBranch, versionTemplate, branchVersionTemplate, tagTemplate, tagPattern } = parseArgs();
|
|
394
|
+
const { cwd, output, modulesRoot, mainBranch, versionTemplate, branchVersionTemplate, tagTemplate, tagPattern, branchTagPattern } = parseArgs();
|
|
381
395
|
if (!output) {
|
|
382
396
|
log.error("Output path is required. Use [output] or --output <path>.");
|
|
383
397
|
process.exit(1);
|
|
@@ -387,7 +401,7 @@ function main() {
|
|
|
387
401
|
log.error({ cwd, modulesRoot }, "No supported modules were discovered under modules root");
|
|
388
402
|
process.exit(1);
|
|
389
403
|
}
|
|
390
|
-
const pipeline = buildPipeline(modules, mainBranch, versionTemplate, branchVersionTemplate, tagTemplate, tagPattern);
|
|
404
|
+
const pipeline = buildPipeline(modules, mainBranch, versionTemplate, branchVersionTemplate, tagTemplate, tagPattern, branchTagPattern);
|
|
391
405
|
const outputPath = path.resolve(cwd, output);
|
|
392
406
|
fs.writeFileSync(outputPath, pipeline, "utf8");
|
|
393
407
|
log.info({ modules: modules.map((m) => m.modulePath), outputPath }, "Generated GitLab pipeline");
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -4,6 +4,7 @@ usage
|
|
|
4
4
|
|
|
5
5
|
recommedations
|
|
6
6
|
do not change the provided module types and scripts. instead, copy and customise your own type.
|
|
7
|
+
be careful changin environment in release.sh (eg install packages) as the module releases run in one job in one container.
|
|
7
8
|
|
|
8
9
|
requirements
|
|
9
10
|
POLYCI_TOKEN variable must be defined in GitLab and accessible in the jobs that match the rule in the root .gitlab-ci.yml.
|