polyci 0.0.29 → 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.
- package/dist/main.js +65 -69
- package/package.json +1 -1
- 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
|
|
19
|
+
function applyTagTemplate(template, moduleName) {
|
|
20
20
|
return template
|
|
21
21
|
.replaceAll("{module}", moduleName)
|
|
22
|
-
.replaceAll("{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(` -
|
|
189
|
-
lines.push(` -
|
|
190
|
-
lines.push(` -
|
|
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(` - $
|
|
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(` -
|
|
212
|
-
lines.push(` -
|
|
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,23 +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
|
-
lines.push(` -
|
|
233
|
-
lines.push(` -
|
|
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`);
|
|
234
256
|
lines.push(` artifacts:`);
|
|
235
257
|
lines.push(` paths:`);
|
|
236
|
-
lines.push(` - $
|
|
237
|
-
lines.push(` - $
|
|
258
|
+
lines.push(` - ${module.modulePath}/dist`);
|
|
259
|
+
lines.push(` - ${module.modulePath}/polyci.env`);
|
|
238
260
|
lines.push(` expire_in: 1 day`);
|
|
239
261
|
lines.push(``);
|
|
240
262
|
}
|
|
241
|
-
function appendGlobalReleaseJob(lines, modules
|
|
263
|
+
function appendGlobalReleaseJob(lines, modules) {
|
|
242
264
|
lines.push(`release:`);
|
|
243
265
|
lines.push(` stage: release`);
|
|
244
266
|
lines.push(` needs:`);
|
|
@@ -247,46 +269,30 @@ function appendGlobalReleaseJob(lines, modules, mainBranch, versionTemplate, bra
|
|
|
247
269
|
lines.push(` optional: true`);
|
|
248
270
|
}
|
|
249
271
|
lines.push(` image: $IMAGE_NODE`);
|
|
250
|
-
lines.push(` variables:`);
|
|
251
|
-
lines.push(` GITLAB_TOKEN: $POLYCI_TOKEN # Used to push release commits/tags.`);
|
|
252
272
|
lines.push(` script:`);
|
|
253
273
|
lines.push(` - apk update`);
|
|
254
274
|
lines.push(` - apk add $GIT_PACKAGE`);
|
|
255
275
|
lines.push(` - set -euo pipefail`);
|
|
256
276
|
lines.push(` - git config user.email "polyci@anarun.net"`);
|
|
257
277
|
lines.push(` - git config user.name "polyci"`);
|
|
258
|
-
lines.push(` - git remote set-url origin "https://oauth2:\${
|
|
278
|
+
lines.push(` - git remote set-url origin "https://oauth2:\${POLYCI_TOKEN}@\${CI_SERVER_HOST}/\${CI_PROJECT_PATH}.git"`);
|
|
259
279
|
lines.push(` - TAG_NAMES=""`);
|
|
260
280
|
lines.push(``);
|
|
261
281
|
for (const module of modules) {
|
|
262
282
|
lines.push(` - |`);
|
|
263
|
-
lines.push(` if [ -f "${module.modulePath}/
|
|
264
|
-
lines.push(`
|
|
265
|
-
lines.push(`
|
|
266
|
-
lines.push(`
|
|
267
|
-
lines.push(`
|
|
268
|
-
lines.push(` MODULE_VERSION="${applyVersionTemplate(versionTemplate)}"`);
|
|
269
|
-
lines.push(` MODULE_TAG="${applyTagTemplate(tagTemplate, module.moduleName, applyVersionTemplate(versionTemplate))}"`);
|
|
270
|
-
lines.push(` else`);
|
|
271
|
-
lines.push(` echo "Version did not change for ${module.moduleName} on branch $CI_COMMIT_BRANCH, skipping release."`);
|
|
272
|
-
lines.push(` fi`);
|
|
273
|
-
lines.push(` else`);
|
|
274
|
-
lines.push(` if [ "\${NEXT_VERSION:-}" != "\${LATEST_VERSION:-}" ] || [ "\${NEXT_INCREMENT:-}" != "\${LATEST_INCREMENT:-}" ]; then`);
|
|
275
|
-
lines.push(` MODULE_VERSION="${applyVersionTemplate(branchVersionTemplate)}"`);
|
|
276
|
-
lines.push(` MODULE_TAG="${applyTagTemplate(tagTemplate, module.moduleName, applyVersionTemplate(branchVersionTemplate))}"`);
|
|
277
|
-
lines.push(` else`);
|
|
278
|
-
lines.push(` echo "Version/increment did not change for ${module.moduleName} on branch $CI_COMMIT_BRANCH, skipping release."`);
|
|
279
|
-
lines.push(` fi`);
|
|
280
|
-
lines.push(` fi`);
|
|
281
|
-
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`);
|
|
282
288
|
lines.push(` cp -r ci "${module.modulePath}/ci"`);
|
|
289
|
+
lines.push(` ROOT_REPO_DIR="\${pwd}"`);
|
|
283
290
|
lines.push(` cd "${module.modulePath}"`);
|
|
291
|
+
lines.push(` echo "Release ${module.moduleName} version $PLI_MODULE_VERSION."`);
|
|
284
292
|
lines.push(` source "ci/${module.moduleType}/release.sh"`);
|
|
285
|
-
lines.push(` cd
|
|
286
|
-
lines.push(` TAG_NAMES="\${TAG_NAMES} \${
|
|
293
|
+
lines.push(` cd "$ROOT_REPO_DIR"`);
|
|
294
|
+
lines.push(` TAG_NAMES="\${TAG_NAMES} \${PLI_MODULE_TAG}"`);
|
|
287
295
|
lines.push(` fi`);
|
|
288
|
-
lines.push(` else`);
|
|
289
|
-
lines.push(` echo "Missing ${module.modulePath}/semalease.env, skipping ${module.moduleName} release."`);
|
|
290
296
|
lines.push(` fi`);
|
|
291
297
|
}
|
|
292
298
|
lines.push(``);
|
|
@@ -299,13 +305,13 @@ function appendGlobalReleaseJob(lines, modules, mainBranch, versionTemplate, bra
|
|
|
299
305
|
lines.push(` git push origin "HEAD:refs/heads/\${CI_COMMIT_BRANCH:-\${CI_COMMIT_REF_NAME}}"`);
|
|
300
306
|
lines.push(` git push origin --tags`);
|
|
301
307
|
lines.push(` else`);
|
|
302
|
-
lines.push(` echo "No new tags
|
|
308
|
+
lines.push(` echo "No new tags. Skipping commit/push."`);
|
|
303
309
|
lines.push(` fi`);
|
|
304
310
|
lines.push(` artifacts:`);
|
|
305
311
|
lines.push(` paths:`);
|
|
306
312
|
for (const module of modules) {
|
|
307
313
|
lines.push(` - ${module.modulePath}/dist`);
|
|
308
|
-
lines.push(` - ${module.modulePath}/
|
|
314
|
+
lines.push(` - ${module.modulePath}/polyci.env`);
|
|
309
315
|
lines.push(` - ${module.modulePath}/package.json`);
|
|
310
316
|
}
|
|
311
317
|
lines.push(` expire_in: 1 day`);
|
|
@@ -321,20 +327,14 @@ function appendModulePublishJob(lines, module) {
|
|
|
321
327
|
lines.push(` - job: ${module.moduleName}-test`);
|
|
322
328
|
lines.push(` - job: release`);
|
|
323
329
|
lines.push(` image: $IMAGE_DOCKER`);
|
|
324
|
-
lines.push(` variables:`);
|
|
325
|
-
lines.push(` MODULE_NAME: ${module.moduleName}`);
|
|
326
|
-
lines.push(` MODULE_PATH: ${module.modulePath}`);
|
|
327
|
-
lines.push(` MODULE_TYPE: ${module.moduleType}`);
|
|
328
330
|
lines.push(` script:`);
|
|
329
331
|
lines.push(` - cp -r ci "${module.modulePath}/ci"`);
|
|
330
332
|
lines.push(` - cd ${module.modulePath}`);
|
|
331
|
-
lines.push(` -
|
|
332
|
-
lines.push(` - source deploy.env`);
|
|
333
|
+
lines.push(` - source polyci.env`);
|
|
333
334
|
lines.push(` - source "ci/${module.moduleType}/publish.sh"`);
|
|
334
335
|
lines.push(` artifacts:`);
|
|
335
336
|
lines.push(` paths:`);
|
|
336
|
-
lines.push(` - ${module.modulePath}/
|
|
337
|
-
lines.push(` - ${module.modulePath}/package.json`);
|
|
337
|
+
lines.push(` - ${module.modulePath}/polyci.env`);
|
|
338
338
|
lines.push(` expire_in: 1 day`);
|
|
339
339
|
lines.push(``);
|
|
340
340
|
}
|
|
@@ -347,14 +347,10 @@ function appendModuleDeployJob(lines, module) {
|
|
|
347
347
|
lines.push(` needs:`);
|
|
348
348
|
lines.push(` - job: ${module.moduleName}-publish`);
|
|
349
349
|
lines.push(` image: $IMAGE_COMPOSE`);
|
|
350
|
-
lines.push(` variables:`);
|
|
351
|
-
lines.push(` MODULE_NAME: ${module.moduleName}`);
|
|
352
|
-
lines.push(` MODULE_PATH: ${module.modulePath}`);
|
|
353
|
-
lines.push(` MODULE_TYPE: ${module.moduleType}`);
|
|
354
350
|
lines.push(` script:`);
|
|
355
351
|
lines.push(` - cp -r ci "${module.modulePath}/ci"`);
|
|
356
352
|
lines.push(` - cd ${module.modulePath}`);
|
|
357
|
-
lines.push(` - source
|
|
353
|
+
lines.push(` - source polyci.env`);
|
|
358
354
|
lines.push(` - source "ci/${module.moduleType}/deploy.sh"`);
|
|
359
355
|
lines.push(``);
|
|
360
356
|
}
|
|
@@ -364,9 +360,9 @@ function buildPipeline(modules, mainBranch, versionTemplate, branchVersionTempla
|
|
|
364
360
|
for (const module of modules) {
|
|
365
361
|
appendModuleBuildJob(lines, module);
|
|
366
362
|
appendModuleTestJob(lines, module);
|
|
367
|
-
appendModuleReleaseJob(lines, module, tagPattern);
|
|
363
|
+
appendModuleReleaseJob(lines, module, tagPattern, mainBranch, versionTemplate, branchVersionTemplate, tagTemplate);
|
|
368
364
|
}
|
|
369
|
-
appendGlobalReleaseJob(lines, modules
|
|
365
|
+
appendGlobalReleaseJob(lines, modules);
|
|
370
366
|
for (const module of modules) {
|
|
371
367
|
appendModulePublishJob(lines, module);
|
|
372
368
|
appendModuleDeployJob(lines, module);
|
package/package.json
CHANGED
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.
|