From 30266e5107fa5685c0257a86452e0d7ec91c3af0 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Mon, 25 Aug 2025 15:10:36 -0400 Subject: [PATCH] Improve publish scripts --- Makefile | 9 ++++++++- dist/chromium/publish-chromium.js | 17 ++++++++++++---- dist/edge/publish-edge.js | 33 ++++++++++++++++--------------- dist/github-api.js | 24 ++++++++++++++++++++++ 4 files changed, 62 insertions(+), 21 deletions(-) diff --git a/Makefile b/Makefile index ddec8e4dc..b7149a169 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,8 @@ run_options := $(filter-out $@,$(MAKECMDGOALS)) .PHONY: all clean cleanassets test lint chromium opera firefox npm dig \ mv3-chromium mv3-firefox mv3-edge mv3-safari ubol-codemirror \ - compare maxcost medcost mincost modifiers record wasm + compare maxcost medcost mincost modifiers record wasm \ + publish-chromium publish-edge sources := ./dist/version $(shell find ./assets -type f) $(shell find ./src -type f) platform := $(wildcard platform/*/*) @@ -105,6 +106,12 @@ clean: cleanassets: rm -rf dist/build/mv3-data dist/build/uAssets +publish-chromium: + node dist/chromium/publish-chromium.js ghowner=gorhill ghrepo=uBlock ghtag=$(version) cwsid=cjpalhdlnbpafiamejdnhcphjbkeiagm + +publish-edge: + node dist/edge/publish-edge.js ghowner=gorhill ghrepo=uBlock ghtag=$(version) edgeid=$(UBO_EDGE_ID) + # Not real targets, just convenient for auto-completion at shell prompt compare: @echo diff --git a/dist/chromium/publish-chromium.js b/dist/chromium/publish-chromium.js index b309df140..cc4d8bdd0 100644 --- a/dist/chromium/publish-chromium.js +++ b/dist/chromium/publish-chromium.js @@ -119,15 +119,24 @@ async function publishToCWS(filePath) { async function main() { if ( githubOwner === '' ) { return 'Need GitHub owner'; } if ( githubRepo === '' ) { return 'Need GitHub repo'; } + if ( githubTag === '' ) { return 'Need GitHub tag'; } ghapi.setGithubContext(githubOwner, githubRepo, githubTag, githubAuth); const assetInfo = await ghapi.getAssetInfo('chromium'); + if ( assetInfo === undefined ) { + process.exit(1); + } - console.log(`GitHub owner: "${githubOwner}"`); - console.log(`GitHub repo: "${githubRepo}"`); - console.log(`Release tag: "${githubTag}"`); - console.log(`Release asset: "${assetInfo.name}"`); + await ghapi.prompt([ + 'Publish to Chrome store:', + ` GitHub owner: "${githubOwner}"`, + ` GitHub repo: "${githubRepo}"`, + ` Release tag: "${githubTag}"`, + ` Asset name: "${assetInfo.name}"`, + ` Extension id: ${cwsId}`, + ` Publish? (enter "yes"): `, + ].join('\n')); // Fetch asset from GitHub repo const filePath = await ghapi.downloadAssetFromRelease(assetInfo); diff --git a/dist/edge/publish-edge.js b/dist/edge/publish-edge.js index 6a27168a8..aec182fe8 100644 --- a/dist/edge/publish-edge.js +++ b/dist/edge/publish-edge.js @@ -35,17 +35,9 @@ const edgeId = commandLineArgs.edgeid; /******************************************************************************/ -async function sleep(seconds) { - return new Promise(resolve => { - setTimeout(resolve, seconds * 1000); - }); -} - -/******************************************************************************/ - async function publishToEdgeStore(filePath) { - const edgeApiKey = process.env.EDGE_APIKEY; - const edgeClientId = process.env.EDGE_CLIENTID; + const edgeApiKey = process.env.EDGE_API_KEY; + const edgeClientId = process.env.EDGE_CLIENT_ID; const uploadURL = `https://api.addons.microsoftedge.microsoft.com/v1/products/${edgeId}/submissions/draft/package`; // Read package @@ -79,7 +71,7 @@ async function publishToEdgeStore(filePath) { const interval = 60; // check every 60 seconds let countdown = 60 * 60 / interval; // for at most 60 minutes for (;;) { - await sleep(interval); + await ghapi.sleep(interval); countdown -= 1 if ( countdown <= 0 ) { console.log('Error: Microsoft store timed out') @@ -139,15 +131,24 @@ async function publishToEdgeStore(filePath) { async function main() { if ( githubOwner === '' ) { return 'Need GitHub owner'; } if ( githubRepo === '' ) { return 'Need GitHub repo'; } + if ( githubTag === '' ) { return 'Need GitHub tag'; } ghapi.setGithubContext(githubOwner, githubRepo, githubTag, githubAuth); - const assetInfo = await ghapi.getAssetInfo('edge'); + const assetInfo = await ghapi.getAssetInfo('chromium'); + if ( assetInfo === undefined ) { + process.exit(1); + } - console.log(`GitHub owner: "${githubOwner}"`); - console.log(`GitHub repo: "${githubRepo}"`); - console.log(`Release tag: "${githubTag}"`); - console.log(`Release asset: "${assetInfo.name}"`); + await ghapi.prompt([ + 'Publish to Edge store:', + `GitHub owner: "${githubOwner}"`, + `GitHub repo: "${githubRepo}"`, + `Release tag: "${githubTag}"`, + `Asset name: "${assetInfo.name}"`, + `Product id: ${edgeId}`, + `Publish? (enter "yes"): `, + ].join('\n')); // Fetch asset from GitHub repo const filePath = await ghapi.downloadAssetFromRelease(assetInfo); diff --git a/dist/github-api.js b/dist/github-api.js index 6cac6660a..cece67cf7 100644 --- a/dist/github-api.js +++ b/dist/github-api.js @@ -20,6 +20,7 @@ */ import * as fs from 'node:fs/promises'; +import * as readline from 'node:readline/promises'; import { execSync } from 'node:child_process'; import os from 'node:os'; import path from 'node:path'; @@ -32,6 +33,29 @@ function voidFunc() { /******************************************************************************/ +export async function sleep(seconds) { + return new Promise(resolve => { + setTimeout(resolve, seconds * 1000); + }); +} + +/******************************************************************************/ + +export async function prompt(message) { + const rl = readline.createInterface({ + input: process.stdin, + output: process.stdout, + }); + const answer = await rl.question(message); + if ( answer !== 'yes' ) { + console.log('Aborted'); + process.exit(1); + } + return true; +} + +/******************************************************************************/ + function reportFetchError(response) { console.log(response.statusText); }