Improve publish scripts

This commit is contained in:
Raymond Hill 2025-08-25 15:10:36 -04:00
parent 69fa0c2e09
commit 30266e5107
No known key found for this signature in database
GPG key ID: 25E1490B761470C2
4 changed files with 62 additions and 21 deletions

View file

@ -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

View file

@ -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);

View file

@ -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);

24
dist/github-api.js vendored
View file

@ -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);
}