From 40dc1d9384640863c2125c25c1d8e332c0b2a1db Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 26 Feb 2020 11:56:59 +0000 Subject: [PATCH] Set version in fetch script Which plays better with doing develop builds. --- package.json | 7 +++---- scripts/fetch-package.js | 14 ++++++++++++++ scripts/set-version.js | 35 ++++++++++++++++++++++++++++++++--- 3 files changed, 49 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index a52119c..162a6ab 100644 --- a/package.json +++ b/package.json @@ -14,13 +14,12 @@ "scripts": { "mkdirs": "mkdirp packages deploys", "fetch": "yarn run mkdirs && node scripts/fetch-package.js", - "setversion": "node scripts/set-version.js", "start": "electron .", "lint": "eslint src/ scripts/ hak/", "build:native": "yarn run hak", - "build32": "yarn run setversion && electron-builder --ia32", - "build64": "yarn run setversion && electron-builder --x64", - "build": "yarn run setversion && electron-builder", + "build32": "electron-builder --ia32", + "build64": "electron-builder --x64", + "build": "electron-builder", "docker:setup": "docker build -t riot-desktop-dockerbuild dockerbuild", "docker:build:native": "scripts/in-docker.sh yarn run hak", "docker:build": "scripts/in-docker.sh yarn run build", diff --git a/scripts/fetch-package.js b/scripts/fetch-package.js index c0b2cf6..1ee43c4 100755 --- a/scripts/fetch-package.js +++ b/scripts/fetch-package.js @@ -15,6 +15,8 @@ const PUB_KEY_URL = "https://packages.riot.im/riot-release-key.asc"; const PACKAGE_URL_PREFIX = "https://github.com/vector-im/riot-web/releases/download/"; const ASAR_PATH = 'webapp.asar'; +const {setPackageVersion, setDebVersion} = require('./set-version.js'); + async function getLatestDevelopUrl(bkToken) { const buildsResult = await needle('get', "https://api.buildkite.com/v2/organizations/matrix-dot-org/pipelines/riot-web/builds", @@ -116,6 +118,7 @@ async function main() { let targetVersion; let filename; let url; + let setVersion = false; while (process.argv.length > 2) { switch (process.argv[2]) { @@ -146,6 +149,8 @@ async function main() { if (targetVersion === undefined) { targetVersion = 'v' + riotDesktopPackageJson.version; + filename = 'riot-' + targetVersion + '.tar.gz'; + url = PACKAGE_URL_PREFIX + targetVersion + '/' + filename; } else if (targetVersion === 'develop') { const buildKiteApiKey = process.env.BUILDKITE_API_KEY; if (buildKiteApiKey === undefined) { @@ -161,6 +166,7 @@ async function main() { } else { filename = 'riot-' + targetVersion + '.tar.gz'; url = PACKAGE_URL_PREFIX + targetVersion + '/' + filename; + setVersion = true; } const haveGpg = await new Promise((resolve) => { @@ -272,6 +278,14 @@ async function main() { console.log("Pack " + expectedDeployDir + " -> " + ASAR_PATH); await asar.createPackage(expectedDeployDir, ASAR_PATH); + + if (setVersion) { + const semVer = targetVersion.slice(1); + console.log("Updating version to " + semVer); + await setPackageVersion(semVer); + await setDebVersion(semVer); + } + console.log("Done!"); } diff --git a/scripts/set-version.js b/scripts/set-version.js index 9e1735b..897b514 100755 --- a/scripts/set-version.js +++ b/scripts/set-version.js @@ -9,7 +9,7 @@ const fs = require('fs').promises; const asar = require('asar'); const childProcess = require('child_process'); -async function main() { +async function versionFromAsar() { try { await fs.stat('webapp.asar'); } catch (e) { @@ -17,8 +17,10 @@ async function main() { return 1; } - const ver = asar.extractFile('webapp.asar', 'version').toString().trim(); + return asar.extractFile('webapp.asar', 'version').toString().trim(); +} +async function setPackageVersion(ver) { // set version in package.json: electron-builder will use this to populate // all the various version fields await new Promise((resolve, reject) => { @@ -36,7 +38,9 @@ async function main() { } }); }); +} +async function setDebVersion(ver) { // Also create a debian package control file with the version. // We use a custom control file so we need to do this ourselves const outFile = await fs.open('pkg/control', 'w'); @@ -48,4 +52,29 @@ async function main() { console.log("Version set to " + ver); } -main().then((ret) => process.exit(ret)); +async function main(args) { + let setDeb = false; + let setPkg = false; + let version; + + for (const arg of args) { + if (arg === '--deb') { + setDeb = true; + } else if (arg === '--pkg') { + setPkg = true; + } else { + version = arg; + } + } + + if (version === undefined) version = await versionFromAsar(); + + if (setPkg) setDebVersion(ver); + if (setDeb) setDebVersion(ver); +} + +if (require.main === module) { + main(process.argv.slice(2)).then((ret) => process.exit(ret)); +} + +module.exports = {versionFromAsar, setPackageVersion, setDebVersion};