Skip to content

Commit 601a164

Browse files
authored
Merge pull request tsparticles#5661 from tsparticles/v4
4.0.0-beta.8
2 parents 4781874 + 0cd950d commit 601a164

2 files changed

Lines changed: 58 additions & 7 deletions

File tree

.github/workflows/npm-publish.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ concurrency:
1616
env:
1717
NX_CLOUD_DISTRIBUTED_EXECUTION: true
1818
NX_CLOUD_ACCESS_TOKEN: '${{ secrets.NX_CLOUD_ACCESS_TOKEN }}'
19+
ZIP_CONCURRENCY: 5
1920
IS_STABLE: ${{ !contains(github.ref, '-alpha.') && !contains(github.ref, '-beta.') }}
2021

2122
jobs:
@@ -39,9 +40,6 @@ jobs:
3940
with:
4041
run_install: false
4142

42-
- name: Initialize Nx Cloud
43-
run: pnpm nx-cloud start-ci-run --distribute-on="5 linux-medium-js"
44-
4543
- name: Get pnpm store directory
4644
id: pnpm-cache
4745
run: echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT
@@ -57,6 +55,9 @@ jobs:
5755
- name: Install Dependencies
5856
run: pnpm install
5957

58+
- name: Initialize Nx Cloud
59+
run: pnpm exec nx-cloud start-ci-run --distribute-on="5 linux-medium-js"
60+
6061
- name: Build All Packages
6162
run: pnpm nx run-many -t build:ci
6263
env:
@@ -65,6 +66,8 @@ jobs:
6566
# 📦 ZIP artifacts (solo stable)
6667
- name: Generate zip artifacts
6768
if: env.IS_STABLE == 'true'
69+
env:
70+
ZIP_CONCURRENCY: ${{ env.ZIP_CONCURRENCY }}
6871
run: pnpm run release:zip-artifacts
6972

7073
# 🚀 Publish npm

scripts/package-zips.js

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
import { execSync } from "node:child_process";
1+
import { spawn } from "node:child_process";
22
import { readdirSync, existsSync, readFileSync, mkdirSync, rmSync } from "node:fs";
3+
import { availableParallelism } from "node:os";
34
import { join, relative } from "node:path";
45

56
const ROOT = process.cwd();
67
const OUTPUT_DIR = join(ROOT, "release-artifacts");
78
const SKIPPED_PATH_PREFIXES = ["demo", "utils/tests"];
89
const SKIPPED_DIR_NAMES = new Set([".git", "node_modules", "dist", "release-artifacts"]);
10+
const DEFAULT_CONCURRENCY = Math.max(1, Math.min(8, availableParallelism()));
11+
const ZIP_CONCURRENCY = Math.max(1, Number.parseInt(process.env.ZIP_CONCURRENCY ?? "", 10) || DEFAULT_CONCURRENCY);
912

1013
// Clean output directory
1114
rmSync(OUTPUT_DIR, { recursive: true, force: true });
@@ -54,13 +57,51 @@ function findPackages(dir) {
5457
function createZip(distPath, outputZipPath) {
5558
console.log(`📦 Creating ${outputZipPath}`);
5659

57-
execSync(`cd "${distPath}" && zip -r "${outputZipPath}" .`, {
58-
stdio: "inherit",
60+
return new Promise((resolve, reject) => {
61+
const child = spawn("zip", ["-r", outputZipPath, "."], {
62+
cwd: distPath,
63+
stdio: "inherit",
64+
});
65+
66+
child.on("error", (error) => {
67+
reject(error);
68+
});
69+
70+
child.on("close", (code) => {
71+
if (code === 0) {
72+
resolve();
73+
74+
return;
75+
}
76+
77+
reject(new Error(`zip command failed with exit code ${code} for ${outputZipPath}`));
78+
});
5979
});
6080
}
6181

82+
async function runWithConcurrency(items, concurrency, worker) {
83+
let index = 0;
84+
85+
async function runWorker() {
86+
while (true) {
87+
const currentIndex = index;
88+
89+
index += 1;
90+
91+
if (currentIndex >= items.length) {
92+
return;
93+
}
94+
95+
await worker(items[currentIndex]);
96+
}
97+
}
98+
99+
await Promise.all(Array.from({ length: Math.min(concurrency, items.length) }, () => runWorker()));
100+
}
101+
62102
// 🔍 Find all packages in repo
63103
const allPackages = findPackages(ROOT);
104+
const zipJobs = [];
64105

65106
for (const pkgPath of allPackages) {
66107
const distPath = join(pkgPath, "dist");
@@ -82,7 +123,14 @@ for (const pkgPath of allPackages) {
82123
const zipName = `${name}-${version}.zip`;
83124
const zipPath = join(OUTPUT_DIR, zipName);
84125

85-
createZip(distPath, zipPath);
126+
zipJobs.push({
127+
distPath,
128+
zipPath,
129+
});
86130
}
87131

132+
console.log(`⚙️ Packaging ${zipJobs.length} artifacts with concurrency ${ZIP_CONCURRENCY}`);
133+
134+
await runWithConcurrency(zipJobs, ZIP_CONCURRENCY, ({ distPath, zipPath }) => createZip(distPath, zipPath));
135+
88136
console.log("✅ All package archives created successfully.");

0 commit comments

Comments
 (0)