@jakubmazanec/carson-templates 2.0.0-next.1b2cc9c → 2.0.0-next.439463c

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jakubmazanec/carson-templates",
3
- "version": "2.0.0-next.1b2cc9c",
3
+ "version": "2.0.0-next.439463c",
4
4
  "description": "Collection of Carson templates.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -34,7 +34,7 @@
34
34
  "semver": "^7.3.6"
35
35
  },
36
36
  "devDependencies": {
37
- "@jakubmazanec/carson": "0.3.0-next.1b2cc9c",
37
+ "@jakubmazanec/carson": "0.3.0-next.439463c",
38
38
  "@jakubmazanec/fs-utils": "^0.1.0",
39
39
  "@jest/globals": "^29.5.0",
40
40
  "@types/fs-extra": "^9.0.13",
@@ -45,7 +45,7 @@
45
45
  "zen-observable": "^0.10.0"
46
46
  },
47
47
  "peerDependencies": {
48
- "@jakubmazanec/carson": "0.3.0-next.1b2cc9c"
48
+ "@jakubmazanec/carson": "0.3.0-next.439463c"
49
49
  },
50
50
  "packageManager": "npm@8.19.4",
51
51
  "engines": {
@@ -228,7 +228,7 @@ jobs:
228
228
  name: Feature branch release
229
229
  runs-on: ubuntu-latest
230
230
  timeout-minutes: 15
231
- if: "github.ref_name != '<%- getMainBranch(workspace) %>' && github.ref_name != '<%- getDevelopmentBranch(workspace) %>'"
231
+ if: "github.ref_name != '<%- getMainBranch(workspace) %>' && github.ref_name != '<%- getDevelopmentBranch(workspace) %>' && github.actor != 'renovate[bot]'"
232
232
  steps:
233
233
  - name: Cancel previous runs
234
234
  uses: styfle/cancel-workflow-action@0.11.0
@@ -306,3 +306,202 @@ jobs:
306
306
  env:
307
307
  NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
308
308
  NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
309
+
310
+ renovate_bot_release:
311
+ name: Renovate bot release
312
+ runs-on: ubuntu-latest
313
+ timeout-minutes: 15
314
+ if: "github.ref_name != '<%- getMainBranch(workspace) %>' && github.ref_name != '<%- getDevelopmentBranch(workspace) %>' && github.actor == 'renovate[bot]'"
315
+ steps:
316
+ - name: Cancel previous runs
317
+ uses: styfle/cancel-workflow-action@0.11.0
318
+ with:
319
+ access_token: ${{ secrets.GITHUB_TOKEN }}
320
+
321
+ - uses: actions/checkout@v3
322
+ with:
323
+ token: ${{ secrets.GITHUB_TOKEN }}
324
+ fetch-depth: 0
325
+
326
+ - name: Configure git
327
+ run: |
328
+ git config user.email "bot@mazanec.dev"
329
+ git config user.name "Bot"
330
+
331
+ - uses: actions/setup-node@v3
332
+ with:
333
+ node-version: 16
334
+ registry-url: 'https://registry.npmjs.org'
335
+
336
+ - name: Install packages
337
+ run: npm ci
338
+
339
+ - name: Check for changes
340
+ run: |
341
+ git config core.filemode false
342
+ git_status=$(git status --porcelain)
343
+
344
+ if [[ -n $git_status ]]; then
345
+ echo "You have uncommitted changes!"
346
+ git status --porcelain
347
+ git config --unset core.filemode
348
+ exit 1
349
+ fi
350
+
351
+ git config --unset core.filemode
352
+
353
+ - name: Run tests
354
+ run: npm test
355
+
356
+ - name: Check for changes
357
+ run: |
358
+ git config core.filemode false
359
+ git_status=$(git status --porcelain)
360
+
361
+ if [[ -n $git_status ]]; then
362
+ echo "You have uncommitted changes!"
363
+ git status --porcelain
364
+ git config --unset core.filemode
365
+ exit 1
366
+ fi
367
+
368
+ git config --unset core.filemode
369
+
370
+ - name: Build packages
371
+ run: npm run build
372
+
373
+ - name: Generate changeset
374
+ uses: actions/github-script@v6
375
+ with:
376
+ script: |
377
+ let { promises: fs } = require('fs');
378
+
379
+ async function getPackagesNames(files) {
380
+ let names = [];
381
+
382
+ for (let file of files) {
383
+ let data = JSON.parse(await fs.readFile(file, 'utf8'));
384
+
385
+ if (!data.private) {
386
+ names.push(data.name);
387
+ }
388
+ }
389
+
390
+ return names;
391
+ }
392
+
393
+ async function createChangeset(fileName, packageBumps, packages) {
394
+ let message = '';
395
+
396
+ for (let [packageName, bump] of packageBumps) {
397
+ message =
398
+ message + `Dependency \`${packageName}\` updated to \`${bump}\`.\n`;
399
+ }
400
+
401
+ let header = packages
402
+ .map((packageName) => `'${packageName}': patch`)
403
+ .join('\n');
404
+
405
+ await fs.writeFile(fileName, `---\n${header}\n---\n${message.trim()}\n`);
406
+ }
407
+
408
+ async function getBumps(files) {
409
+ let bumps = new Map();
410
+
411
+ for (let file of files) {
412
+ let { stdout: changes } = await exec.getExecOutput('git', ['show', file]);
413
+
414
+ for (let change of changes.split('\n')) {
415
+ if (!change.startsWith('+ ')) {
416
+ continue;
417
+ }
418
+
419
+ let match = change.match(/"(.*?)"/g);
420
+
421
+ bumps.set(match[0].replace(/"/g, ''), match[1].replace(/"/g, ''));
422
+ }
423
+ }
424
+
425
+ return bumps;
426
+ }
427
+
428
+ let branch = await exec.getExecOutput('git branch --show-current');
429
+
430
+ if (!branch.stdout.startsWith('renovate/')) {
431
+ console.log('Not a renovate branch, skipping...');
432
+
433
+ return;
434
+ }
435
+
436
+ let diffOutput = await exec.getExecOutput('git diff --name-only HEAD~1');
437
+ let diffFiles = diffOutput.stdout.split('\n');
438
+
439
+ if (diffFiles.find((diffFile) => diffFile.startsWith('.changeset'))) {
440
+ console.log('Changeset already exists, skipping...');
441
+
442
+ return;
443
+ }
444
+
445
+ let files = diffFiles
446
+ .filter((file) => file !== 'package.json') // skip root package.json
447
+ .filter((file) => file.includes('package.json'));
448
+ let packageNames = await getPackagesNames(files);
449
+
450
+ if (!packageNames.length) {
451
+ console.log('No package.json changes to published packages, skipping...');
452
+
453
+ await exec.exec('npx', ['changeset', '--empty']);
454
+ await exec.exec('git', ['add', '.', '--all']);
455
+ await exec.exec('git commit -C HEAD --amend --no-edit');
456
+ await exec.exec('git push --force');
457
+
458
+ return;
459
+ }
460
+
461
+ let { stdout: shortHash } = await exec.getExecOutput(
462
+ 'git rev-parse --short HEAD',
463
+ );
464
+ let fileName = `.changeset/renovate-${shortHash.trim()}.md`;
465
+ let packageBumps = await getBumps(files);
466
+
467
+ await createChangeset(fileName, packageBumps, packageNames);
468
+ await exec.exec('git', ['add', '.', '--all']);
469
+ await exec.exec('git commit -C HEAD --amend --no-edit');
470
+ await exec.exec('git push --force');
471
+
472
+ - name: Update Carson
473
+ uses: actions/github-script@v6
474
+ with:
475
+ script: |
476
+ let branch = await exec.getExecOutput('git branch --show-current');
477
+
478
+ if (!branch.stdout.startsWith('renovate/')) {
479
+ console.log('Not a renovate branch, skipping...');
480
+
481
+ return;
482
+ }
483
+
484
+ await exec.exec('npm', ['install']);
485
+ await exec.exec('git', ['add', '.', '--all']);
486
+ await exec.exec('git commit -m"Run Carson update [skip actions]"');
487
+ await exec.exec('git push --force');
488
+
489
+ - name: Authenticate to npm registry
490
+ run: |
491
+ echo "//registry.npmjs.com/:_authToken=NPM_TOKEN" > .npmrc
492
+ env:
493
+ NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
494
+
495
+ - name: Version packages
496
+ run: |
497
+ npx changeset version --snapshot unstable --snapshot-prerelease-template "{tag}.{commit}"
498
+ git status
499
+ env:
500
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
501
+
502
+ - name: Publish packages
503
+ run: |
504
+ npx changeset publish --tag unstable --no-git-tag
505
+ env:
506
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
507
+ NPM_TOKEN: ${{ secrets.NPM_TOKEN }}