@edifice.io/cli 1.6.0-develop-b2school.10 → 1.6.0-develop-docker.20241120162649
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 +1 -1
- package/src/publish/index.js +84 -101
package/package.json
CHANGED
package/src/publish/index.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
// Originally ported to TS from https://github.com/remix-run/react-router/tree/main/scripts/{version,publish}.js
|
|
3
3
|
|
|
4
4
|
import { parse as parseCommit } from "@commitlint/parse";
|
|
5
|
-
import currentGitBranch from "current-git-branch";
|
|
6
5
|
import { execSync } from "node:child_process";
|
|
7
6
|
import path from "node:path";
|
|
8
7
|
import * as semver from "semver";
|
|
@@ -23,7 +22,9 @@ import {
|
|
|
23
22
|
export const publish = async (options) => {
|
|
24
23
|
const { branchConfigs, packages, rootDir, branch, tag, ghToken } = options;
|
|
25
24
|
|
|
26
|
-
|
|
25
|
+
console.log({ branch, ghToken });
|
|
26
|
+
|
|
27
|
+
const branchName = /** @type {string} */ (branch);
|
|
27
28
|
const isMainBranch = branchName === "main";
|
|
28
29
|
const npmTag = isMainBranch ? "latest" : branchName;
|
|
29
30
|
|
|
@@ -38,51 +39,21 @@ export const publish = async (options) => {
|
|
|
38
39
|
/** @type {string[]} */
|
|
39
40
|
const allTags = execSync("git tag").toString().split("\n");
|
|
40
41
|
|
|
41
|
-
// TODO: Keep this code for now, but it's not used
|
|
42
42
|
const filteredTags = allTags
|
|
43
43
|
// Ensure tag is valid
|
|
44
44
|
.filter((t) => semver.valid(t))
|
|
45
|
-
//
|
|
45
|
+
// Only include non-prerelease tags from main branch
|
|
46
46
|
.filter((t) => {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
// For prerelease branches, only include tags for that branch
|
|
50
|
-
if (branchConfig.prerelease) {
|
|
51
|
-
return isPrereleaseTag && prereleaseBranch === branchName;
|
|
52
|
-
}
|
|
53
|
-
// For main branch, exclude all prereleases
|
|
54
|
-
return !isPrereleaseTag;
|
|
47
|
+
// Exclude any prerelease tags
|
|
48
|
+
return semver.prerelease(t) === null;
|
|
55
49
|
})
|
|
56
50
|
// sort by latest
|
|
57
51
|
// @ts-ignore
|
|
58
52
|
.sort(semver.compare);
|
|
59
53
|
|
|
60
|
-
/* const filteredTags = allTags
|
|
61
|
-
// Ensure tag is valid
|
|
62
|
-
.filter((t) => semver.valid(t))
|
|
63
|
-
// Filter tags based on whether the branch is a release or pre-release
|
|
64
|
-
.filter((t) => {
|
|
65
|
-
const isPrereleaseTag = semver.prerelease(t) !== null;
|
|
66
|
-
return branchConfig.prerelease ? isPrereleaseTag : !isPrereleaseTag;
|
|
67
|
-
})
|
|
68
|
-
// sort by latest
|
|
69
|
-
// @ts-ignore
|
|
70
|
-
.sort(semver.compare); */
|
|
71
|
-
|
|
72
54
|
// Get the latest tag
|
|
73
55
|
let latestTag = filteredTags.at(-1);
|
|
74
56
|
|
|
75
|
-
// TODO: Keep this code for now, but it's not used
|
|
76
|
-
/* if (branchConfig.prerelease) {
|
|
77
|
-
const mainTags = execSync("git tag --merged main").toString().split("\n");
|
|
78
|
-
const validMainTags = mainTags
|
|
79
|
-
.filter((t) => semver.valid(t))
|
|
80
|
-
.sort((a, b) => semver.compare(a, b));
|
|
81
|
-
|
|
82
|
-
latestTag = validMainTags.at(-1) || latestTag; // Use the latest tag from main if available
|
|
83
|
-
} */
|
|
84
|
-
|
|
85
|
-
// console.log({ filteredTags: filteredTags.reverse() });
|
|
86
57
|
let rangeFrom = latestTag;
|
|
87
58
|
|
|
88
59
|
// If RELEASE_ALL is set via a commit subject or body, all packages will be
|
|
@@ -217,7 +188,9 @@ export const publish = async (options) => {
|
|
|
217
188
|
|
|
218
189
|
const version = tag
|
|
219
190
|
? semver.parse(tag)?.version
|
|
220
|
-
:
|
|
191
|
+
: branchConfig.prerelease
|
|
192
|
+
? `${semver.inc(latestTag, releaseType, npmTag, false)}.${Date.now()}`
|
|
193
|
+
: semver.inc(latestTag, releaseType, npmTag);
|
|
221
194
|
|
|
222
195
|
if (!version) {
|
|
223
196
|
throw new Error(
|
|
@@ -288,6 +261,10 @@ export const publish = async (options) => {
|
|
|
288
261
|
const changelogCommitsMd = await Promise.all(
|
|
289
262
|
Object.entries(
|
|
290
263
|
commitsSinceLatestTag.reduce((prev, curr) => {
|
|
264
|
+
// Only include fix, feat, and chore commits
|
|
265
|
+
if (!["docs", "fix", "feat", "chore"].includes(curr.type)) {
|
|
266
|
+
return prev;
|
|
267
|
+
}
|
|
291
268
|
return {
|
|
292
269
|
...prev,
|
|
293
270
|
[curr.type]: [...(prev[curr.type] ?? []), curr],
|
|
@@ -295,20 +272,7 @@ export const publish = async (options) => {
|
|
|
295
272
|
}, /** @type {Record<string, import('./index').Commit[]>} */ ({})),
|
|
296
273
|
)
|
|
297
274
|
.sort(
|
|
298
|
-
getSorterFn(([type]) =>
|
|
299
|
-
[
|
|
300
|
-
"other",
|
|
301
|
-
"examples",
|
|
302
|
-
"docs",
|
|
303
|
-
"ci",
|
|
304
|
-
"test",
|
|
305
|
-
"chore",
|
|
306
|
-
"refactor",
|
|
307
|
-
"perf",
|
|
308
|
-
"fix",
|
|
309
|
-
"feat",
|
|
310
|
-
].indexOf(type),
|
|
311
|
-
),
|
|
275
|
+
getSorterFn(([type]) => ["docs", "chore", "fix", "feat"].indexOf(type)),
|
|
312
276
|
)
|
|
313
277
|
.reverse()
|
|
314
278
|
.map(async ([type, commits]) => {
|
|
@@ -352,7 +316,15 @@ export const publish = async (options) => {
|
|
|
352
316
|
).then((groups) => {
|
|
353
317
|
return groups
|
|
354
318
|
.map(([type, commits]) => {
|
|
355
|
-
|
|
319
|
+
const typeTitle =
|
|
320
|
+
{
|
|
321
|
+
fix: "Bug fixes",
|
|
322
|
+
feat: "Features",
|
|
323
|
+
chore: "Chores",
|
|
324
|
+
docs: "Documentation",
|
|
325
|
+
}[type] || capitalize(type);
|
|
326
|
+
|
|
327
|
+
return [`### ${typeTitle}`, commits.join("\n")].join("\n\n");
|
|
356
328
|
})
|
|
357
329
|
.join("\n\n");
|
|
358
330
|
});
|
|
@@ -400,11 +372,11 @@ export const publish = async (options) => {
|
|
|
400
372
|
);
|
|
401
373
|
}
|
|
402
374
|
|
|
403
|
-
console.info();
|
|
404
|
-
console.info(`Publishing all packages to npm with tag "${npmTag}"`);
|
|
375
|
+
/* console.info();
|
|
376
|
+
console.info(`Publishing all packages to npm with tag "${npmTag}"`); */
|
|
405
377
|
|
|
406
378
|
// Publish each package
|
|
407
|
-
for (const pkg of changedPackages) {
|
|
379
|
+
/* for (const pkg of changedPackages) {
|
|
408
380
|
const packageDir = path.join(rootDir, pkg.packageDir);
|
|
409
381
|
|
|
410
382
|
const cmd = `cd ${packageDir} && pnpm publish --tag ${npmTag} --access=public --no-git-checks`;
|
|
@@ -413,59 +385,70 @@ export const publish = async (options) => {
|
|
|
413
385
|
// @ts-ignore
|
|
414
386
|
stdio: [process.stdin, process.stdout, process.stderr],
|
|
415
387
|
});
|
|
416
|
-
}
|
|
388
|
+
} */
|
|
417
389
|
|
|
418
390
|
console.info();
|
|
419
|
-
console.info("
|
|
420
|
-
/* execSync(
|
|
421
|
-
`git add -A && git reset -- ${changedPackages
|
|
422
|
-
.map((pkg) => path.resolve(rootDir, pkg.packageDir, "package.json"))
|
|
423
|
-
.join(" ")}`,
|
|
424
|
-
); */
|
|
425
|
-
execSync(
|
|
426
|
-
`git reset -- ${changedPackages
|
|
427
|
-
.map((pkg) => path.resolve(rootDir, pkg.packageDir, "package.json"))
|
|
428
|
-
.join(" ")}`,
|
|
429
|
-
);
|
|
430
|
-
execSync(
|
|
431
|
-
`git checkout -- ${changedPackages
|
|
432
|
-
.map((pkg) => path.resolve(rootDir, pkg.packageDir, "package.json"))
|
|
433
|
-
.join(" ")}`,
|
|
434
|
-
);
|
|
435
|
-
// execSync(`git commit -m "${releaseCommitMsg(version)}" --allow-empty -n`);
|
|
436
|
-
console.info(" Reset changes.");
|
|
391
|
+
console.info("Committing changes...");
|
|
437
392
|
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
393
|
+
// Split the git operations into smaller chunks and add maxBuffer option
|
|
394
|
+
try {
|
|
395
|
+
execSync(`git checkout --track origin/${branch}`);
|
|
396
|
+
execSync("git config user.name 'jenkinsEdificePublic'");
|
|
397
|
+
execSync("git config user.email 'sre@edifice.io'");
|
|
442
398
|
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
*/
|
|
446
|
-
console.info();
|
|
447
|
-
console.info(`Creating new git tag v${version}`);
|
|
448
|
-
execSync(`git tag -a -m "v${version}" v${version}`);
|
|
399
|
+
// Add files in smaller batches if needed
|
|
400
|
+
execSync("git add -A", { maxBuffer: 1024 * 1024 * 10 }); // 10MB buffer
|
|
449
401
|
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
402
|
+
// Separate commit command
|
|
403
|
+
execSync(`git commit -m "${releaseCommitMsg(version)}" -n`, {
|
|
404
|
+
maxBuffer: 1024 * 1024 * 10,
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
console.info(" Committed Changes.");
|
|
454
408
|
|
|
455
|
-
if (ghToken && isMainBranch) {
|
|
456
409
|
console.info();
|
|
457
|
-
console.info("
|
|
458
|
-
|
|
459
|
-
// Stringify the markdown to escape any quotes
|
|
460
|
-
execSync(
|
|
461
|
-
`gh release create v${version} ${
|
|
462
|
-
branchConfig.prerelease ? "--prerelease" : ""
|
|
463
|
-
} --notes '${changelogMd.replace(/'/g, '"')}'`,
|
|
464
|
-
{ env: { ...process.env, GH_TOKEN: ghToken } },
|
|
465
|
-
);
|
|
466
|
-
console.info(" Github release created.");
|
|
467
|
-
}
|
|
410
|
+
console.info("Pushing changes...");
|
|
468
411
|
|
|
469
|
-
|
|
470
|
-
|
|
412
|
+
// Push with increased buffer
|
|
413
|
+
execSync(`git push`, {
|
|
414
|
+
maxBuffer: 1024 * 1024 * 10,
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
console.info(" Changes pushed.");
|
|
418
|
+
|
|
419
|
+
console.info();
|
|
420
|
+
console.info(`Creating new git tag v${version}`);
|
|
421
|
+
/**
|
|
422
|
+
* Create a new git tag for the release.
|
|
423
|
+
*/
|
|
424
|
+
execSync(`git tag -a -m "v${version}" v${version}`);
|
|
425
|
+
|
|
426
|
+
console.info();
|
|
427
|
+
console.info("Pushing tags...");
|
|
428
|
+
/**
|
|
429
|
+
* Push the tags to the main branch.
|
|
430
|
+
*/
|
|
431
|
+
execSync("git push --tags");
|
|
432
|
+
console.info(" Tags pushed.");
|
|
433
|
+
|
|
434
|
+
if (ghToken && isMainBranch) {
|
|
435
|
+
console.info();
|
|
436
|
+
console.info("Creating github release...");
|
|
437
|
+
|
|
438
|
+
// Stringify the markdown to escape any quotes
|
|
439
|
+
execSync(
|
|
440
|
+
`gh release create v${version} ${
|
|
441
|
+
branchConfig.prerelease ? "--prerelease" : ""
|
|
442
|
+
} --notes '${changelogMd.replace(/'/g, '"')}'`,
|
|
443
|
+
{ env: { ...process.env, GH_TOKEN: ghToken } },
|
|
444
|
+
);
|
|
445
|
+
console.info(" Github release created.");
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
console.info();
|
|
449
|
+
console.info("All done!");
|
|
450
|
+
} catch (error) {
|
|
451
|
+
console.error("Error during git operations:", error);
|
|
452
|
+
throw error;
|
|
453
|
+
}
|
|
471
454
|
};
|