Skip to content

Commit e80c97c

Browse files
committed
Update GitHub Actions and refactor sample size processing
- Upgrade actions/checkout, actions/configure-pages, actions/setup-node, actions/upload-pages-artifact, and actions/deploy-pages to latest versions. - Refactor JSON fetching in process-sample-size.js to use a cache-busting mechanism and improve error handling. - Remove Puppeteer dependency from package.json as it's no longer needed.
1 parent f6a8390 commit e80c97c

3 files changed

Lines changed: 149 additions & 136 deletions

File tree

.github/workflows/publish.yml

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
push:
55
branches:
66
- master
7-
pull_request_target:
7+
pull_request:
88
workflow_dispatch:
99
workflow_call:
1010
schedule:
@@ -22,33 +22,21 @@ jobs:
2222
permissions:
2323
contents: read
2424
steps:
25-
26-
- name: Checkout PR
27-
if: ${{ github.event_name == 'pull_request_target' }}
28-
uses: actions/checkout@v4
29-
with:
30-
ref: ${{ github.event.pull_request.head.ref }}
31-
repository: ${{ github.event.pull_request.head.repo.full_name }}
32-
3325
- name: Checkout
34-
if: ${{ github.event_name != 'pull_request_target' }}
35-
uses: actions/checkout@v4
36-
with:
37-
ref: master
26+
uses: actions/checkout@v7
3827

3928
- name: Setup Pages
40-
uses: actions/configure-pages@v4
29+
uses: actions/configure-pages@v6
4130
- name: Use Node.js
42-
uses: actions/setup-node@v4
31+
uses: actions/setup-node@v7
4332
with:
44-
node-version: 22
33+
node-version: 24
4534
cache: npm
4635
- name: Update npm to latest
4736
run: npm i --prefer-online --no-fund --no-audit -g npm@latest
4837
- run: npm -v
4938
- run: npm i --ignore-scripts --no-audit --no-fund --package-lock
5039

51-
- run: npm run puppeteer
5240
- run: npm run build
5341
- run: npm run timestamp
5442
env:
@@ -57,12 +45,12 @@ jobs:
5745
- run: ./build/deploy.sh
5846

5947
- name: Upload artifact
60-
uses: actions/upload-pages-artifact@v3
48+
uses: actions/upload-pages-artifact@v5
6149
with:
6250
path: './out'
6351

6452
deploy:
65-
if: ${{ github.event_name != 'pull_request_target' && contains(fromJSON('["refs/heads/master", "refs/heads/main"]'), github.ref) }}
53+
if: ${{ contains(fromJSON('["refs/heads/master", "refs/heads/main"]'), github.ref) }}
6654
runs-on: ubuntu-latest
6755
needs: build
6856
environment:
@@ -76,7 +64,7 @@ jobs:
7664
steps:
7765
- name: Deploy to GitHub Pages
7866
id: deployment
79-
uses: actions/deploy-pages@v4
67+
uses: actions/deploy-pages@v5
8068
# internal-only alpha, not available yet: https://github.com/actions/deploy-pages/pull/61
8169
# with:
8270
# preview: ${{ github.event_name == 'pull_request_target' }}

build/process-sample-size.js

Lines changed: 141 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
const fs = require("fs");
1616
const fileUtils = require("./file-utils");
1717
const request = require("request");
18-
const puppeteer = require("puppeteer");
1918

2019
// GitHub-served raw JSON file URLs from gh-pages branch
2120
const overallURL =
@@ -25,6 +24,47 @@ const conciseURL =
2524
const detailedURL =
2625
"https://tsitu.github.io/MH-Tools/data/json/sample-summary-detailed.json";
2726

