From 2ad20c781d147ef7206e7714ff474ffd8acfa0e4 Mon Sep 17 00:00:00 2001 From: Dan Rosser Date: Mon, 9 Nov 2026 16:36:22 +1100 Subject: [PATCH 1/4] Enable ASAR packaging with unpacked generators and writable preferences --- .github/workflows/build-linux.yml | 3 ++ .github/workflows/build-vs.yml | 1 + frontend/index.js | 15 +++--- frontend/package.json | 10 ++-- frontend/packaged-paths.js | 32 +++++++++++++ frontend/readme.md | 1 + scripts/linux/test_cmdline.sh | 3 ++ scripts/osx/ci_build_pg.sh | 8 ++-- scripts/osx/test_cmdline.sh | 3 ++ scripts/test_asar_package.cjs | 30 ++++++++++++ scripts/test_packaged_paths.cjs | 76 +++++++++++++++++++++++++++++++ scripts/vs/test_cmdline.sh | 3 ++ 12 files changed, 169 insertions(+), 16 deletions(-) create mode 100644 frontend/packaged-paths.js create mode 100644 scripts/test_asar_package.cjs create mode 100644 scripts/test_packaged_paths.cjs diff --git a/.github/workflows/build-linux.yml b/.github/workflows/build-linux.yml index da28655a0..328839e8c 100644 --- a/.github/workflows/build-linux.yml +++ b/.github/workflows/build-linux.yml @@ -95,6 +95,7 @@ jobs: npm install npm update npm run dist:linux64 + node ../scripts/test_asar_package.cjs dist/linux-unpacked/resources cd dist pwd ls @@ -187,6 +188,7 @@ jobs: npm install npm update npm run dist:linux64 + node ../scripts/test_asar_package.cjs dist/linux-unpacked/resources - name: Copy GUI tarball to root directory run: | @@ -271,6 +273,7 @@ jobs: npm install npm update npm run dist:linux:arm64 + node ../scripts/test_asar_package.cjs dist/linux-arm64-unpacked/resources - name: Copy GUI tarball to root directory run: | diff --git a/.github/workflows/build-vs.yml b/.github/workflows/build-vs.yml index 518ef68b1..d1f92cca7 100644 --- a/.github/workflows/build-vs.yml +++ b/.github/workflows/build-vs.yml @@ -100,6 +100,7 @@ jobs: npm install npm update npm run dist:win64 + node ../scripts/test_asar_package.cjs dist/win-unpacked/resources cd dist pwd ls diff --git a/frontend/index.js b/frontend/index.js index 3f1de9307..20e08e228 100644 --- a/frontend/index.js +++ b/frontend/index.js @@ -6,6 +6,7 @@ const process = require('process'); const os = require("os"); const { execFile, spawn } = require('child_process'); const { readProjectSettings } = require('./project-settings'); +const { bundledGeneratorPath, settingsStore } = require('./packaged-paths'); const { app, @@ -204,9 +205,9 @@ console.log(`Detected platform: ${platformId}`); console.log(`Default template: ${defaultTemplate}`); +const savedSettings = settingsStore(__dirname, app.getPath('userData'), app.isPackaged); try { - const settingsJsonString = fs.readFileSync(path.resolve(__dirname, 'settings.json'), 'utf-8'); - settings = JSON.parse(settingsJsonString); + settings = savedSettings.read(); console.log(settings); // older settings stored the template label (has spaces) instead of the platform id @@ -1157,14 +1158,10 @@ ipcMain.on('getRandomSketchName', (event, projectPath) => { function getPgPath() { let pgApp = ""; try { - if (hostplatform == "linux" || hostplatform == "linux64") { // ???: when appear there linux64? + if (!app.isPackaged && (hostplatform == "linux" || hostplatform == "linux64")) { pgApp = path.join(defaultOfPath, "apps/projectGenerator/commandLine/bin/projectGenerator"); } else { - pgApp = path.normalize(path.join(__dirname, "app", "projectGenerator")); - } - - if (hostplatform == "windows") { - pgApp += ".exe"; + pgApp = bundledGeneratorPath(__dirname); } } catch (error) { console.error("Error determining project generator path:", error); @@ -2465,7 +2462,7 @@ ipcMain.on('saveDefaultSettings', (event, defaultSettings) => { // fs.writeFile is async and would resolve after that, so a quit right after e.g. // picking a new OF path could race past the actual disk write and lose it (#602) try { - fs.writeFileSync(path.resolve(__dirname, 'settings.json'), defaultSettings); + savedSettings.write(defaultSettings); event.returnValue = "Updated default settings for the PG. (written to settings.json)"; } catch (err) { event.returnValue = "Unable to save defaultSettings to settings.json... (Error=" + err.code + ")"; diff --git a/frontend/package.json b/frontend/package.json index 4c2d76ffe..4fca9bf5a 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -25,7 +25,7 @@ "dist:linux": "electron-builder --linux --publish never", "dist:linux64": "electron-builder --linux --x64 --publish never", "dist:linux:arm64": "electron-builder --linux --arm64 --publish never", - "build:linux64": "electron-packager . $npm_package_productName --icon=static/icon/of.icns --out=dist --ignore='dist' --ignore='readme.md' --prune --overwrite --electron-version=45.2.3 --platform=linux --arch=x64" + "build:linux64": "electron-packager . $npm_package_productName --icon=static/icon/of.icns --out=dist --ignore='dist' --ignore='readme.md' --prune --overwrite --electron-version=45.2.3 --asar.unpack='app/**/*' --platform=linux --arch=x64" }, "build": { "appId": "cc.openframeworks.projectGenerator", @@ -43,8 +43,8 @@ "arm64" ] }, - "mergeASARs": false, - "x64ArchFiles": "Contents/Resources/app/app/projectGenerator" + "mergeASARs": true, + "x64ArchFiles": "Contents/Resources/app.asar.unpacked/app/projectGenerator" }, "win": { "icon": "static/icon/of.ico", @@ -65,6 +65,7 @@ "app/**/*", "static/**/*", "index.js", + "packaged-paths.js", "app.js", "project-settings.js", "preload.js", @@ -82,7 +83,8 @@ ] } ], - "asar": false + "asar": true, + "asarUnpack": ["app/**/*"] }, "keywords": [ "electron-app" diff --git a/frontend/packaged-paths.js b/frontend/packaged-paths.js new file mode 100644 index 000000000..e770b11ee --- /dev/null +++ b/frontend/packaged-paths.js @@ -0,0 +1,32 @@ +const fs = require('node:fs'); +const path = require('node:path'); + +function bundledGeneratorPath(appDirectory, platform = process.platform) { + const directory = path.basename(appDirectory) === 'app.asar' ? appDirectory + '.unpacked' : appDirectory; + return path.join(directory, 'app', platform === 'win32' ? 'projectGenerator.exe' : 'projectGenerator'); +} + +function settingsStore(appDirectory, userDataDirectory, packaged) { + const filename = path.join(packaged ? userDataDirectory : appDirectory, 'settings.json'); + const candidates = [filename]; + if (packaged) { + candidates.push(path.join(appDirectory, 'settings.json')); + if (path.basename(appDirectory) === 'app.asar') candidates.push(path.join(path.dirname(appDirectory), 'app', 'settings.json')); + } + return { + filename, + read() { + for (const file of candidates) { + try { return JSON.parse(fs.readFileSync(file, 'utf8')); } + catch (error) { if (error.code !== 'ENOENT') throw error; } + } + throw Object.assign(new Error('No saved settings'), { code: 'ENOENT' }); + }, + write(contents) { + fs.mkdirSync(path.dirname(filename), { recursive: true }); + fs.writeFileSync(filename, contents); + }, + }; +} + +module.exports = { bundledGeneratorPath, settingsStore }; diff --git a/frontend/readme.md b/frontend/readme.md index 32b87864a..bb8086798 100644 --- a/frontend/readme.md +++ b/frontend/readme.md @@ -66,6 +66,7 @@ npm update ### Debugging You can open `settings.json` to enable some hidden settings, useful for debugging. +Packaged apps save it in Electron's user data directory: `~/Library/Application Support/projectGenerator` on macOS, `%APPDATA%/projectGenerator` on Windows, or `$XDG_CONFIG_HOME/projectGenerator` (usually `~/.config/projectGenerator`) on Linux. Development runs continue to use `frontend/settings.json`. Moreover, Electron uses Webkit so all the Webkit developper tools are available to you. ( `Cmd/Ctrl` + `Shift` + `i` from the Electron window.) - Console messages from `index.js` show up in the terminal (where you did `npm start`). diff --git a/scripts/linux/test_cmdline.sh b/scripts/linux/test_cmdline.sh index d575e63db..295cd2768 100755 --- a/scripts/linux/test_cmdline.sh +++ b/scripts/linux/test_cmdline.sh @@ -54,4 +54,7 @@ python3 "${CURRENT_DIR}/../test_xcode_settings.py" ./projectGenerator ../../../. echo "Test existing-project GUI settings and update arguments" node --test "${CURRENT_DIR}/../test_gui_project_settings.cjs" +echo "Test packaged executable paths and writable settings" +node --test "${CURRENT_DIR}/../test_packaged_paths.cjs" + echo "Successful projectGenerator tests for [linux64]"; diff --git a/scripts/osx/ci_build_pg.sh b/scripts/osx/ci_build_pg.sh index 6b7543961..116f52148 100755 --- a/scripts/osx/ci_build_pg.sh +++ b/scripts/osx/ci_build_pg.sh @@ -62,7 +62,7 @@ package_app(){ echo "-------------" echo "Copy cmdline PG from app contents (signed)" SOURCE_FILE="commandLine/bin/commandLine.app/Contents/MacOS/commandLine" - DEST_FILE="projectGenerator-$PLATFORM/projectGenerator.app/Contents/Resources/app/app/projectGenerator" + DEST_FILE="projectGenerator-$PLATFORM/projectGenerator.app/Contents/Resources/app.asar.unpacked/app/projectGenerator" # Check if source file exists if [ ! -f "$SOURCE_FILE" ]; then @@ -75,7 +75,7 @@ package_app(){ # Check destination directory exists; if not, print error if [ ! -d "$(dirname "$DEST_FILE")" ]; then echo "Error: Destination directory does not exist: $(dirname "$DEST_FILE")" - ls -lah projectGenerator-$PLATFORM/projectGenerator.app/Contents/Resources/app/app/ + ls -lah projectGenerator-$PLATFORM/projectGenerator.app/Contents/Resources/app.asar.unpacked/app/ exit 12 fi @@ -96,6 +96,8 @@ package_app(){ exit 13 fi + node "${PG_DIR}/scripts/test_asar_package.cjs" "${PG_DIR}/projectGenerator-$PLATFORM/projectGenerator.app/Contents/Resources" + cd ${PG_DIR} echo "Current directory: (should be projectGenerator) $(pwd)" echo "Directory contents:" @@ -146,7 +148,7 @@ sign_and_upload(){ PLATFORM=$1 # Copy commandLine into electron .app cd ${PG_DIR} - cp commandLine/bin/projectGenerator projectGenerator-$PLATFORM/projectGenerator.app/Contents/Resources/app/app/projectGenerator 2> /dev/null + cp commandLine/bin/projectGenerator projectGenerator-$PLATFORM/projectGenerator.app/Contents/Resources/app.asar.unpacked/app/projectGenerator 2> /dev/null # sed -i -e "s/osx/$PLATFORM/g" projectGenerator-$PLATFORM/projectGenerator.app/Contents/Resources/app/settings.json diff --git a/scripts/osx/test_cmdline.sh b/scripts/osx/test_cmdline.sh index 95329f114..396d92b77 100755 --- a/scripts/osx/test_cmdline.sh +++ b/scripts/osx/test_cmdline.sh @@ -52,6 +52,9 @@ python3 "${CURRENT_DIR}/../test_xcode_settings.py" ./projectGenerator "${PG_DIR} echo "Test 6: existing-project GUI settings and update arguments" node --test "${CURRENT_DIR}/../test_gui_project_settings.cjs" || exit 1 +echo "Test packaged executable paths and writable settings" +node --test "${CURRENT_DIR}/../test_packaged_paths.cjs" || exit 1 + # echo "test out of folder -o [vs]"; # rm -rf ../../../../../pg2 # mkdir -p ../../../../../pg2 diff --git a/scripts/test_asar_package.cjs b/scripts/test_asar_package.cjs new file mode 100644 index 000000000..2e73f388c --- /dev/null +++ b/scripts/test_asar_package.cjs @@ -0,0 +1,30 @@ +// Run after packaging, on the same host platform/architecture as the bundled generator: +// node scripts/test_asar_package.cjs /path/to/app/resources +const assert = require('node:assert/strict'); +const fs = require('node:fs'); +const path = require('node:path'); +const { pathToFileURL } = require('node:url'); +const { spawnSync } = require('node:child_process'); +const { bundledGeneratorPath } = require('../frontend/packaged-paths'); + +async function main() { + assert.ok(process.argv[2], 'Pass the packaged app resources directory'); + const archive = path.resolve(process.argv[2], 'app.asar'); + const asar = await import(pathToFileURL(require.resolve('@electron/asar', { paths: [path.join(__dirname, '../frontend')] })).href); + for (const file of ['index.html', 'index.js', 'app.js', 'preload.js', 'packaged-paths.js', 'locales/en.json']) { + assert.ok(asar.extractFile(archive, file).length, `Missing ${file}`); + assert.ok(!asar.statFile(archive, file).unpacked, `${file} should be packed`); + } + assert.equal(asar.extractFile(archive, 'packaged-paths.js').toString(), fs.readFileSync(path.join(__dirname, '../frontend/packaged-paths.js'), 'utf8')); + const generator = bundledGeneratorPath(archive); + const relative = 'app/' + path.basename(generator); + assert.equal(asar.statFile(archive, relative).unpacked, true, 'Native generator must be unpacked'); + const result = spawnSync(generator, ['--version'], { encoding: 'utf8', timeout: 30000, env: { ...process.env, TZ: 'UTC0' } }); + if (result.error) throw result.error; + assert.equal(result.status, 0, result.stderr || result.stdout); + assert.match(result.stdout, /version/); + console.log('ASAR assets, unpacked native generator and spawn --version passed'); + console.log(result.stdout.trim()); +} + +main().catch((error) => { console.error(error); process.exitCode = 1; }); diff --git a/scripts/test_packaged_paths.cjs b/scripts/test_packaged_paths.cjs new file mode 100644 index 000000000..408ae38e5 --- /dev/null +++ b/scripts/test_packaged_paths.cjs @@ -0,0 +1,76 @@ +const test = require('node:test'); +const assert = require('node:assert/strict'); +const fs = require('node:fs'); +const os = require('node:os'); +const path = require('node:path'); +const vm = require('node:vm'); +const { bundledGeneratorPath, settingsStore } = require('../frontend/packaged-paths'); + +function fixture(t) { + const folder = fs.mkdtempSync(path.join(os.tmpdir(), 'pg-packaged-paths-')); + t.after(() => fs.rmSync(folder, { recursive: true, force: true })); + return { app: path.join(folder, 'resources', 'app.asar'), userData: path.join(folder, 'preferences') }; +} + +test('native generators use real unpacked paths on all platforms and development paths stay direct', () => { + const app = path.resolve('resources', 'app.asar'); + for (const platform of ['darwin', 'linux', 'win32']) { + const binary = platform === 'win32' ? 'projectGenerator.exe' : 'projectGenerator'; + assert.equal(bundledGeneratorPath(app, platform), path.join(app + '.unpacked', 'app', binary)); + assert.equal(bundledGeneratorPath(path.resolve('frontend'), platform), path.resolve('frontend', 'app', binary)); + } +}); + +test('packaged preferences persist outside the archive and survive replacing the app directory', (t) => { + const f = fixture(t); + const store = settingsStore(f.app, f.userData, true); + assert.throws(() => store.read(), { code: 'ENOENT' }); + store.write(JSON.stringify({ defaultOfPath: '/my/OF', advancedMode: true })); + assert.deepEqual(store.read(), { defaultOfPath: '/my/OF', advancedMode: true }); + assert.ok(!fs.existsSync(f.app)); + const updated = settingsStore(path.join(path.dirname(f.app), 'replacement', 'app.asar'), f.userData, true); + assert.deepEqual(updated.read(), store.read()); +}); + +test('legacy unpacked preferences migrate on save without changing their original file', (t) => { + const f = fixture(t); + const legacy = path.join(path.dirname(f.app), 'app', 'settings.json'); + fs.mkdirSync(path.dirname(legacy), { recursive: true }); + fs.writeFileSync(legacy, '{"language":"ja"}'); + const store = settingsStore(f.app, f.userData, true); + assert.deepEqual(store.read(), { language: 'ja' }); + assert.ok(!fs.existsSync(store.filename)); + store.write('{"language":"fr"}'); + assert.deepEqual(store.read(), { language: 'fr' }); + assert.equal(fs.readFileSync(legacy, 'utf8'), '{"language":"ja"}'); +}); + +test('development settings stay alongside the source and invalid saved settings are reported', (t) => { + const f = fixture(t); + const directory = path.join(path.dirname(f.app), 'frontend'); + const store = settingsStore(directory, f.userData, false); + store.write('{"advancedMode":true}'); + assert.equal(store.filename, path.join(directory, 'settings.json')); + assert.deepEqual(store.read(), { advancedMode: true }); + store.write('{invalid'); + assert.throws(() => store.read(), SyntaxError); + assert.ok(!fs.existsSync(f.userData)); +}); + +test('main process uses the bundled generator for packaged Linux and preserves the development override', () => { + const source = fs.readFileSync(path.join(__dirname, '../frontend/index.js'), 'utf8'); + const start = source.indexOf('function getPgPath()'); + const end = source.indexOf('// clear error', start); + for (const platform of ['darwin', 'linux', 'win32']) { + const appDirectory = path.resolve('resources', 'app.asar'); + const app = { isPackaged: true }; + const context = vm.createContext({ path, console, app, hostplatform: platform === 'linux' ? 'linux64' : platform === 'win32' ? 'windows' : 'osx', + defaultOfPath: '/of', __dirname: appDirectory, bundledGeneratorPath: (folder) => bundledGeneratorPath(folder, platform) }); + vm.runInContext(source.slice(start, end), context); + assert.equal(vm.runInContext('getPgPath()', context), bundledGeneratorPath(appDirectory, platform)); + if (platform === 'linux') { + app.isPackaged = false; + assert.equal(vm.runInContext('getPgPath()', context), path.join('/of', 'apps/projectGenerator/commandLine/bin/projectGenerator')); + } + } +}); diff --git a/scripts/vs/test_cmdline.sh b/scripts/vs/test_cmdline.sh index 861555497..c14907d3c 100755 --- a/scripts/vs/test_cmdline.sh +++ b/scripts/vs/test_cmdline.sh @@ -99,4 +99,7 @@ fi echo "Test command line arguments" "${CURRENT_DIR}/../test_cmdline_args.sh" ./"${EXE_FILE}" ../openFrameworks vs || exit 1 +echo "Test packaged executable paths and writable settings" +node --test "${CURRENT_DIR}/../test_packaged_paths.cjs" || exit 1 + echo "Successful projectGenerator tests for [vs]" From 45a52f2cd5795b8256bb3b21a0dda0d1a0b74d93 Mon Sep 17 00:00:00 2001 From: Dan Rosser Date: Mon, 9 Nov 2026 17:51:45 +1100 Subject: [PATCH 2/4] CI: run Windows packaging tests with the setup-node environment --- .github/workflows/build-vs.yml | 4 ++++ scripts/vs/test_cmdline.sh | 3 --- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-vs.yml b/.github/workflows/build-vs.yml index d1f92cca7..1d58a41c8 100644 --- a/.github/workflows/build-vs.yml +++ b/.github/workflows/build-vs.yml @@ -88,6 +88,10 @@ jobs: shell: pwsh run: node --test ../openFrameworks/apps/projectGenerator/scripts/test_gui_project_settings.cjs + - name: Test packaged executable paths and writable settings + shell: pwsh + run: node --test ../openFrameworks/apps/projectGenerator/scripts/test_packaged_paths.cjs + - name: Build emptyExample and allAddonsExample if: github.event_name == 'pull_request' || github.ref == 'refs/heads/master' shell: bash diff --git a/scripts/vs/test_cmdline.sh b/scripts/vs/test_cmdline.sh index c14907d3c..861555497 100755 --- a/scripts/vs/test_cmdline.sh +++ b/scripts/vs/test_cmdline.sh @@ -99,7 +99,4 @@ fi echo "Test command line arguments" "${CURRENT_DIR}/../test_cmdline_args.sh" ./"${EXE_FILE}" ../openFrameworks vs || exit 1 -echo "Test packaged executable paths and writable settings" -node --test "${CURRENT_DIR}/../test_packaged_paths.cjs" || exit 1 - echo "Successful projectGenerator tests for [vs]" From 9c4dea3543f33166e15b24632e1b0946f3e1f717 Mon Sep 17 00:00:00 2001 From: Dan Rosser Date: Mon, 9 Nov 2026 18:51:16 +1100 Subject: [PATCH 3/4] Bump GUI version to 0.121.0 --- frontend/npm-shrinkwrap.json | 4 ++-- frontend/package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/frontend/npm-shrinkwrap.json b/frontend/npm-shrinkwrap.json index 5db72abe3..8d2205a66 100644 --- a/frontend/npm-shrinkwrap.json +++ b/frontend/npm-shrinkwrap.json @@ -1,12 +1,12 @@ { "name": "projectGenerator", - "version": "0.120.0", + "version": "0.121.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "projectGenerator", - "version": "0.120.0", + "version": "0.121.0", "license": "MIT", "dependencies": { "@types/jquery": "^3.5.34", diff --git a/frontend/package.json b/frontend/package.json index 4fca9bf5a..f1b3ec3ec 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,7 +1,7 @@ { "name": "projectGenerator", "productName": "projectGenerator", - "version": "0.120.0", + "version": "0.121.0", "description": "Build electron GUI openFrameworks projectGenerator", "license": "MIT", "main": "index.js", From 6db8b1a8b2c44827ad28a4578c620d1d6638255a Mon Sep 17 00:00:00 2001 From: Dan Rosser Date: Mon, 9 Nov 2026 21:09:40 +1100 Subject: [PATCH 4/4] Bump CLI to 0.126.0 and require CLI bumps for GUI releases --- .github/workflows/release-versions.yml | 20 +++++++++ AGENTS.md | 18 +++++++++ README.md | 10 +++++ commandLine/src/defines.h | 2 +- scripts/check_release_versions.py | 56 ++++++++++++++++++++++++++ 5 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/release-versions.yml create mode 100644 AGENTS.md create mode 100644 scripts/check_release_versions.py diff --git a/.github/workflows/release-versions.yml b/.github/workflows/release-versions.yml new file mode 100644 index 000000000..40bd8cf47 --- /dev/null +++ b/.github/workflows/release-versions.yml @@ -0,0 +1,20 @@ +name: Release version policy + +on: + pull_request: + +permissions: + contents: read + +jobs: + release-versions: + runs-on: ubuntu-24.04 + timeout-minutes: 5 + steps: + - uses: actions/checkout@v7.0.1 + with: + fetch-depth: 0 + - name: Check GUI and command-line versions + env: + BASE_SHA: ${{ github.event.pull_request.base.sha }} + run: python3 scripts/check_release_versions.py "$BASE_SHA" diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 000000000..5b0ec90e1 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,18 @@ +# Repository instructions + +## Attribution + +Do not add assistant attribution to commits, pull requests, issues or comments. + +## Release versions + +Whenever the GUI version in `frontend/package.json` increases, also increase the +command-line version in `commandLine/src/defines.h`, including GUI-only, +packaging and dependency releases. Both versions must advance relative to the +PR's base branch; their numbers do not need to match. A CLI-only release does not +require a GUI version bump. + +Keep both root version fields in `frontend/npm-shrinkwrap.json` equal to the GUI +version, and state both GUI and CLI versions in the PR description. Run +`python3 scripts/check_release_versions.py ` before pushing a version +change. See the release version policy in `README.md`. diff --git a/README.md b/README.md index 6cd44c99f..9ae93cf21 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,16 @@ projectGenerator\scripts\osx\setup_environment.sh (first time) ## Contributing +### Release version policy + +Every GUI version bump must also bump the command-line version, including releases +that change only GUI code, packaging or dependencies. Update `frontend/package.json`, +both root version fields in `frontend/npm-shrinkwrap.json`, and +`commandLine/src/defines.h`. GUI and CLI versions are numbered independently; +both must increase relative to the PR's base branch. A CLI-only release can keep +the GUI version unchanged. Include both versions in the PR description. +CI checks this policy with `python3 scripts/check_release_versions.py `. + The project generator is available in two flavors: - A command line utility tool. This option is the most versatile and provides all features. diff --git a/commandLine/src/defines.h b/commandLine/src/defines.h index f253d10bc..1b5ce8258 100644 --- a/commandLine/src/defines.h +++ b/commandLine/src/defines.h @@ -1,5 +1,5 @@ #define OFPROJECTGENERATOR_MAJOR_VERSION "0" -#define OFPROJECTGENERATOR_MINOR_VERSION "125" +#define OFPROJECTGENERATOR_MINOR_VERSION "126" #define OFPROJECTGENERATOR_PATCH_VERSION "0" #define PG_VERSION (OFPROJECTGENERATOR_MAJOR_VERSION "." OFPROJECTGENERATOR_MINOR_VERSION "." OFPROJECTGENERATOR_PATCH_VERSION) diff --git a/scripts/check_release_versions.py b/scripts/check_release_versions.py new file mode 100644 index 000000000..08a07ff76 --- /dev/null +++ b/scripts/check_release_versions.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python3 +"""Require a CLI version bump whenever a PR increases the GUI version.""" +import argparse +import json +import pathlib +import re +import subprocess + + +def version(value): + if not isinstance(value, str) or not re.fullmatch(r"\d+\.\d+\.\d+", value): + raise ValueError(f"expected a major.minor.patch version, got {value!r}") + return tuple(int(part) for part in value.split(".")) + + +def cli_version(contents): + parts = [] + for part in ("MAJOR", "MINOR", "PATCH"): + match = re.search(r'^#define\s+OFPROJECTGENERATOR_' + part + r'_VERSION\s+"(\d+)"\s*$', contents, re.MULTILINE) + if not match: + raise ValueError(f"missing command-line {part} version") + parts.append(int(match[1])) + return tuple(parts) + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("base", help="PR base commit or branch, for example upstream/master") + args = parser.parse_args() + root = pathlib.Path(subprocess.check_output(["git", "rev-parse", "--show-toplevel"], text=True).strip()) + + def previous(file): + return subprocess.check_output(["git", "show", f"{args.base}:{file}"], cwd=root, text=True) + + package = json.loads((root / "frontend/package.json").read_text()) + lock = json.loads((root / "frontend/npm-shrinkwrap.json").read_text()) + gui = version(package["version"]) + cli = cli_version((root / "commandLine/src/defines.h").read_text()) + old_gui = version(json.loads(previous("frontend/package.json"))["version"]) + old_cli = cli_version(previous("commandLine/src/defines.h")) + + if lock["version"] != package["version"] or lock["packages"][""]["version"] != package["version"]: + raise ValueError("both npm-shrinkwrap.json root versions must match frontend/package.json") + if gui < old_gui or cli < old_cli: + raise ValueError("GUI and command-line versions must not decrease relative to the base") + if gui > old_gui and cli <= old_cli: + raise ValueError("a GUI version bump also requires a command-line version bump in commandLine/src/defines.h") + + print(f"Release versions OK: GUI {'.'.join(map(str, gui))}, CLI {'.'.join(map(str, cli))}") + + +if __name__ == "__main__": + try: + main() + except (ValueError, KeyError, subprocess.CalledProcessError) as error: + raise SystemExit(f"Release version check failed: {error}")