mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-12-06 19:56:45 +10:30
Gate store releases on Seth's approval and include Firefox sources
This commit is contained in:
1 parent
a2b604a87a
commit
9fd51512e3
4 files changed
+198
-173
No files matched your search
@@ -2,6 +2,10 @@ name: Build Extension
|
|||||||
description: Install dependencies, build Chrome and Firefox extensions, and package zips.
|
description: Install dependencies, build Chrome and Firefox extensions, and package zips.
|
||||||
|
|
||||||
inputs:
|
inputs:
|
||||||
|
include_sources:
|
||||||
|
description: Include the committed source and Firefox build instructions.
|
||||||
|
required: false
|
||||||
|
default: "false"
|
||||||
gh_release_update_check:
|
gh_release_update_check:
|
||||||
description: Enable GitHub release update checker in the built extension.
|
description: Enable GitHub release update checker in the built extension.
|
||||||
required: false
|
required: false
|
||||||
@@ -29,6 +33,9 @@ outputs:
|
|||||||
firefox_zip:
|
firefox_zip:
|
||||||
description: Path to the Firefox extension zip
|
description: Path to the Firefox extension zip
|
||||||
value: ${{ steps.zip.outputs.firefox_zip }}
|
value: ${{ steps.zip.outputs.firefox_zip }}
|
||||||
|
sources_zip:
|
||||||
|
description: Path to the Firefox source zip when include_sources is true
|
||||||
|
value: ${{ steps.zip.outputs.sources_zip }}
|
||||||
|
|
||||||
runs:
|
runs:
|
||||||
using: composite
|
using: composite
|
||||||
@@ -56,4 +63,4 @@ runs:
|
|||||||
env:
|
env:
|
||||||
UPDATE_CHANNEL: ${{ inputs.update_channel }}
|
UPDATE_CHANNEL: ${{ inputs.update_channel }}
|
||||||
BUILD_LABEL: ${{ inputs.build_label }}
|
BUILD_LABEL: ${{ inputs.build_label }}
|
||||||
run: node scripts/package-extension-zips.mjs "${{ steps.version.outputs.version }}"
|
run: node scripts/package-extension-zips.mjs "${{ steps.version.outputs.version }}" "${{ inputs.include_sources == 'true' && '--sources' || '' }}"
|
||||||
@@ -0,0 +1,120 @@
|
|||||||
|
name: Publish Stores
|
||||||
|
|
||||||
|
on:
|
||||||
|
release:
|
||||||
|
types: [published]
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: store-release-${{ github.ref }}
|
||||||
|
cancel-in-progress: false
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
if: github.event_name == 'workflow_dispatch' || !github.event.release.prerelease
|
||||||
|
runs-on: windows-latest
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
shell: bash
|
||||||
|
outputs:
|
||||||
|
publisher_version: ${{ steps.publisher.outputs.version }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v7
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
|
- name: Check release version
|
||||||
|
if: github.event_name == 'release'
|
||||||
|
env:
|
||||||
|
RELEASE_TAG: ${{ github.event.release.tag_name }}
|
||||||
|
run: test "${RELEASE_TAG#v}" = "$(node -p "require('./package.json').version")"
|
||||||
|
|
||||||
|
- name: Build store packages
|
||||||
|
id: build
|
||||||
|
uses: ./.github/actions/build-extension
|
||||||
|
with:
|
||||||
|
include_sources: "true"
|
||||||
|
|
||||||
|
- name: Check build
|
||||||
|
run: npm run lint && npm run test:unit && npm run test:smoke
|
||||||
|
|
||||||
|
- name: Verify Firefox source rebuild
|
||||||
|
env:
|
||||||
|
SOURCES_ZIP: ${{ steps.build.outputs.sources_zip }}
|
||||||
|
run: |
|
||||||
|
mkdir "$RUNNER_TEMP/source-rebuild"
|
||||||
|
tar -xf "$SOURCES_ZIP" -C "$RUNNER_TEMP/source-rebuild"
|
||||||
|
cd "$RUNNER_TEMP/source-rebuild"
|
||||||
|
npm ci
|
||||||
|
npm run build:firefox
|
||||||
|
diff -qr "$GITHUB_WORKSPACE/dist/firefox" dist/firefox
|
||||||
|
|
||||||
|
- name: Record publisher version and package checksums
|
||||||
|
id: publisher
|
||||||
|
run: |
|
||||||
|
echo "version=$(node -p "require('./node_modules/publish-browser-extension/package.json').version")" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "Commit: $GITHUB_SHA" >> "$GITHUB_STEP_SUMMARY"
|
||||||
|
sha256sum dist/*.zip | tee -a "$GITHUB_STEP_SUMMARY"
|
||||||
|
|
||||||
|
- name: Upload review artifacts
|
||||||
|
uses: actions/upload-artifact@v7
|
||||||
|
with:
|
||||||
|
name: store-packages
|
||||||
|
path: dist/*.zip
|
||||||
|
if-no-files-found: error
|
||||||
|
|
||||||
|
- name: Attach packages to release
|
||||||
|
if: github.event_name == 'release'
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ github.token }}
|
||||||
|
RELEASE_TAG: ${{ github.event.release.tag_name }}
|
||||||
|
run: gh release upload "$RELEASE_TAG" dist/*.zip --clobber
|
||||||
|
|
||||||
|
publish:
|
||||||
|
needs: build
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
environment: store-publishing
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
store: [chrome, firefox]
|
||||||
|
env:
|
||||||
|
DRY_RUN: ${{ github.event_name == 'workflow_dispatch' }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/setup-node@v7
|
||||||
|
with:
|
||||||
|
node-version: 26.x
|
||||||
|
|
||||||
|
- uses: actions/download-artifact@v8
|
||||||
|
with:
|
||||||
|
name: store-packages
|
||||||
|
path: dist
|
||||||
|
|
||||||
|
- name: Install publisher without lifecycle scripts
|
||||||
|
env:
|
||||||
|
PUBLISHER_VERSION: ${{ needs.build.outputs.publisher_version }}
|
||||||
|
run: npm install --prefix "$RUNNER_TEMP/publisher" --ignore-scripts --no-audit --no-fund "publish-browser-extension@$PUBLISHER_VERSION"
|
||||||
|
|
||||||
|
- name: Submit Chrome
|
||||||
|
if: matrix.store == 'chrome'
|
||||||
|
env:
|
||||||
|
CHROME_API_VERSION: v2
|
||||||
|
CHROME_EXTENSION_ID: ${{ secrets.CHROME_EXTENSION_ID }}
|
||||||
|
CHROME_PUBLISHER_ID: ${{ secrets.CHROME_PUBLISHER_ID }}
|
||||||
|
CHROME_SERVICE_ACCOUNT_CLIENT_EMAIL: ${{ secrets.CHROME_SERVICE_ACCOUNT_CLIENT_EMAIL }}
|
||||||
|
CHROME_SERVICE_ACCOUNT_PRIVATE_KEY: ${{ secrets.CHROME_SERVICE_ACCOUNT_PRIVATE_KEY }}
|
||||||
|
run: '"$RUNNER_TEMP/publisher/node_modules/.bin/publish-extension" --chrome-zip dist/*-chrome.zip --dry-run "$DRY_RUN"'
|
||||||
|
|
||||||
|
- name: Submit Firefox with sources
|
||||||
|
if: matrix.store == 'firefox'
|
||||||
|
env:
|
||||||
|
FIREFOX_EXTENSION_ID: ${{ secrets.FIREFOX_EXTENSION_ID }}
|
||||||
|
FIREFOX_JWT_ISSUER: ${{ secrets.FIREFOX_JWT_ISSUER }}
|
||||||
|
FIREFOX_JWT_SECRET: ${{ secrets.FIREFOX_JWT_SECRET }}
|
||||||
|
FIREFOX_CHANNEL: listed
|
||||||
|
run: '"$RUNNER_TEMP/publisher/node_modules/.bin/publish-extension" --firefox-zip dist/*-firefox.zip --firefox-sources-zip dist/*-sources.zip --dry-run "$DRY_RUN"'
|
||||||
+32
-155
@@ -1,158 +1,35 @@
|
|||||||
/**
|
import { execFileSync } from "node:child_process";
|
||||||
* @fileoverview
|
import { readFileSync } from "node:fs";
|
||||||
* This script is a command-line utility for publishing the BetterSEQTA+ extension.
|
import { fileURLToPath } from "node:url";
|
||||||
* It automates the process of finding the latest built extension ZIP files for specified
|
|
||||||
* browsers, zipping the project source code (for Firefox), and then invoking the
|
|
||||||
* `publish-extension` tool with the appropriate arguments.
|
|
||||||
*
|
|
||||||
* To use this script, invoke it with Node.js followed by browser arguments:
|
|
||||||
* e.g., `node lib/publish.js --b chrome firefox`
|
|
||||||
* or `node lib/publish.js --b chrome`
|
|
||||||
* or `node lib/publish.js --b firefox`
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { globSync } from "node:fs";
|
process.chdir(fileURLToPath(new URL("..", import.meta.url)));
|
||||||
import semver from "semver";
|
|
||||||
import { execSync } from "node:child_process";
|
|
||||||
|
|
||||||
function getLatestVersion(files) {
|
|
||||||
console.log("Files passed to getLatestVersion:", files);
|
|
||||||
|
|
||||||
const versions = files
|
|
||||||
.map((file) => {
|
|
||||||
const match = file.match(/@([\d.]+)-/);
|
|
||||||
console.log("Matching file:", file, "Version found:", match ? match[1] : "None");
|
|
||||||
|
|
||||||
if (!match) return null;
|
|
||||||
|
|
||||||
const fullVersion = match[1]; // Original version (e.g., 3.4.5.1)
|
|
||||||
// Trim to 3 parts for semver comparison, as semver typically handles X.Y.Z
|
|
||||||
const semverVersion = fullVersion.split(".").slice(0, 3).join(".");
|
|
||||||
|
|
||||||
return { fullVersion, semverVersion };
|
|
||||||
})
|
|
||||||
.filter(Boolean); // Remove null entries if any file didn't match
|
|
||||||
|
|
||||||
console.log(
|
|
||||||
"Extracted versions:",
|
|
||||||
versions.map((v) => v.semverVersion),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (versions.length === 0) {
|
|
||||||
console.log("No versions extracted.");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find latest version using the trimmed semver format
|
|
||||||
const latestSemver = semver.maxSatisfying(
|
|
||||||
versions.map((v) => v.semverVersion),
|
|
||||||
"*", // Satisfy any version, effectively finding the max
|
|
||||||
);
|
|
||||||
console.log("Latest SemVer-compatible version:", latestSemver);
|
|
||||||
|
|
||||||
if (!latestSemver) {
|
|
||||||
console.log("Could not determine latest semver version.");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the original full version string that matches the identified latest SemVer version
|
|
||||||
const latestVersionData = versions.find((v) => v.semverVersion === latestSemver);
|
|
||||||
const latestFullVersion = latestVersionData ? latestVersionData.fullVersion : null;
|
|
||||||
|
|
||||||
console.log("Final selected latest version:", latestFullVersion);
|
|
||||||
return latestFullVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getLatestFiles(browser) {
|
|
||||||
const pattern = `dist/betterseqtaplus@*-*${browser}.zip`;
|
|
||||||
console.log("Glob pattern:", pattern);
|
|
||||||
|
|
||||||
const files = globSync(pattern);
|
|
||||||
console.log("Files found for browser", browser, ":", files);
|
|
||||||
|
|
||||||
if (files.length === 0) {
|
|
||||||
console.log("No files found for browser", browser);
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
const latestVersion = getLatestVersion(files);
|
|
||||||
if (!latestVersion) {
|
|
||||||
console.log("Could not determine latest version for browser", browser);
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find the exact file by matching the original full version string
|
|
||||||
const latestFile = files.find((file) => file.includes(`@${latestVersion}-`));
|
|
||||||
|
|
||||||
console.log("Latest file for browser", browser, ":", latestFile);
|
|
||||||
return latestFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
function zipSources() {
|
|
||||||
const zipFileName = `dist/betterseqtaplus@latest-sources.zip`;
|
|
||||||
|
|
||||||
const excludePatterns = [
|
|
||||||
"node_modules",
|
|
||||||
"dist",
|
|
||||||
".env*",
|
|
||||||
".git",
|
|
||||||
".github",
|
|
||||||
".vscode",
|
|
||||||
"LICENSE",
|
|
||||||
"package.json",
|
|
||||||
]
|
|
||||||
.map((pattern) => `-x!${pattern}`) // Format for 7z exclude syntax
|
|
||||||
.join(" ");
|
|
||||||
|
|
||||||
// Command to zip the current directory's contents into zipFileName, applying exclude patterns
|
|
||||||
const zipCommand = `7zz a ${zipFileName} . ${excludePatterns}`;
|
|
||||||
|
|
||||||
console.log("Zipping project sources with command:", zipCommand);
|
|
||||||
execSync(zipCommand, { stdio: "inherit" }); // Execute synchronously and show output
|
|
||||||
|
|
||||||
return zipFileName;
|
|
||||||
}
|
|
||||||
|
|
||||||
function runPublishCommand(browsers) {
|
|
||||||
const chromeZip = browsers.includes("chrome") ? getLatestFiles("chrome") : null;
|
|
||||||
const firefoxZip = browsers.includes("firefox") ? getLatestFiles("firefox") : null;
|
|
||||||
// Sources are typically only needed for Firefox submissions
|
|
||||||
const firefoxSourcesZip = browsers.includes("firefox") ? zipSources() : null;
|
|
||||||
|
|
||||||
console.log("Chrome zip:", chromeZip);
|
|
||||||
console.log("Firefox zip:", firefoxZip);
|
|
||||||
console.log("Firefox sources zip:", firefoxSourcesZip);
|
|
||||||
|
|
||||||
if (browsers.length === 0) {
|
|
||||||
console.log("No browsers specified. Exiting.");
|
|
||||||
process.exit(0); // Exit gracefully if no action is needed
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if required files are missing for the specified browsers
|
|
||||||
if (
|
|
||||||
(browsers.includes("chrome") && !chromeZip) ||
|
|
||||||
(browsers.includes("firefox") && (!firefoxZip || !firefoxSourcesZip))
|
|
||||||
) {
|
|
||||||
console.error("Could not find required zip files for specified browsers.");
|
|
||||||
process.exit(1); // Exit with error status
|
|
||||||
}
|
|
||||||
|
|
||||||
let command = "publish-extension";
|
|
||||||
if (chromeZip) {
|
|
||||||
command += ` --chrome-zip ${chromeZip}`;
|
|
||||||
}
|
|
||||||
if (firefoxZip && firefoxSourcesZip) {
|
|
||||||
command += ` --firefox-zip ${firefoxZip} --firefox-sources-zip ${firefoxSourcesZip}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log("Running command:", command);
|
|
||||||
execSync(command, { stdio: "inherit" }); // Execute and show output
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse command-line arguments to determine which browsers to publish for
|
|
||||||
const args = process.argv.slice(2);
|
const args = process.argv.slice(2);
|
||||||
const browserIndex = args.indexOf("--b"); // Find the --b flag
|
const browsers = args.filter((arg) => arg !== "--b" && arg !== "--dry-run");
|
||||||
// If --b is found, take all subsequent arguments as browser names
|
if (!browsers.length || browsers.some((browser) => !["chrome", "firefox"].includes(browser))) {
|
||||||
const browsers = browserIndex !== -1 ? args.slice(browserIndex + 1) : [];
|
throw new Error("Usage: npm run publish -- chrome firefox [--dry-run]");
|
||||||
|
}
|
||||||
|
|
||||||
runPublishCommand(browsers);
|
const { name, version } = JSON.parse(readFileSync("package.json", "utf8"));
|
||||||
|
if (browsers.includes("firefox")) {
|
||||||
|
execFileSync(
|
||||||
|
process.execPath,
|
||||||
|
["scripts/package-extension-zips.mjs", version, "--sources-only"],
|
||||||
|
{
|
||||||
|
stdio: "inherit",
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const flags = browsers.flatMap((browser) => [
|
||||||
|
`--${browser}-zip`,
|
||||||
|
`dist/${name}@${version}-${browser}.zip`,
|
||||||
|
]);
|
||||||
|
if (browsers.includes("firefox")) {
|
||||||
|
flags.push("--firefox-sources-zip", `dist/${name}@${version}-sources.zip`);
|
||||||
|
}
|
||||||
|
if (args.includes("--dry-run")) flags.push("--dry-run");
|
||||||
|
execFileSync(
|
||||||
|
process.execPath,
|
||||||
|
[fileURLToPath(import.meta.resolve("publish-browser-extension/cli")), ...flags],
|
||||||
|
{ stdio: "inherit" },
|
||||||
|
);
|
||||||
@@ -12,24 +12,14 @@ function zipDirectory(sourceRel, outRel) {
|
|||||||
const sourceDir = join(root, sourceRel);
|
const sourceDir = join(root, sourceRel);
|
||||||
const outZip = join(root, outRel);
|
const outZip = join(root, outRel);
|
||||||
if (!existsSync(sourceDir)) throw new Error(`Missing build output: ${sourceRel}`);
|
if (!existsSync(sourceDir)) throw new Error(`Missing build output: ${sourceRel}`);
|
||||||
|
const manifest = JSON.parse(readFileSync(join(sourceDir, "manifest.json"), "utf8"));
|
||||||
|
if (manifest.version !== version) throw new Error(`Rebuild ${sourceRel} for version ${version}`);
|
||||||
|
|
||||||
mkdirSync(dirname(outZip), { recursive: true });
|
mkdirSync(dirname(outZip), { recursive: true });
|
||||||
if (existsSync(outZip)) unlinkSync(outZip);
|
if (existsSync(outZip)) unlinkSync(outZip);
|
||||||
|
|
||||||
if (process.platform === "win32") {
|
if (process.platform === "win32") {
|
||||||
const esc = (s) => s.replace(/'/g, "''");
|
execFileSync("tar", ["-a", "-cf", outZip, "-C", sourceDir, "."], { stdio: "inherit" });
|
||||||
execFileSync(
|
|
||||||
"powershell",
|
|
||||||
[
|
|
||||||
"-NoProfile",
|
|
||||||
"-Command",
|
|
||||||
[
|
|
||||||
"Add-Type -AssemblyName System.IO.Compression.FileSystem",
|
|
||||||
`[IO.Compression.ZipFile]::CreateFromDirectory('${esc(sourceDir)}', '${esc(outZip)}')`,
|
|
||||||
].join("; "),
|
|
||||||
],
|
|
||||||
{ stdio: "inherit" },
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
execFileSync("zip", ["-r", "-q", outZip, "."], { cwd: sourceDir, stdio: "inherit" });
|
execFileSync("zip", ["-r", "-q", outZip, "."], { cwd: sourceDir, stdio: "inherit" });
|
||||||
}
|
}
|
||||||
@@ -47,10 +37,41 @@ const base =
|
|||||||
const chromeZip = `dist/${base}-chrome.zip`;
|
const chromeZip = `dist/${base}-chrome.zip`;
|
||||||
const firefoxZip = `dist/${base}-firefox.zip`;
|
const firefoxZip = `dist/${base}-firefox.zip`;
|
||||||
|
|
||||||
zipDirectory("dist/chrome", chromeZip);
|
if (!process.argv.includes("--sources-only")) {
|
||||||
zipDirectory("dist/firefox", firefoxZip);
|
zipDirectory("dist/chrome", chromeZip);
|
||||||
console.log(`Packaged ${chromeZip}\nPackaged ${firefoxZip}`);
|
zipDirectory("dist/firefox", firefoxZip);
|
||||||
|
console.log(`Packaged ${chromeZip}\nPackaged ${firefoxZip}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const sourcesZip = `dist/${base}-sources.zip`;
|
||||||
|
if (process.argv.includes("--sources") || process.argv.includes("--sources-only")) {
|
||||||
|
// Archive the committed source only, never local credentials or dependency folders.
|
||||||
|
execFileSync("git", ["diff", "--quiet", "HEAD", "--"], { cwd: root, stdio: "inherit" });
|
||||||
|
mkdirSync(join(root, "dist"), { recursive: true });
|
||||||
|
const instructions =
|
||||||
|
`Build environment: ${process.platform} ${process.arch}, Node.js ${process.version}.\n` +
|
||||||
|
"On Windows, run these commands in Git Bash:\n\n" +
|
||||||
|
"npm ci\n" +
|
||||||
|
"GH_RELEASE_UPDATE_CHECK=false UPDATE_CHANNEL=stable npm run build\n\n" +
|
||||||
|
"Firefox output: dist/firefox. No .env file is required.\n";
|
||||||
|
execFileSync(
|
||||||
|
"git",
|
||||||
|
[
|
||||||
|
"archive",
|
||||||
|
"--format=zip",
|
||||||
|
"--output",
|
||||||
|
join(root, sourcesZip),
|
||||||
|
`--add-virtual-file=BUILD.txt:${instructions}`,
|
||||||
|
"HEAD",
|
||||||
|
],
|
||||||
|
{ cwd: root, stdio: "inherit" },
|
||||||
|
);
|
||||||
|
console.log(`Packaged ${sourcesZip}`);
|
||||||
|
}
|
||||||
|
|
||||||
if (process.env.GITHUB_OUTPUT) {
|
if (process.env.GITHUB_OUTPUT) {
|
||||||
appendFileSync(process.env.GITHUB_OUTPUT, `chrome_zip=${chromeZip}\nfirefox_zip=${firefoxZip}\n`);
|
appendFileSync(
|
||||||
|
process.env.GITHUB_OUTPUT,
|
||||||
|
`chrome_zip=${chromeZip}\nfirefox_zip=${firefoxZip}\nsources_zip=${sourcesZip}\n`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user