From 74a6ae51080e89a0440228382445c699c7b82556 Mon Sep 17 00:00:00 2001 From: StroepWafel Date: Tue, 23 Jun 2026 09:38:22 +0930 Subject: [PATCH] fix zipping --- .github/actions/build-extension/action.yml | 12 +--- scripts/package-extension-zips.mjs | 71 ++++++++++++++++++++++ 2 files changed, 72 insertions(+), 11 deletions(-) create mode 100644 scripts/package-extension-zips.mjs diff --git a/.github/actions/build-extension/action.yml b/.github/actions/build-extension/action.yml index 2e6afc8a..6d71a1b8 100644 --- a/.github/actions/build-extension/action.yml +++ b/.github/actions/build-extension/action.yml @@ -62,14 +62,4 @@ runs: env: UPDATE_CHANNEL: ${{ inputs.update_channel }} BUILD_LABEL: ${{ inputs.build_label }} - run: | - VERSION="${{ steps.version.outputs.version }}" - if [ "$UPDATE_CHANNEL" = "nightly" ] && [ -n "$BUILD_LABEL" ]; then - BASE="betterseqtaplus-nightly-${BUILD_LABEL}" - else - BASE="betterseqtaplus-${VERSION}" - fi - tar -a -cf "dist/${BASE}-chrome.zip" -C dist/chrome . - tar -a -cf "dist/${BASE}-firefox.zip" -C dist/firefox . - echo "chrome_zip=dist/${BASE}-chrome.zip" >> "$GITHUB_OUTPUT" - echo "firefox_zip=dist/${BASE}-firefox.zip" >> "$GITHUB_OUTPUT" + run: node scripts/package-extension-zips.mjs "${{ steps.version.outputs.version }}" diff --git a/scripts/package-extension-zips.mjs b/scripts/package-extension-zips.mjs new file mode 100644 index 00000000..0342a26b --- /dev/null +++ b/scripts/package-extension-zips.mjs @@ -0,0 +1,71 @@ +/** + * Package Chrome/Firefox build folders into zip files Windows Explorer can open. + * Git Bash `tar -a` on CI often produces zips that fail to unzip on Windows. + */ +import { execFileSync } from "node:child_process"; +import { + appendFileSync, + existsSync, + mkdirSync, + readFileSync, + unlinkSync, +} from "node:fs"; +import { dirname, join } from "node:path"; +import { fileURLToPath } from "node:url"; + +const root = join(dirname(fileURLToPath(import.meta.url)), ".."); + +function zipDirectory(sourceRel, outRel) { + const sourceDir = join(root, sourceRel); + const outZip = join(root, outRel); + + if (!existsSync(sourceDir)) { + throw new Error(`Missing build output: ${sourceRel}`); + } + + mkdirSync(dirname(outZip), { recursive: true }); + if (existsSync(outZip)) { + unlinkSync(outZip); + } + + if (process.platform === "win32") { + const ps = [ + "Add-Type -AssemblyName System.IO.Compression.FileSystem", + `[IO.Compression.ZipFile]::CreateFromDirectory('${sourceDir.replace(/'/g, "''")}', '${outZip.replace(/'/g, "''")}')`, + ].join("; "); + execFileSync("powershell", ["-NoProfile", "-Command", ps], { + stdio: "inherit", + }); + } else { + execFileSync("zip", ["-r", "-q", outZip, "."], { + cwd: sourceDir, + stdio: "inherit", + }); + } +} + +const pkg = JSON.parse(readFileSync(join(root, "package.json"), "utf8")); +const version = process.argv[2] || pkg.version; +const updateChannel = process.env.UPDATE_CHANNEL || "stable"; +const buildLabel = process.env.BUILD_LABEL || ""; + +const base = + updateChannel === "nightly" && buildLabel + ? `betterseqtaplus-nightly-${buildLabel}` + : `betterseqtaplus-${version}`; + +const chromeZip = `dist/${base}-chrome.zip`; +const firefoxZip = `dist/${base}-firefox.zip`; + +zipDirectory("dist/chrome", chromeZip); +zipDirectory("dist/firefox", firefoxZip); + +console.log(`Packaged ${chromeZip}`); +console.log(`Packaged ${firefoxZip}`); + +if (process.env.GITHUB_OUTPUT) { + appendFileSync( + process.env.GITHUB_OUTPUT, + `chrome_zip=${chromeZip}\nfirefox_zip=${firefoxZip}\n`, + ); +}