polyci 0.0.5 → 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.
Files changed (2) hide show
  1. package/dist/main.js +18 -10
  2. 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
- return { cwd, output, modulesRoot, branchRule };
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,13 +216,14 @@ 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
223
  lines.push(` if [ -f "${module.modulePath}/semalease.env" ]; then`);
221
224
  lines.push(` . "${module.modulePath}/semalease.env"`);
222
225
  lines.push(" TAG_NAME=\"\"");
223
- lines.push(" if [ \"$CI_COMMIT_BRANCH\" = \"main\" ]; then");
226
+ lines.push(` if [ "$CI_COMMIT_BRANCH" = "${mainBranch}" ]; then`);
224
227
  lines.push(" if [ \"${NEXT_VERSION:-}\" != \"${LATEST_VERSION:-}\" ]; then");
225
228
  lines.push(` TAG_NAME="${module.moduleName}-v\${NEXT_VERSION}"`);
226
229
  lines.push(" else");
@@ -241,15 +244,20 @@ function appendGlobalReleaseJob(lines, modules) {
241
244
  lines.push(` git add "${module.modulePath}/package.json" "${module.modulePath}/public/release.json"`);
242
245
  }
243
246
  lines.push(" git tag \"$TAG_NAME\"");
247
+ lines.push(" TAG_CREATED=true");
244
248
  lines.push(" fi");
245
249
  lines.push(" else");
246
250
  lines.push(` echo "Missing ${module.modulePath}/semalease.env, skipping ${module.moduleName}"`);
247
251
  lines.push(" fi");
248
252
  }
249
253
  lines.push("");
250
- lines.push(" git commit -m \"release: update affected modules\"");
251
- lines.push(" git push origin HEAD");
252
- lines.push(" git push origin --tags");
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");
253
261
  lines.push(` artifacts:`);
254
262
  lines.push(` paths:`);
255
263
  for (const module of modules) {
@@ -318,7 +326,7 @@ function appendModuleDeployJob(lines, module, branchRule) {
318
326
  lines.push(" - rm -rf ~/.ssh");
319
327
  lines.push("");
320
328
  }
321
- function buildPipeline(modules, branchRule) {
329
+ function buildPipeline(modules, branchRule, mainBranch) {
322
330
  const lines = [];
323
331
  appendGlobalVariables(lines);
324
332
  for (const module of modules) {
@@ -326,7 +334,7 @@ function buildPipeline(modules, branchRule) {
326
334
  appendModuleTestJob(lines, module, branchRule);
327
335
  appendModuleReleaseJob(lines, module, branchRule);
328
336
  }
329
- appendGlobalReleaseJob(lines, modules);
337
+ appendGlobalReleaseJob(lines, modules, mainBranch);
330
338
  for (const module of modules) {
331
339
  appendModulePublishJob(lines, module, branchRule);
332
340
  appendModuleDeployJob(lines, module, branchRule);
@@ -334,7 +342,7 @@ function buildPipeline(modules, branchRule) {
334
342
  return `${lines.join("\n").trimEnd()}\n`;
335
343
  }
336
344
  function main() {
337
- const { cwd, output, modulesRoot, branchRule } = parseArgs();
345
+ const { cwd, output, modulesRoot, branchRule, mainBranch } = parseArgs();
338
346
  if (!output) {
339
347
  log.error("Output path is required. Use [output] or --output <path>.");
340
348
  process.exit(1);
@@ -344,7 +352,7 @@ function main() {
344
352
  log.error({ cwd, modulesRoot }, "No supported modules were discovered under modules root");
345
353
  process.exit(1);
346
354
  }
347
- const pipeline = buildPipeline(modules, branchRule);
355
+ const pipeline = buildPipeline(modules, branchRule, mainBranch);
348
356
  const outputPath = path.resolve(cwd, output);
349
357
  fs.writeFileSync(outputPath, pipeline, "utf8");
350
358
  log.info({ modules: modules.map((m) => m.modulePath), outputPath }, "Generated GitLab pipeline");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "polyci",
3
3
  "description": "Monorepo CI/CD utilities.",
4
- "version": "0.0.5",
4
+ "version": "0.0.6",
5
5
  "type": "module",
6
6
  "private": false,
7
7
  "author": "Alexander Tsarev",