Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
},
"devDependencies": {
"@cloudflare/vitest-pool-workers": "^0.16.10",
"@tktco/node-actionlint": "^1.6.0",
"@types/node": "^24.10.1",
"@vitest/coverage-v8": "^4.1.7",
"drizzle-kit": "^0.31.7",
Expand Down
62 changes: 58 additions & 4 deletions scripts/actionlint.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { execFileSync } from "node:child_process";
import { readdirSync } from "node:fs";
import { readFileSync, readdirSync } from "node:fs";
import { createRequire } from "node:module";
import { join } from "node:path";
import { setTimeout as delay } from "node:timers/promises";

const require = createRequire(import.meta.url);
const { actionlint } = require("github-actionlint");

const workflowDir = ".github/workflows";
const files = readdirSync(workflowDir)
Expand All @@ -12,5 +16,55 @@ if (files.length === 0) {
process.exit(1);
}

const bin = process.platform === "win32" ? "github-actionlint.cmd" : "github-actionlint";
execFileSync(bin, files, { stdio: "inherit", shell: process.platform === "win32" });
const maxAttempts = Math.max(1, Number.parseInt(process.env.ACTIONLINT_DOWNLOAD_ATTEMPTS ?? "4", 10) || 4);
const retryDelaysMs = [1000, 3000, 7000];
const retryableSetupError = /Download failed: (?:408|425|429|5\d\d)\b|ECONNRESET|ETIMEDOUT|EAI_AGAIN|ENOTFOUND|socket hang up/i;

function errorMessage(error) {
return error instanceof Error ? error.message : String(error);
}

async function runWasmActionlint(reason) {
console.warn(`official actionlint setup unavailable, using WASM fallback: ${reason}`);
const { getLintLog, runLint } = require("@tktco/node-actionlint");
const fileData = files.map((file) => ({ path: file, data: readFileSync(file, "utf8") }));
const results = (
await Promise.all(
fileData.map(async (file) => {
const lintResults = await runLint(file.data, file.path);
return lintResults.map((result) => ({ ...result, ...file }));
}),
)
)
.flat()
.filter((result) => result.message);
const log = getLintLog(results);
if (log) {
console.error(log);
return { code: 1 };
}
return { code: 0 };
}

async function runActionlint() {
if (process.env.ACTIONLINT_FORCE_WASM_FALLBACK === "1") {
return runWasmActionlint("forced by ACTIONLINT_FORCE_WASM_FALLBACK");
}

for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {
try {
return await actionlint({ args: files, spawnOptions: { stdio: "inherit" } });
} catch (error) {
const message = errorMessage(error);
if (!retryableSetupError.test(message)) throw error;
if (attempt >= maxAttempts) return runWasmActionlint(message);
const delayMs = retryDelaysMs[Math.min(attempt - 1, retryDelaysMs.length - 1)];
console.warn(`actionlint setup failed, retrying (${attempt}/${maxAttempts}): ${message}`);
await delay(delayMs);
}
}
throw new Error("actionlint setup failed without returning a result");
}

const result = await runActionlint();
process.exit(result.code);