polyci 0.0.22 → 0.0.25

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 +19 -45
  2. package/package.json +1 -1
package/dist/main.js CHANGED
@@ -97,13 +97,6 @@ function parseArgs() {
97
97
  function toPosixPath(p) {
98
98
  return p.split(path.sep).join("/");
99
99
  }
100
- function toJobId(value) {
101
- return value
102
- .replace(/[^a-zA-Z0-9_]/g, "_")
103
- .replace(/_+/g, "_")
104
- .replace(/^_+|_+$/g, "")
105
- .toLowerCase();
106
- }
107
100
  function detectModuleType(directory) {
108
101
  const baseName = path.basename(directory);
109
102
  if (baseName === "node_modules" || baseName === ".git" || baseName === "dist") {
@@ -127,7 +120,7 @@ function detectModuleType(directory) {
127
120
  catch (error) {
128
121
  log.warn({ directory, error }, "Unable to read package.json while detecting module type");
129
122
  }
130
- return null;
123
+ return "npm-package";
131
124
  }
132
125
  function discoverModulesRecursively(repoRoot, modulesRoot, scanDir, modules) {
133
126
  const moduleType = detectModuleType(scanDir);
@@ -142,7 +135,6 @@ function discoverModulesRecursively(repoRoot, modulesRoot, scanDir, modules) {
142
135
  moduleName,
143
136
  modulePath: relativeModulePath,
144
137
  moduleType,
145
- jobId: toJobId(relativeModulePath),
146
138
  });
147
139
  return;
148
140
  }
@@ -182,7 +174,7 @@ function appendGlobalVariables(lines) {
182
174
  lines.push(``);
183
175
  }
184
176
  function appendModuleBuildJob(lines, module) {
185
- lines.push(`${module.jobId}_build:`);
177
+ lines.push(`${module.moduleName}-build:`);
186
178
  lines.push(` stage: build`);
187
179
  lines.push(` rules:`);
188
180
  lines.push(` - changes:`);
@@ -203,13 +195,13 @@ function appendModuleBuildJob(lines, module) {
203
195
  lines.push(``);
204
196
  }
205
197
  function appendModuleTestJob(lines, module) {
206
- lines.push(`${module.jobId}_test:`);
198
+ lines.push(`${module.moduleName}-test:`);
207
199
  lines.push(` stage: test`);
208
200
  lines.push(` rules:`);
209
201
  lines.push(` - changes:`);
210
202
  lines.push(` - ${module.modulePath}/**/*`);
211
203
  lines.push(` needs:`);
212
- lines.push(` - job: ${module.jobId}_build`);
204
+ lines.push(` - job: ${module.moduleName}-build`);
213
205
  lines.push(` image: $IMAGE_LINUX`);
214
206
  lines.push(` variables:`);
215
207
  lines.push(` MODULE_NAME: ${module.moduleName}`);
@@ -221,14 +213,14 @@ function appendModuleTestJob(lines, module) {
221
213
  lines.push(``);
222
214
  }
223
215
  function appendModuleReleaseJob(lines, module, tagPattern) {
224
- lines.push(`${module.jobId}_release:`);
216
+ lines.push(`${module.moduleName}-release:`);
225
217
  lines.push(` stage: release`);
226
218
  lines.push(` rules:`);
227
219
  lines.push(` - changes:`);
228
220
  lines.push(` - ${module.modulePath}/**/*`);
229
221
  lines.push(` needs:`);
230
- lines.push(` - job: ${module.jobId}_build`);
231
- lines.push(` - job: ${module.jobId}_test`);
222
+ lines.push(` - job: ${module.moduleName}-build`);
223
+ lines.push(` - job: ${module.moduleName}-test`);
232
224
  lines.push(` image: $IMAGE_NODE`);
233
225
  lines.push(` variables:`);
234
226
  lines.push(` MODULE_NAME: ${module.moduleName}`);
@@ -247,11 +239,11 @@ function appendModuleReleaseJob(lines, module, tagPattern) {
247
239
  lines.push(``);
248
240
  }
249
241
  function appendGlobalReleaseJob(lines, modules, mainBranch, versionTemplate, branchVersionTemplate, tagTemplate) {
250
- lines.push(`release_and_tag:`);
242
+ lines.push(`release:`);
251
243
  lines.push(` stage: release`);
252
244
  lines.push(` needs:`);
253
245
  for (const module of modules) {
254
- lines.push(` - job: ${module.jobId}_release`);
246
+ lines.push(` - job: ${module.moduleName}-release`);
255
247
  lines.push(` optional: true`);
256
248
  }
257
249
  lines.push(` image: $IMAGE_NODE`);
@@ -267,7 +259,6 @@ function appendGlobalReleaseJob(lines, modules, mainBranch, versionTemplate, bra
267
259
  lines.push(` - TAG_NAMES=""`);
268
260
  lines.push(``);
269
261
  for (const module of modules) {
270
- lines.push(` - echo "Tagging release for ${module.moduleName} (${module.modulePath})"`);
271
262
  lines.push(` - |`);
272
263
  lines.push(` if [ -f "${module.modulePath}/semalease.env" ]; then`);
273
264
  lines.push(` . "${module.modulePath}/semalease.env"`);
@@ -291,7 +282,7 @@ function appendGlobalReleaseJob(lines, modules, mainBranch, versionTemplate, bra
291
282
  lines.push(` cp -r ci "${module.modulePath}/ci"`);
292
283
  lines.push(` cd "${module.modulePath}"`);
293
284
  lines.push(` source "ci/${module.moduleType}/release.sh"`);
294
- lines.push(` cd - >/dev/null`);
285
+ lines.push(` cd -`);
295
286
  lines.push(` TAG_NAMES="\${TAG_NAMES} \${MODULE_TAG}"`);
296
287
  lines.push(` fi`);
297
288
  lines.push(` else`);
@@ -315,19 +306,20 @@ function appendGlobalReleaseJob(lines, modules, mainBranch, versionTemplate, bra
315
306
  for (const module of modules) {
316
307
  lines.push(` - ${module.modulePath}/dist`);
317
308
  lines.push(` - ${module.modulePath}/deploy.env`);
309
+ lines.push(` - ${module.modulePath}/package.json`);
318
310
  }
319
311
  lines.push(` expire_in: 1 day`);
320
312
  lines.push(``);
321
313
  }
322
314
  function appendModulePublishJob(lines, module) {
323
- lines.push(`${module.jobId}_publish:`);
315
+ lines.push(`${module.moduleName}-publish:`);
324
316
  lines.push(` stage: publish`);
325
317
  lines.push(` rules:`);
326
318
  lines.push(` - changes:`);
327
319
  lines.push(` - ${module.modulePath}/**/*`);
328
320
  lines.push(` needs:`);
329
- lines.push(` - job: ${module.jobId}_test`);
330
- lines.push(` - job: release_and_tag`);
321
+ lines.push(` - job: ${module.moduleName}-test`);
322
+ lines.push(` - job: release`);
331
323
  lines.push(` image: $IMAGE_DOCKER`);
332
324
  lines.push(` variables:`);
333
325
  lines.push(` MODULE_NAME: ${module.moduleName}`);
@@ -337,23 +329,22 @@ function appendModulePublishJob(lines, module) {
337
329
  lines.push(` - cp ci/$MODULE_TYPE/Dockerfile $MODULE_PATH`);
338
330
  lines.push(` - cd $MODULE_PATH`);
339
331
  lines.push(` - source deploy.env`);
340
- lines.push(` - echo -n $CI_JOB_TOKEN | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY`);
341
- lines.push(` - docker build --tag $CI_REGISTRY_IMAGE/$MODULE_NAME:v$INSTANCE_VERSION .`);
342
- lines.push(` - docker push $CI_REGISTRY_IMAGE/$MODULE_NAME:v$INSTANCE_VERSION`);
332
+ lines.push(` - source "ci/$MODULE_TYPE/publish.sh"`);
343
333
  lines.push(` artifacts:`);
344
334
  lines.push(` paths:`);
345
335
  lines.push(` - $MODULE_PATH/deploy.env`);
336
+ lines.push(` - $MODULE_PATH/package.json`);
346
337
  lines.push(` expire_in: 1 day`);
347
338
  lines.push(``);
348
339
  }
349
340
  function appendModuleDeployJob(lines, module) {
350
- lines.push(`${module.jobId}_deploy:`);
341
+ lines.push(`${module.moduleName}-deploy:`);
351
342
  lines.push(` stage: deploy`);
352
343
  lines.push(` rules:`);
353
344
  lines.push(` - changes:`);
354
345
  lines.push(` - ${module.modulePath}/**/*`);
355
346
  lines.push(` needs:`);
356
- lines.push(` - job: ${module.jobId}_publish`);
347
+ lines.push(` - job: ${module.moduleName}-publish`);
357
348
  lines.push(` image: $IMAGE_COMPOSE`);
358
349
  lines.push(` variables:`);
359
350
  lines.push(` MODULE_NAME: ${module.moduleName}`);
@@ -361,24 +352,7 @@ function appendModuleDeployJob(lines, module) {
361
352
  lines.push(` MODULE_TYPE: ${module.moduleType}`);
362
353
  lines.push(` script:`);
363
354
  lines.push(` - source $MODULE_PATH/deploy.env`);
364
- lines.push(` - export INSTANCE_HOST`);
365
- lines.push(` - export INSTANCE_CONTAINER `);
366
- lines.push(` - export INSTANCE_VERSION`);
367
- lines.push(` - apk add --update --no-cache openssh-client-default`);
368
- lines.push(` - eval $(ssh-agent -s)`);
369
- lines.push(` - echo "$DEPLOY_USER_KEY" | tr -d '\\r' | ssh-add -`);
370
- lines.push(` - mkdir -p ~/.ssh`);
371
- lines.push(` - chmod 700 ~/.ssh`);
372
- lines.push(` - ssh-keyscan -p $DEPLOY_PORT $DEPLOY_ADDRESS >> ~/.ssh/known_hosts`);
373
- lines.push(` - chmod 644 ~/.ssh/known_hosts`);
374
- lines.push(` - echo -n $CI_JOB_TOKEN | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY`);
375
- lines.push(` - docker context create remote --docker "host=ssh://$DEPLOY_USER@$DEPLOY_ADDRESS:$DEPLOY_PORT"`);
376
- lines.push(` - cd ci`);
377
- lines.push(` - export DOCKER_API_VERSION=1.41`);
378
- lines.push(` - docker --context remote compose -p $INSTANCE_CONTAINER down --remove-orphans`);
379
- lines.push(` - docker --context remote compose pull`);
380
- lines.push(` - docker --context remote compose -p $INSTANCE_CONTAINER up -d`);
381
- lines.push(` - rm -rf ~/.ssh`);
355
+ lines.push(` - source "ci/${module.moduleType}/deploy.sh"`);
382
356
  lines.push(``);
383
357
  }
384
358
  function buildPipeline(modules, mainBranch, versionTemplate, branchVersionTemplate, tagTemplate, tagPattern) {
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.22",
4
+ "version": "0.0.25",
5
5
  "type": "module",
6
6
  "private": false,
7
7
  "author": "Alexander Tsarev",