polyci 0.0.30 → 0.0.31

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 (3) hide show
  1. package/dist/main.js +64 -67
  2. package/package.json +1 -1
  3. package/readme.md +12 -0
package/dist/main.js CHANGED
@@ -16,10 +16,10 @@ function applyVersionTemplate(template) {
16
16
  .replaceAll("{version}", "${NEXT_VERSION}")
17
17
  .replaceAll("{increment}", "${NEXT_INCREMENT}");
18
18
  }
19
- function applyTagTemplate(template, moduleName, version) {
19
+ function applyTagTemplate(template, moduleName) {
20
20
  return template
21
21
  .replaceAll("{module}", moduleName)
22
- .replaceAll("{version}", version);
22
+ .replaceAll("{version}", "${PLI_MODULE_VERSION}");
23
23
  }
24
24
  function getInvalidTagTemplatePlaceholders(template) {
25
25
  const matches = template.matchAll(/\{([^}]+)\}/g);
@@ -180,17 +180,18 @@ function appendModuleBuildJob(lines, module) {
180
180
  lines.push(` - changes:`);
181
181
  lines.push(` - ${module.modulePath}/**/*`);
182
182
  lines.push(` image: $IMAGE_NODE`);
183
- lines.push(` variables:`);
184
- lines.push(` MODULE_NAME: ${module.moduleName}`);
185
- lines.push(` MODULE_PATH: ${module.modulePath}`);
186
- lines.push(` MODULE_TYPE: ${module.moduleType}`);
187
183
  lines.push(` script:`);
188
- lines.push(` - cd $MODULE_PATH`);
189
- lines.push(` - npm ci`);
190
- lines.push(` - npm run build`);
184
+ lines.push(` - cp -r ci "${module.modulePath}/ci"`);
185
+ lines.push(` - cd ${module.modulePath}`);
186
+ lines.push(` - echo "PLI_MODULE_NAME=${module.moduleName}" > polyci.env`);
187
+ lines.push(` - echo "PLI_MODULE_PATH=${module.modulePath}" >> polyci.env`);
188
+ lines.push(` - echo "PLI_MODULE_TYPE=${module.moduleType}" >> polyci.env`);
189
+ lines.push(` - source polyci.env`);
190
+ lines.push(` - source "ci/${module.moduleType}/build.sh"`);
191
191
  lines.push(` artifacts:`);
192
192
  lines.push(` paths:`);
193
- lines.push(` - $MODULE_PATH/dist/`);
193
+ lines.push(` - ${module.modulePath}/dist`);
194
+ lines.push(` - ${module.modulePath}/policy.env`);
194
195
  lines.push(` expire_in: 1 day`);
195
196
  lines.push(``);
196
197
  }
@@ -203,16 +204,18 @@ function appendModuleTestJob(lines, module) {
203
204
  lines.push(` needs:`);
204
205
  lines.push(` - job: ${module.moduleName}-build`);
205
206
  lines.push(` image: $IMAGE_LINUX`);
206
- lines.push(` variables:`);
207
- lines.push(` MODULE_NAME: ${module.moduleName}`);
208
- lines.push(` MODULE_PATH: ${module.modulePath}`);
209
- lines.push(` MODULE_TYPE: ${module.moduleType}`);
210
207
  lines.push(` script:`);
211
- lines.push(` - cd $MODULE_PATH`);
212
- lines.push(` - echo "test is tasty"`);
208
+ lines.push(` - cp -r ci "${module.modulePath}/ci"`);
209
+ lines.push(` - cd ${module.modulePath}`);
210
+ lines.push(` - source polyci.env`);
211
+ lines.push(` - source "ci/${module.moduleType}/test.sh"`);
212
+ lines.push(` artifacts:`);
213
+ lines.push(` paths:`);
214
+ lines.push(` - ${module.modulePath}/dist`);
215
+ lines.push(` - ${module.modulePath}/policy.env`);
213
216
  lines.push(``);
214
217
  }
215
- function appendModuleReleaseJob(lines, module, tagPattern) {
218
+ function appendModuleReleaseJob(lines, module, tagPattern, mainBranch, versionTemplate, branchVersionTemplate, tagTemplate) {
216
219
  lines.push(`${module.moduleName}-release:`);
217
220
  lines.push(` stage: release`);
218
221
  lines.push(` rules:`);
@@ -222,22 +225,42 @@ function appendModuleReleaseJob(lines, module, tagPattern) {
222
225
  lines.push(` - job: ${module.moduleName}-build`);
223
226
  lines.push(` - job: ${module.moduleName}-test`);
224
227
  lines.push(` image: $IMAGE_NODE`);
225
- lines.push(` variables:`);
226
- lines.push(` MODULE_NAME: ${module.moduleName}`);
227
- lines.push(` MODULE_PATH: ${module.modulePath}`);
228
- lines.push(` MODULE_TYPE: ${module.moduleType}`);
229
228
  lines.push(` script:`);
230
229
  lines.push(` - apk update`);
231
230
  lines.push(` - apk add $GIT_PACKAGE`);
232
231
  lines.push(` - npx semalease --cwd "${module.modulePath}" --tag-pattern "${tagPattern}" ${module.modulePath}/semalease.env`);
232
+ lines.push(` - |`);
233
+ lines.push(` if [ -f "${module.modulePath}/semalease.env" ]; then`);
234
+ lines.push(` source "${module.modulePath}/semalease.env"`);
235
+ lines.push(` if [ "$CI_COMMIT_BRANCH" = "${mainBranch}" ]; then`);
236
+ lines.push(` if [ "\${NEXT_VERSION:-}" != "\${LATEST_VERSION:-}" ]; then`);
237
+ lines.push(` PLI_MODULE_VERSION="${applyVersionTemplate(versionTemplate)}"`);
238
+ lines.push(` PLI_MODULE_TAG="${applyTagTemplate(tagTemplate, module.moduleName)}"`);
239
+ lines.push(` else`);
240
+ lines.push(` echo "Version did not change for ${module.moduleName} on branch $CI_COMMIT_BRANCH, skipping release."`);
241
+ lines.push(` fi`);
242
+ lines.push(` else`);
243
+ lines.push(` if [ "\${NEXT_VERSION:-}" != "\${LATEST_VERSION:-}" ] || [ "\${NEXT_INCREMENT:-}" != "\${LATEST_INCREMENT:-}" ]; then`);
244
+ lines.push(` PLI_MODULE_VERSION="${applyVersionTemplate(branchVersionTemplate)}"`);
245
+ lines.push(` PLI_MODULE_TAG="${applyTagTemplate(tagTemplate, module.moduleName)}"`);
246
+ lines.push(` else`);
247
+ lines.push(` echo "Version/increment did not change for ${module.moduleName} on branch $CI_COMMIT_BRANCH, skipping release."`);
248
+ lines.push(` fi`);
249
+ lines.push(` fi`);
250
+ lines.push(` fi`);
251
+ lines.push(` - |`);
252
+ lines.push(` if [ -n "$PLI_MODULE_VERSION" && -n "$PLI_MODULE_TAG" ]; then`);
253
+ lines.push(` echo "PLI_MODULE_VERSION=$PLI_MODULE_VERSION" >> ${module.modulePath}/polyci.env`);
254
+ lines.push(` echo "PLI_MODULE_TAG=$PLI_MODULE_TAG" >> ${module.modulePath}/polyci.env`);
255
+ lines.push(` fi`);
233
256
  lines.push(` artifacts:`);
234
257
  lines.push(` paths:`);
235
- lines.push(` - $MODULE_PATH/dist`);
236
- lines.push(` - $MODULE_PATH/semalease.env`);
258
+ lines.push(` - ${module.modulePath}/dist`);
259
+ lines.push(` - ${module.modulePath}/polyci.env`);
237
260
  lines.push(` expire_in: 1 day`);
238
261
  lines.push(``);
239
262
  }
240
- function appendGlobalReleaseJob(lines, modules, mainBranch, versionTemplate, branchVersionTemplate, tagTemplate) {
263
+ function appendGlobalReleaseJob(lines, modules) {
241
264
  lines.push(`release:`);
242
265
  lines.push(` stage: release`);
243
266
  lines.push(` needs:`);
@@ -246,46 +269,30 @@ function appendGlobalReleaseJob(lines, modules, mainBranch, versionTemplate, bra
246
269
  lines.push(` optional: true`);
247
270
  }
248
271
  lines.push(` image: $IMAGE_NODE`);
249
- lines.push(` variables:`);
250
- lines.push(` GITLAB_TOKEN: $POLYCI_TOKEN # Used to push release commits/tags.`);
251
272
  lines.push(` script:`);
252
273
  lines.push(` - apk update`);
253
274
  lines.push(` - apk add $GIT_PACKAGE`);
254
275
  lines.push(` - set -euo pipefail`);
255
276
  lines.push(` - git config user.email "polyci@anarun.net"`);
256
277
  lines.push(` - git config user.name "polyci"`);
257
- lines.push(` - git remote set-url origin "https://oauth2:\${GITLAB_TOKEN}@\${CI_SERVER_HOST}/\${CI_PROJECT_PATH}.git"`);
278
+ lines.push(` - git remote set-url origin "https://oauth2:\${POLYCI_TOKEN}@\${CI_SERVER_HOST}/\${CI_PROJECT_PATH}.git"`);
258
279
  lines.push(` - TAG_NAMES=""`);
259
280
  lines.push(``);
260
281
  for (const module of modules) {
261
282
  lines.push(` - |`);
262
- lines.push(` if [ -f "${module.modulePath}/semalease.env" ]; then`);
263
- lines.push(` . "${module.modulePath}/semalease.env"`);
264
- lines.push(` MODULE_TAG=""`);
265
- lines.push(` if [ "$CI_COMMIT_BRANCH" = "${mainBranch}" ]; then`);
266
- lines.push(` if [ "\${NEXT_VERSION:-}" != "\${LATEST_VERSION:-}" ]; then`);
267
- lines.push(` MODULE_VERSION="${applyVersionTemplate(versionTemplate)}"`);
268
- lines.push(` MODULE_TAG="${applyTagTemplate(tagTemplate, module.moduleName, applyVersionTemplate(versionTemplate))}"`);
269
- lines.push(` else`);
270
- lines.push(` echo "Version did not change for ${module.moduleName} on branch $CI_COMMIT_BRANCH, skipping release."`);
271
- lines.push(` fi`);
272
- lines.push(` else`);
273
- lines.push(` if [ "\${NEXT_VERSION:-}" != "\${LATEST_VERSION:-}" ] || [ "\${NEXT_INCREMENT:-}" != "\${LATEST_INCREMENT:-}" ]; then`);
274
- lines.push(` MODULE_VERSION="${applyVersionTemplate(branchVersionTemplate)}"`);
275
- lines.push(` MODULE_TAG="${applyTagTemplate(tagTemplate, module.moduleName, applyVersionTemplate(branchVersionTemplate))}"`);
276
- lines.push(` else`);
277
- lines.push(` echo "Version/increment did not change for ${module.moduleName} on branch $CI_COMMIT_BRANCH, skipping release."`);
278
- lines.push(` fi`);
279
- lines.push(` fi`);
280
- lines.push(` if [ "$MODULE_TAG" != "" ]; then`);
283
+ lines.push(` if [ -f "${module.modulePath}/polyci.env" ]; then`);
284
+ lines.push(` unset PLI_MODULE_NAME`);
285
+ lines.push(` unset PLI_MODULE_TAG`);
286
+ lines.push(` source "${module.modulePath}/polyci.env"`);
287
+ lines.push(` if [ -n "$PLI_MODULE_NAME" && -n "$PLI_MODULE_TAG" ]; then`);
281
288
  lines.push(` cp -r ci "${module.modulePath}/ci"`);
289
+ lines.push(` ROOT_REPO_DIR="\${pwd}"`);
282
290
  lines.push(` cd "${module.modulePath}"`);
291
+ lines.push(` echo "Release ${module.moduleName} version $PLI_MODULE_VERSION."`);
283
292
  lines.push(` source "ci/${module.moduleType}/release.sh"`);
284
- lines.push(` cd -`);
285
- lines.push(` TAG_NAMES="\${TAG_NAMES} \${MODULE_TAG}"`);
293
+ lines.push(` cd "$ROOT_REPO_DIR"`);
294
+ lines.push(` TAG_NAMES="\${TAG_NAMES} \${PLI_MODULE_TAG}"`);
286
295
  lines.push(` fi`);
287
- lines.push(` else`);
288
- lines.push(` echo "Missing ${module.modulePath}/semalease.env, skipping ${module.moduleName} release."`);
289
296
  lines.push(` fi`);
290
297
  }
291
298
  lines.push(``);
@@ -298,13 +305,13 @@ function appendGlobalReleaseJob(lines, modules, mainBranch, versionTemplate, bra
298
305
  lines.push(` git push origin "HEAD:refs/heads/\${CI_COMMIT_BRANCH:-\${CI_COMMIT_REF_NAME}}"`);
299
306
  lines.push(` git push origin --tags`);
300
307
  lines.push(` else`);
301
- lines.push(` echo "No new tags created; skipping commit/push"`);
308
+ lines.push(` echo "No new tags. Skipping commit/push."`);
302
309
  lines.push(` fi`);
303
310
  lines.push(` artifacts:`);
304
311
  lines.push(` paths:`);
305
312
  for (const module of modules) {
306
313
  lines.push(` - ${module.modulePath}/dist`);
307
- lines.push(` - ${module.modulePath}/deploy.env`);
314
+ lines.push(` - ${module.modulePath}/polyci.env`);
308
315
  lines.push(` - ${module.modulePath}/package.json`);
309
316
  }
310
317
  lines.push(` expire_in: 1 day`);
@@ -320,20 +327,14 @@ function appendModulePublishJob(lines, module) {
320
327
  lines.push(` - job: ${module.moduleName}-test`);
321
328
  lines.push(` - job: release`);
322
329
  lines.push(` image: $IMAGE_DOCKER`);
323
- lines.push(` variables:`);
324
- lines.push(` MODULE_NAME: ${module.moduleName}`);
325
- lines.push(` MODULE_PATH: ${module.modulePath}`);
326
- lines.push(` MODULE_TYPE: ${module.moduleType}`);
327
330
  lines.push(` script:`);
328
331
  lines.push(` - cp -r ci "${module.modulePath}/ci"`);
329
332
  lines.push(` - cd ${module.modulePath}`);
330
- lines.push(` - test -f deploy.env || touch deploy.env`);
331
- lines.push(` - source deploy.env`);
333
+ lines.push(` - source polyci.env`);
332
334
  lines.push(` - source "ci/${module.moduleType}/publish.sh"`);
333
335
  lines.push(` artifacts:`);
334
336
  lines.push(` paths:`);
335
- lines.push(` - ${module.modulePath}/deploy.env`);
336
- lines.push(` - ${module.modulePath}/package.json`);
337
+ lines.push(` - ${module.modulePath}/polyci.env`);
337
338
  lines.push(` expire_in: 1 day`);
338
339
  lines.push(``);
339
340
  }
@@ -346,14 +347,10 @@ function appendModuleDeployJob(lines, module) {
346
347
  lines.push(` needs:`);
347
348
  lines.push(` - job: ${module.moduleName}-publish`);
348
349
  lines.push(` image: $IMAGE_COMPOSE`);
349
- lines.push(` variables:`);
350
- lines.push(` MODULE_NAME: ${module.moduleName}`);
351
- lines.push(` MODULE_PATH: ${module.modulePath}`);
352
- lines.push(` MODULE_TYPE: ${module.moduleType}`);
353
350
  lines.push(` script:`);
354
351
  lines.push(` - cp -r ci "${module.modulePath}/ci"`);
355
352
  lines.push(` - cd ${module.modulePath}`);
356
- lines.push(` - source deploy.env`);
353
+ lines.push(` - source polyci.env`);
357
354
  lines.push(` - source "ci/${module.moduleType}/deploy.sh"`);
358
355
  lines.push(``);
359
356
  }
@@ -363,9 +360,9 @@ function buildPipeline(modules, mainBranch, versionTemplate, branchVersionTempla
363
360
  for (const module of modules) {
364
361
  appendModuleBuildJob(lines, module);
365
362
  appendModuleTestJob(lines, module);
366
- appendModuleReleaseJob(lines, module, tagPattern);
363
+ appendModuleReleaseJob(lines, module, tagPattern, mainBranch, versionTemplate, branchVersionTemplate, tagTemplate);
367
364
  }
368
- appendGlobalReleaseJob(lines, modules, mainBranch, versionTemplate, branchVersionTemplate, tagTemplate);
365
+ appendGlobalReleaseJob(lines, modules);
369
366
  for (const module of modules) {
370
367
  appendModulePublishJob(lines, module);
371
368
  appendModuleDeployJob(lines, module);
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.30",
4
+ "version": "0.0.31",
5
5
  "type": "module",
6
6
  "private": false,
7
7
  "author": "Alexander Tsarev",
package/readme.md CHANGED
@@ -0,0 +1,12 @@
1
+ installation
2
+
3
+ usage
4
+
5
+ recommedations
6
+ do not change the provided module types and scripts. instead, copy and customise your own type.
7
+
8
+ requirements
9
+ POLYCI_TOKEN variable must be defined in GitLab and accessible in the jobs that match the rule in the root .gitlab-ci.yml.
10
+ each module must have build script to be called via "npm run build".
11
+ each module must put the build result into ./dist folder.
12
+ docker service deploy needs docker host server with traefik 3.