Skip to content

Commit 9d7d280

Browse files
committed
Add jsDelivr CDN cache purging and examples testing to the publish workflow. (#12055)
* - Update puppeteer for the examples' demos - Add examples testing to the first-rc automation * Add jsdelivr purging automation to the publishing workflow. * Post-CR changes. * Post-cursor-review update.
1 parent a7489d3 commit 9d7d280

32 files changed

Lines changed: 6141 additions & 4793 deletions

File tree

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Purges the jsDelivr CDN cache for a given Handsontable version.
5+
*
6+
* Usage: node purge-jsdelivr-cache.mjs <version>
7+
* e.g. node purge-jsdelivr-cache.mjs 12.1.3
8+
*/
9+
10+
import { readdirSync } from 'fs';
11+
import { join, relative } from 'path';
12+
13+
const version = process.argv[2];
14+
15+
if (!version) {
16+
console.error('Usage: node purge-jsdelivr-cache.mjs <version>');
17+
process.exit(1);
18+
}
19+
20+
const [major, minor, patch] = version.split('.').map(Number);
21+
22+
const EXTENSIONS = ['.js', '.css'];
23+
24+
function collectFiles(dir) {
25+
const results = [];
26+
27+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
28+
const fullPath = join(dir, entry.name);
29+
30+
if (entry.isDirectory()) {
31+
results.push(...collectFiles(fullPath));
32+
33+
} else if (EXTENSIONS.some(ext => entry.name.endsWith(ext))) {
34+
results.push(fullPath);
35+
}
36+
}
37+
38+
return results;
39+
}
40+
41+
const PKG_DIR = 'handsontable/tmp';
42+
43+
const distDir = join(PKG_DIR, 'dist');
44+
const stylesDir = join(PKG_DIR, 'styles');
45+
46+
const DIST_FILES = collectFiles(distDir)
47+
.map(f => relative(distDir, f));
48+
49+
const STYLES_FILES = collectFiles(stylesDir)
50+
.map(f => relative(stylesDir, f));
51+
52+
const tags = ['latest'];
53+
54+
if (patch !== 0) {
55+
tags.push(`${major}`, `${major}.${minor}`);
56+
} else if (minor !== 0) {
57+
tags.push(`${major}`);
58+
}
59+
60+
let failed = false;
61+
62+
for (const tag of tags) {
63+
console.log(`\nPurging @${tag} cache...`);
64+
65+
for (const file of DIST_FILES) {
66+
const url = `https://purge.jsdelivr.net/npm/handsontable@${tag}/dist/${file}`;
67+
const res = await fetch(url);
68+
69+
console.log(`${res.status} @${tag}/dist/${file}`);
70+
71+
if (!res.ok) {
72+
failed = true;
73+
}
74+
}
75+
76+
for (const file of STYLES_FILES) {
77+
const url = `https://purge.jsdelivr.net/npm/handsontable@${tag}/styles/${file}`;
78+
const res = await fetch(url);
79+
80+
console.log(`${res.status} @${tag}/styles/${file}`);
81+
82+
if (!res.ok) {
83+
failed = true;
84+
}
85+
}
86+
}
87+
88+
if (failed) {
89+
console.error('\nSome purge requests failed (see above).');
90+
process.exit(1);
91+
}
92+
93+
console.log('\nAll purge requests completed successfully.');

