polyci 0.0.4 → 0.0.6
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 +40 -29
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -12,6 +12,7 @@ function parseArgs() {
|
|
|
12
12
|
.option("-o, --output <path>", "Output pipeline file path")
|
|
13
13
|
.option("--modules-root <path>", "Modules root directory", "./modules")
|
|
14
14
|
.option("--branch-rule <regex>", "Branch rule regex for module jobs", DEFAULT_BRANCH_RULE)
|
|
15
|
+
.option("--main-branch <name>", "Primary branch name for release tagging logic", "main")
|
|
15
16
|
.option("--cwd <path>", "Working directory", process.cwd())
|
|
16
17
|
.parse();
|
|
17
18
|
const options = program.opts();
|
|
@@ -19,7 +20,8 @@ function parseArgs() {
|
|
|
19
20
|
const cwd = path.resolve(options.cwd);
|
|
20
21
|
const modulesRoot = path.resolve(cwd, options.modulesRoot);
|
|
21
22
|
const branchRule = options.branchRule;
|
|
22
|
-
|
|
23
|
+
const mainBranch = options.mainBranch;
|
|
24
|
+
return { cwd, output, modulesRoot, branchRule, mainBranch };
|
|
23
25
|
}
|
|
24
26
|
function toPosixPath(p) {
|
|
25
27
|
return p.split(path.sep).join("/");
|
|
@@ -195,7 +197,7 @@ function appendModuleReleaseJob(lines, module, branchRule) {
|
|
|
195
197
|
lines.push(` expire_in: 1 day`);
|
|
196
198
|
lines.push("");
|
|
197
199
|
}
|
|
198
|
-
function appendGlobalReleaseJob(lines, modules) {
|
|
200
|
+
function appendGlobalReleaseJob(lines, modules, mainBranch) {
|
|
199
201
|
lines.push("release_and_tag:");
|
|
200
202
|
lines.push(" stage: release");
|
|
201
203
|
lines.push(" needs:");
|
|
@@ -214,39 +216,48 @@ function appendGlobalReleaseJob(lines, modules) {
|
|
|
214
216
|
lines.push(" git config user.email \"polyci@anarun.net\"");
|
|
215
217
|
lines.push(" git config user.name \"polyci\"");
|
|
216
218
|
lines.push(" git remote set-url origin \"https://oauth2:${GITLAB_TOKEN}@${CI_SERVER_HOST}/${CI_PROJECT_PATH}.git\"");
|
|
219
|
+
lines.push(" TAG_CREATED=false");
|
|
217
220
|
lines.push("");
|
|
218
221
|
for (const module of modules) {
|
|
219
222
|
lines.push(` echo "Tagging release for ${module.moduleName} (${module.modulePath})"`);
|
|
220
|
-
lines.push(` if [
|
|
221
|
-
lines.push(`
|
|
222
|
-
lines.push("
|
|
223
|
-
lines.push("
|
|
224
|
-
lines.push(
|
|
225
|
-
lines.push("
|
|
226
|
-
lines.push("
|
|
227
|
-
lines.push(`
|
|
228
|
-
lines.push("
|
|
223
|
+
lines.push(` if [ -f "${module.modulePath}/semalease.env" ]; then`);
|
|
224
|
+
lines.push(` . "${module.modulePath}/semalease.env"`);
|
|
225
|
+
lines.push(" TAG_NAME=\"\"");
|
|
226
|
+
lines.push(` if [ "$CI_COMMIT_BRANCH" = "${mainBranch}" ]; then`);
|
|
227
|
+
lines.push(" if [ \"${NEXT_VERSION:-}\" != \"${LATEST_VERSION:-}\" ]; then");
|
|
228
|
+
lines.push(` TAG_NAME="${module.moduleName}-v\${NEXT_VERSION}"`);
|
|
229
|
+
lines.push(" else");
|
|
230
|
+
lines.push(` echo "Version did not change for ${module.moduleName} on branch $CI_COMMIT_BRANCH, skipping tag"`);
|
|
231
|
+
lines.push(" fi");
|
|
232
|
+
lines.push(" else");
|
|
233
|
+
lines.push(" if [ \"${NEXT_VERSION:-}\" != \"${LATEST_VERSION:-}\" ] || [ \"${NEXT_INCREMENT:-}\" != \"${LATEST_INCREMENT:-}\" ]; then");
|
|
234
|
+
lines.push(` TAG_NAME="${module.moduleName}-v\${NEXT_VERSION}-\${CI_COMMIT_BRANCH}-\${NEXT_INCREMENT}"`);
|
|
235
|
+
lines.push(" else");
|
|
236
|
+
lines.push(` echo "Version/increment did not change for ${module.moduleName} on branch $CI_COMMIT_BRANCH, skipping tag"`);
|
|
237
|
+
lines.push(" fi");
|
|
229
238
|
lines.push(" fi");
|
|
230
|
-
lines.push(
|
|
231
|
-
lines.push(" else");
|
|
232
|
-
lines.push(" if [ \"${NEXT_VERSION:-}\" = \"${LATEST_VERSION:-}\" ] && [ \"${NEXT_INCREMENT:-}\" = \"${LATEST_INCREMENT:-}\" ]; then");
|
|
233
|
-
lines.push(` echo "Version/increment did not change for ${module.moduleName} on branch $CI_COMMIT_BRANCH, skipping tag"`);
|
|
234
|
-
lines.push(" continue");
|
|
235
|
-
lines.push(" fi");
|
|
236
|
-
lines.push(` TAG_NAME="${module.moduleName}-v\${NEXT_VERSION}-\${CI_COMMIT_BRANCH}-\${NEXT_INCREMENT}"`);
|
|
237
|
-
lines.push(" fi");
|
|
239
|
+
lines.push(" if [ \"$TAG_NAME\" != \"\" ]; then");
|
|
238
240
|
if (module.moduleType === "node-express") {
|
|
239
|
-
lines.push(`
|
|
241
|
+
lines.push(` git add "${module.modulePath}/package.json"`);
|
|
240
242
|
}
|
|
241
243
|
else if (module.moduleType === "node-vite") {
|
|
242
|
-
lines.push(`
|
|
244
|
+
lines.push(` git add "${module.modulePath}/package.json" "${module.modulePath}/public/release.json"`);
|
|
243
245
|
}
|
|
244
|
-
lines.push("
|
|
246
|
+
lines.push(" git tag \"$TAG_NAME\"");
|
|
247
|
+
lines.push(" TAG_CREATED=true");
|
|
248
|
+
lines.push(" fi");
|
|
249
|
+
lines.push(" else");
|
|
250
|
+
lines.push(` echo "Missing ${module.modulePath}/semalease.env, skipping ${module.moduleName}"`);
|
|
251
|
+
lines.push(" fi");
|
|
245
252
|
}
|
|
246
253
|
lines.push("");
|
|
247
|
-
lines.push("
|
|
248
|
-
lines.push("
|
|
249
|
-
lines.push("
|
|
254
|
+
lines.push(" if [ \"$TAG_CREATED\" = true ]; then");
|
|
255
|
+
lines.push(" git commit -m \"release: update affected modules\"");
|
|
256
|
+
lines.push(" git push origin HEAD");
|
|
257
|
+
lines.push(" git push origin --tags");
|
|
258
|
+
lines.push(" else");
|
|
259
|
+
lines.push(" echo \"No new tags created; skipping commit/push\"");
|
|
260
|
+
lines.push(" fi");
|
|
250
261
|
lines.push(` artifacts:`);
|
|
251
262
|
lines.push(` paths:`);
|
|
252
263
|
for (const module of modules) {
|
|
@@ -315,7 +326,7 @@ function appendModuleDeployJob(lines, module, branchRule) {
|
|
|
315
326
|
lines.push(" - rm -rf ~/.ssh");
|
|
316
327
|
lines.push("");
|
|
317
328
|
}
|
|
318
|
-
function buildPipeline(modules, branchRule) {
|
|
329
|
+
function buildPipeline(modules, branchRule, mainBranch) {
|
|
319
330
|
const lines = [];
|
|
320
331
|
appendGlobalVariables(lines);
|
|
321
332
|
for (const module of modules) {
|
|
@@ -323,7 +334,7 @@ function buildPipeline(modules, branchRule) {
|
|
|
323
334
|
appendModuleTestJob(lines, module, branchRule);
|
|
324
335
|
appendModuleReleaseJob(lines, module, branchRule);
|
|
325
336
|
}
|
|
326
|
-
appendGlobalReleaseJob(lines, modules);
|
|
337
|
+
appendGlobalReleaseJob(lines, modules, mainBranch);
|
|
327
338
|
for (const module of modules) {
|
|
328
339
|
appendModulePublishJob(lines, module, branchRule);
|
|
329
340
|
appendModuleDeployJob(lines, module, branchRule);
|
|
@@ -331,7 +342,7 @@ function buildPipeline(modules, branchRule) {
|
|
|
331
342
|
return `${lines.join("\n").trimEnd()}\n`;
|
|
332
343
|
}
|
|
333
344
|
function main() {
|
|
334
|
-
const { cwd, output, modulesRoot, branchRule } = parseArgs();
|
|
345
|
+
const { cwd, output, modulesRoot, branchRule, mainBranch } = parseArgs();
|
|
335
346
|
if (!output) {
|
|
336
347
|
log.error("Output path is required. Use [output] or --output <path>.");
|
|
337
348
|
process.exit(1);
|
|
@@ -341,7 +352,7 @@ function main() {
|
|
|
341
352
|
log.error({ cwd, modulesRoot }, "No supported modules were discovered under modules root");
|
|
342
353
|
process.exit(1);
|
|
343
354
|
}
|
|
344
|
-
const pipeline = buildPipeline(modules, branchRule);
|
|
355
|
+
const pipeline = buildPipeline(modules, branchRule, mainBranch);
|
|
345
356
|
const outputPath = path.resolve(cwd, output);
|
|
346
357
|
fs.writeFileSync(outputPath, pipeline, "utf8");
|
|
347
358
|
log.info({ modules: modules.map((m) => m.modulePath), outputPath }, "Generated GitLab pipeline");
|