Deploy script: wrap in async IIFE (top-level await invalid in CommonJS)
Some checks failed
Deploy to WebDAV (/BLB) / deploy (push) Failing after 43s
Some checks failed
Deploy to WebDAV (/BLB) / deploy (push) Failing after 43s
This commit is contained in:
parent
096c527629
commit
1bbdf05a76
@ -31,6 +31,7 @@ jobs:
|
|||||||
const { execSync } = require('child_process');
|
const { execSync } = require('child_process');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
|
(async () => {
|
||||||
const USER = process.env.WEBDAV_USER;
|
const USER = process.env.WEBDAV_USER;
|
||||||
const PASS = process.env.WEBDAV_PASS;
|
const PASS = process.env.WEBDAV_PASS;
|
||||||
const BASE = process.env.WEBDAV_BASE;
|
const BASE = process.env.WEBDAV_BASE;
|
||||||
@ -40,13 +41,13 @@ jobs:
|
|||||||
|
|
||||||
// Simple content-type map (node:20 image has no `mime` package).
|
// Simple content-type map (node:20 image has no `mime` package).
|
||||||
const MIME = {
|
const MIME = {
|
||||||
html: 'text/html', htm: 'text/html', js: 'application/javascript',
|
html: 'text/html', htm: 'text/html', js: 'application/javascript', mjs: 'application/javascript',
|
||||||
css: 'text/css', json: 'application/json', txt: 'text/plain',
|
css: 'text/css', json: 'application/json', txt: 'text/plain',
|
||||||
md: 'text/markdown', xml: 'application/xml', gif: 'image/gif',
|
md: 'text/markdown', xml: 'application/xml', gif: 'image/gif',
|
||||||
jpg: 'image/jpeg', jpeg: 'image/jpeg', png: 'image/png',
|
jpg: 'image/jpeg', jpeg: 'image/jpeg', png: 'image/png',
|
||||||
ico: 'image/x-icon', svg: 'image/svg+xml', pdf: 'application/pdf',
|
ico: 'image/x-icon', svg: 'image/svg+xml', pdf: 'application/pdf',
|
||||||
mid: 'audio/midi', mp3: 'audio/mpeg', wav: 'audio/x-wav', rm: 'application/vnd.rn-realmedia',
|
mid: 'audio/midi', mp3: 'audio/mpeg', wav: 'audio/x-wav', rm: 'application/vnd.rn-realmedia',
|
||||||
swf: 'application/x-shockwave-flash', jsx: 'text/javascript', mjs: 'application/javascript',
|
swf: 'application/x-shockwave-flash', jsx: 'text/javascript',
|
||||||
};
|
};
|
||||||
const typeFor = (f) => {
|
const typeFor = (f) => {
|
||||||
const e = f.split('.').pop().toLowerCase();
|
const e = f.split('.').pop().toLowerCase();
|
||||||
@ -68,7 +69,7 @@ jobs:
|
|||||||
|
|
||||||
if (files.length === 0) {
|
if (files.length === 0) {
|
||||||
console.log('No site files changed; nothing to deploy.');
|
console.log('No site files changed; nothing to deploy.');
|
||||||
process.exit(0);
|
return;
|
||||||
}
|
}
|
||||||
console.log(`Deploying ${files.length} changed file(s):`);
|
console.log(`Deploying ${files.length} changed file(s):`);
|
||||||
for (const f of files.slice(0, 20)) console.log(' ' + f);
|
for (const f of files.slice(0, 20)) console.log(' ' + f);
|
||||||
@ -98,7 +99,7 @@ jobs:
|
|||||||
const N = 8;
|
const N = 8;
|
||||||
let i = 0;
|
let i = 0;
|
||||||
const failures = [];
|
const failures = [];
|
||||||
const worker = async () => {
|
async function worker() {
|
||||||
while (i < files.length) {
|
while (i < files.length) {
|
||||||
const f = files[i++];
|
const f = files[i++];
|
||||||
try {
|
try {
|
||||||
@ -108,7 +109,7 @@ jobs:
|
|||||||
console.log(`::warning::failed ${f} -- ${e.message}`);
|
console.log(`::warning::failed ${f} -- ${e.message}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
await Promise.all(Array.from({ length: N }, worker));
|
await Promise.all(Array.from({ length: N }, worker));
|
||||||
if (failures.length) {
|
if (failures.length) {
|
||||||
console.log(`::error::${failures.length}/${files.length} files failed to deploy`);
|
console.log(`::error::${failures.length}/${files.length} files failed to deploy`);
|
||||||
@ -116,4 +117,5 @@ jobs:
|
|||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
console.log(`Deployed ${files.length} file(s) successfully.`);
|
console.log(`Deployed ${files.length} file(s) successfully.`);
|
||||||
|
})().catch((e) => { console.error(e); process.exit(1); });
|
||||||
NODE
|
NODE
|
||||||
Loading…
x
Reference in New Issue
Block a user