27+
/**
28+
* Add a unique query string to bypass edge/browser caches for GitHub Pages JSON
29+
* @param {string} url
30+
* @returns {string}
31+
*/
32+
function cacheBust(url) {
33+
return `${url}?t=${Date.now()}`;
34+
}
35+
36+
/**
37+
* Fetch and parse JSON with explicit no-cache headers
38+
* @param {string} url
39+
* @returns {Promise<object>}
40+
*/
41+
function fetchJSON(url) {
42+
return new Promise((resolve, reject) => {
43+
request(
44+
{
45+
url: cacheBust(url),
46+
headers: {
47+
"Cache-Control": "no-cache, no-store, must-revalidate",
48+
Pragma: "no-cache",
49+
Expires: "0"
50+
}
51+
},
52+
(error, response, body) => {
53+
if (error) {
54+
reject(error);
55+
return;
56+
}
57+
58+
try {
59+
resolve(JSON.parse(body));
60+
} catch (parseErr) {
61+
reject(parseErr);
62+
}
63+
}
64+
);
65+
});
66+
}
67+
2868
/**
2969
* Returns ideal sample size for 10% relative uncertainty at 95% level
3070
* Formula: n = 4 * z^2 * (1 - p) / (p * x^2)
@@ -253,127 +293,127 @@ function parseJSON() {
253293

254294
function processOverall() {
255295
return new Promise((resolve, reject) => {
256-
request(overallURL, (error, response, body) => {
257-
if (error) throw error;
258-
const obj = JSON.parse(body);
259-
260-
// Compare overall summary scores
261-
const currentOverallSS = +obj["score"];
262-
const incomingOverallSS = +overallObj["score"];
263-
264-
console.log("----------------------------------------\n");
265-
console.log(
266-
`[ Overall Score Change ]\n\n ${currentOverallSS} (${scoreLabel(
267-
currentOverallSS
268-
)}) -> ${incomingOverallSS} (${scoreLabel(incomingOverallSS)})\n`
269-
);
270-
console.log("----------------------------------------\n");
271-
272-
resolve();
273-
});
296+
fetchJSON(overallURL)
297+
.then(obj => {
298+
299+
// Compare overall summary scores
300+
const currentOverallSS = +obj["score"];
301+
const incomingOverallSS = +overallObj["score"];
302+
303+
console.log("----------------------------------------\n");
304+
console.log(
305+
`[ Overall Score Change ]\n\n ${currentOverallSS} (${scoreLabel(
306+
currentOverallSS
307+
)}) -> ${incomingOverallSS} (${scoreLabel(incomingOverallSS)})\n`
308+
);
309+
console.log("----------------------------------------\n");
310+
311+
resolve();
312+
})
313+
.catch(reject);
274314
});
275315
}
276316

277317
function processLocation() {
278318
return new Promise((resolve, reject) => {
279-
request(conciseURL, (error, response, body) => {
280-
if (error) throw error;
281-
const obj = JSON.parse(body);
282-
console.log("[ Changes By Location ]\n");
283-
284-
// Compare concise summaries
285-
for (let el in conciseObj) {
286-
if (!obj[el]) {
287-
console.log(
288-
`${el} (New Location)\n Average Score: ${
289-
conciseObj[el]["Average Score"]
290-
}\n Location Rating: ${
291-
conciseObj[el]["Location Rating"]
292-
}\n Average Sample Size: ${
293-
conciseObj[el]["Average Sample Size"]
294-
}\n Average Mice Count: ${conciseObj[el]["Average Mice Count"]}\n`
295-
);
296-
} else if (
297-
conciseObj[el]["Average Score"] != obj[el]["Average Score"] ||
298-
conciseObj[el]["Location Rating"] != obj[el]["Location Rating"] ||
299-
conciseObj[el]["Average Sample Size"] !=
300-
obj[el]["Average Sample Size"] ||
301-
conciseObj[el]["Average Mice Count"] != obj[el]["Average Mice Count"]
302-
) {
303-
console.log(
304-
`${el}\n Average Score: ${obj[el]["Average Score"]} -> ${
305-
conciseObj[el]["Average Score"]
306-
}\n Location Rating: ${obj[el]["Location Rating"]} -> ${
307-
conciseObj[el]["Location Rating"]
308-
}\n Average Sample Size: ${obj[el]["Average Sample Size"]} -> ${
309-
conciseObj[el]["Average Sample Size"]
310-
}\n Average Mice Count: ${obj[el]["Average Mice Count"]} -> ${
311-
conciseObj[el]["Average Mice Count"]
312-
}\n`
313-
);
319+
fetchJSON(conciseURL)
320+
.then(obj => {
321+
console.log("[ Changes By Location ]\n");
322+
323+
// Compare concise summaries
324+
for (let el in conciseObj) {
325+
if (!obj[el]) {
326+
console.log(
327+
`${el} (New Location)\n Average Score: ${
328+
conciseObj[el]["Average Score"]
329+
}\n Location Rating: ${
330+
conciseObj[el]["Location Rating"]
331+
}\n Average Sample Size: ${
332+
conciseObj[el]["Average Sample Size"]
333+
}\n Average Mice Count: ${conciseObj[el]["Average Mice Count"]}\n`
334+
);
335+
} else if (
336+
conciseObj[el]["Average Score"] != obj[el]["Average Score"] ||
337+
conciseObj[el]["Location Rating"] != obj[el]["Location Rating"] ||
338+
conciseObj[el]["Average Sample Size"] !=
339+
obj[el]["Average Sample Size"] ||
340+
conciseObj[el]["Average Mice Count"] != obj[el]["Average Mice Count"]
341+
) {
342+
console.log(
343+
`${el}\n Average Score: ${obj[el]["Average Score"]} -> ${
344+
conciseObj[el]["Average Score"]
345+
}\n Location Rating: ${obj[el]["Location Rating"]} -> ${
346+
conciseObj[el]["Location Rating"]
347+
}\n Average Sample Size: ${obj[el]["Average Sample Size"]} -> ${
348+
conciseObj[el]["Average Sample Size"]
349+
}\n Average Mice Count: ${obj[el]["Average Mice Count"]} -> ${
350+
conciseObj[el]["Average Mice Count"]
351+
}\n`
352+
);
353+
}
314354
}
315-
}
316-
console.log("----------------------------------------\n");
355+
console.log("----------------------------------------\n");
317356

318-
resolve();
319-
});
357+
resolve();
358+
})
359+
.catch(reject);
320360
});
321361
}
322362

323363
function processDetailed() {
324364
return new Promise((resolve, reject) => {
325-
request(detailedURL, (error, response, body) => {
326-
if (error) throw error;
327-
const obj = JSON.parse(body);
328-
console.log("[ Changes By Phase/Cheese/Charm ]\n");
329-
330-
// Compare detailed summaries
331-
for (let loc in detailedObj) {
332-
if (!obj[loc]) {
333-
console.log(`${loc} (New Location)`);
334-
for (let sub in detailedObj[loc]) {
335-
console.log(
336-
`${sub}\n Score: ${
337-
detailedObj[loc][sub]["score"]
338-
}\n Sample Size: ${
339-
detailedObj[loc][sub]["sample"]
340-
}\n Mouse Count: ${detailedObj[loc][sub]["count"]}`
341-
);
342-
}
343-
console.log("");
344-
} else {
345-
for (let sub in detailedObj[loc]) {
346-
if (!obj[loc][sub]) {
347-
// Log location every time?
365+
fetchJSON(detailedURL)
366+
.then(obj => {
367+
console.log("[ Changes By Phase/Cheese/Charm ]\n");
368+
369+
// Compare detailed summaries
370+
for (let loc in detailedObj) {
371+
if (!obj[loc]) {
372+
console.log(`${loc} (New Location)`);
373+
for (let sub in detailedObj[loc]) {
348374
console.log(
349-
`${loc}, ${sub} (New PCC)\n Score: ${
375+
`${sub}\n Score: ${
350376
detailedObj[loc][sub]["score"]
351377
}\n Sample Size: ${
352378
detailedObj[loc][sub]["sample"]
353-
}\n Mouse Count: ${detailedObj[loc][sub]["count"]}\n`
354-
);
355-
} else if (
356-
detailedObj[loc][sub]["score"] != obj[loc][sub]["score"] ||
357-
detailedObj[loc][sub]["sample"] != obj[loc][sub]["sample"] ||
358-
detailedObj[loc][sub]["count"] != obj[loc][sub]["count"]
359-
) {
360-
console.log(
361-
`${loc}, ${sub}\n Score: ${obj[loc][sub]["score"]} -> ${
362-
detailedObj[loc][sub]["score"]
363-
}\n Sample Size: ${obj[loc][sub]["sample"]} -> ${
364-
detailedObj[loc][sub]["sample"]
365-
}\n Mouse Count: ${obj[loc][sub]["count"]} -> ${
366-
detailedObj[loc][sub]["count"]
367-
}\n`
379+
}\n Mouse Count: ${detailedObj[loc][sub]["count"]}`
368380
);
369381
}
382+
console.log("");
383+
} else {
384+
for (let sub in detailedObj[loc]) {
385+
if (!obj[loc][sub]) {
386+
// Log location every time?
387+
console.log(
388+
`${loc}, ${sub} (New PCC)\n Score: ${
389+
detailedObj[loc][sub]["score"]
390+
}\n Sample Size: ${
391+
detailedObj[loc][sub]["sample"]
392+
}\n Mouse Count: ${detailedObj[loc][sub]["count"]}\n`
393+
);
394+
} else if (
395+
detailedObj[loc][sub]["score"] != obj[loc][sub]["score"] ||
396+
detailedObj[loc][sub]["sample"] != obj[loc][sub]["sample"] ||
397+
detailedObj[loc][sub]["count"] != obj[loc][sub]["count"]
398+
) {
399+
console.log(
400+
`${loc}, ${sub}\n Score: ${obj[loc][sub]["score"]} -> ${
401+
detailedObj[loc][sub]["score"]
402+
}\n Sample Size: ${obj[loc][sub]["sample"]} -> ${
403+
detailedObj[loc][sub]["sample"]
404+
}\n Mouse Count: ${obj[loc][sub]["count"]} -> ${
405+
detailedObj[loc][sub]["count"]
406+
}\n`
407+
);
408+
}
409+
}
370410
}
371411
}
372-
}
373-
console.log("----------------------------------------");
412+
console.log("----------------------------------------");
374413

375-
resolve();
376-
});
414+
resolve();
415+
})
416+
.catch(reject);
377417
});
378418
}
379419

@@ -382,20 +422,6 @@ function processDetailed() {
382422
* Consistent console.log ordering by using separate functions and chaining
383423
*/
384424
async function calculateDiffs() {
385-
// Force update raw JSON files on GitHub using Puppeteer
386-
const browser = await puppeteer.launch({
387-
args: ["--no-sandbox", "--disable-setuid-sandbox"]
388-
// executablePath:
389-
// "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe"
390-
});
391-
const overallPage = await browser.newPage();
392-
const concisePage = await browser.newPage();
393-
const detailedPage = await browser.newPage();
394-
await overallPage.goto(overallURL);
395-
await concisePage.goto(conciseURL);
396-
await detailedPage.goto(detailedURL);
397-
await browser.close();
398-
399425
await processOverall();
400426
await processLocation();
401427
await processDetailed();

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
"minify:utils": "uglifyjs-folder src/utils -eo src/utils/min -p **/*.js,!**/*min.js",
6161
"minify": "npm-run-all --parallel minify:*",
6262
"\n-- BUILD --": "",
63-
"puppeteer": "npm i puppeteer@18",
6463
"timestamp": "node build/process-timestamp.js",
6564
"sample": "node build/process-sample-size.js",
6665
"mouse-data": "node build/process-mouse-data.js",

0 commit comments

Comments
 (0)