.github/workflows/publish.yml

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ jobs:
115115
VERSION='${{ steps.version.outputs.version }}'
116116
node -e "
117117
import { isVersionValid } from './scripts/utils/pre-release.mjs';
118-
118+
119119
if (!isVersionValid('${VERSION}')) {
120120
console.error('Error: Invalid version format: ${VERSION}');
121121
process.exit(1);
@@ -128,7 +128,7 @@ jobs:
128128
echo "npm version: $NPM_VERSION"
129129
node -e "
130130
import semver from 'semver';
131-
131+
132132
if (!semver.satisfies('${NPM_VERSION}'.trim(), '>=7.17.0')) {
133133
console.error('Error: npm >= 7.17.0 required (found ${NPM_VERSION})');
134134
process.exit(1);
@@ -153,7 +153,7 @@ jobs:
153153
RELEASE_DATE=$(date +%d/%m/%Y)
154154
node -e "
155155
import { setVersion, setReleaseDate } from './scripts/utils/pre-release.mjs';
156-
156+
157157
setVersion('${RC_VERSION}');
158158
setReleaseDate('${RELEASE_DATE}');
159159
"
@@ -162,7 +162,7 @@ jobs:
162162
run: |
163163
node -e "
164164
import { cleanNodeModules } from './scripts/utils/filesystem.mjs';
165-
165+
166166
cleanNodeModules();
167167
"
168168
@@ -181,6 +181,9 @@ jobs:
181181
- name: Build examples
182182
run: npm run in examples build
183183

184+
- name: Run Examples tests
185+
run: npm run in examples test
186+
184187
- name: Verify bundles
185188
run: node ./scripts/verify-bundles.mjs
186189

@@ -423,7 +426,7 @@ jobs:
423426
echo "npm version: $NPM_VERSION"
424427
node -e "
425428
import semver from 'semver';
426-
429+
427430
if (!semver.satisfies('${NPM_VERSION}'.trim(), '>=7.17.0')) {
428431
console.error('Error: npm >= 7.17.0 required (found ${NPM_VERSION})');
429432
process.exit(1);
@@ -456,7 +459,7 @@ jobs:
456459
RELEASE_DATE=$(date +%d/%m/%Y)
457460
node -e "
458461
import { setVersion, setReleaseDate } from './scripts/utils/pre-release.mjs';
459-
462+
460463
setVersion('${RC_VERSION}');
461464
setReleaseDate('${RELEASE_DATE}');
462465
"
@@ -635,10 +638,10 @@ jobs:
635638
git fetch --tags --quiet
636639
637640
COMMITS_TEXT=""
638-
641+
639642
if git rev-parse "$PREV_TAG" >/dev/null 2>&1; then
640643
COMMITS=$(git log "${PREV_TAG}..HEAD" --pretty=format:"%H %s" --no-merges)
641-
644+
642645
if [ -n "$COMMITS" ]; then
643646
while IFS= read -r line; do
644647
SHA=$(echo "$line" | cut -d' ' -f1)
@@ -760,7 +763,7 @@ jobs:
760763
VERSION='${{ steps.version.outputs.version }}'
761764
node -e "
762765
import { isVersionValid } from './scripts/utils/pre-release.mjs';
763-
766+
764767
if (!isVersionValid('${VERSION}')) {
765768
console.error('Error: Invalid version format: ${VERSION}');
766769
process.exit(1);
@@ -773,7 +776,7 @@ jobs:
773776
echo "npm version: $NPM_VERSION"
774777
node -e "
775778
import semver from 'semver';
776-
779+
777780
if (!semver.satisfies('${NPM_VERSION}'.trim(), '>=7.17.0')) {
778781
console.error('Error: npm >= 7.17.0 required (found ${NPM_VERSION})');
779782
process.exit(1);
@@ -786,7 +789,7 @@ jobs:
786789
RELEASE_DATE=$(date +%d/%m/%Y)
787790
node -e "
788791
import { setVersion, setReleaseDate } from './scripts/utils/pre-release.mjs';
789-
792+
790793
setVersion('${VERSION}');
791794
setReleaseDate('${RELEASE_DATE}');
792795
"
@@ -977,6 +980,17 @@ jobs:
977980
done
978981
echo "All packages published successfully."
979982
983+
- name: Unpack handsontable tarball for CDN purge
984+
continue-on-error: true
985+
run: |
986+
mkdir -p handsontable/tmp
987+
tar -xzf _tmp_packs/handsontable-${{ needs.stable-build.outputs.version }}.tgz \
988+
-C handsontable/tmp --strip-components=1
989+
990+
- name: Purge jsDelivr CDN cache
991+
continue-on-error: true
992+
run: node .github/scripts/purge-jsdelivr-cache.mjs '${{ needs.stable-build.outputs.version }}'
993+
980994
- name: Download NuGet package artifact
981995
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # https://github.com/actions/download-artifact/releases/tag/v4.3.0
982996
with:

examples/next/docs/angular-wrapper/basic-example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"http-server": "^14.1.1",
4444
"jasmine": "3.7.0",
4545
"jasmine-console-reporter": "3.1.0",
46-
"puppeteer": "14.3.0",
46+
"puppeteer": "^24.2.1",
4747
"ts-node": "8.3.0",
4848
"typescript": "~5.9.0"
4949
},

examples/next/docs/angular-wrapper/demo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"http-server": "^14.1.1",
4545
"jasmine": "3.7.0",
4646
"jasmine-console-reporter": "3.1.0",
47-
"puppeteer": "14.3.0",
47+
"puppeteer": "^24.2.1",
4848
"ts-node": "8.3.0",
4949
"typescript": "~5.8.0"
5050
},

0 commit comments

Comments
 (0)