Skip to content

Commit

Permalink
Merge pull request #217 from mbektas/improve_versioning
Browse files Browse the repository at this point in the history
improve versioning
  • Loading branch information
mbektas committed Sep 18, 2021
2 parents fe4d579 + 265bbf7 commit 3db6ee6
Show file tree
Hide file tree
Showing 9 changed files with 412 additions and 28 deletions.
2 changes: 1 addition & 1 deletion electron-builder-scripts/linux_after_install.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
./opt/JupyterLab/resources/env_installer/JupyterLabAppServer-3.1.12-Linux-x86_64.sh -b -p "/opt/JupyterLab/resources/jlab_server"
./opt/JupyterLab/resources/env_installer/JupyterLabAppServer-3.1.12-1-Linux-x86_64.sh -b -p "/opt/JupyterLab/resources/jlab_server"
2 changes: 1 addition & 1 deletion electron-builder-scripts/postinstall
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash

"$2/JupyterLab.app/Contents/Resources/env_installer/JupyterLabAppServer-3.1.12-MacOSX-x86_64.sh" -b -p "$2/JupyterLab.app/Contents/Resources/jlab_server"
"$2/JupyterLab.app/Contents/Resources/env_installer/JupyterLabAppServer-3.1.12-1-MacOSX-x86_64.sh" -b -p "$2/JupyterLab.app/Contents/Resources/jlab_server"

exit 0
2 changes: 1 addition & 1 deletion electron-builder-scripts/wininstall.nsh
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
!macroend

!macro customInstall
ExecWait "$INSTDIR\resources\env_installer\JupyterLabAppServer-3.1.12-Windows-x86_64.exe"
ExecWait "$INSTDIR\resources\env_installer\JupyterLabAppServer-3.1.12-1-Windows-x86_64.exe"
!macroend
2 changes: 1 addition & 1 deletion env_installer/construct.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: JupyterLabAppServer
version: 3.1.12
version: 3.1.12-1
company: "Project Jupyter"

welcome_image_text: "JupyterLab"
Expand Down
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jupyterlab_app",
"version": "3.1.12",
"version": "3.1.12-1",
"description": "A native app for JupyterLab, based on electron.",
"main": "./build/out/main/main.js",
"scripts": {
Expand All @@ -27,7 +27,8 @@
"dockerdist:win": "docker run --rm -ti -v ${PWD}:/project -v ${PWD##*/}-node-modules:/project/node_modules -v ~/.electron:/root/.electron electronuserland/builder:wine /bin/bash -c \"yarn && yarn dist:win\"",
"create_env_installer:linux": "rimraf ./env_installer/JupyterLab*.sh && constructor ./env_installer --platform=linux-64 --output-dir ./env_installer",
"create_env_installer:mac": "rimraf ./env_installer/JupyterLab*.sh && constructor ./env_installer --platform=osx-64 --output-dir ./env_installer",
"create_env_installer:win": "rimraf ./env_installer/JupyterLab*.exe && constructor ./env_installer --platform=win-64 --output-dir ./env_installer"
"create_env_installer:win": "rimraf ./env_installer/JupyterLab*.exe && constructor ./env_installer --platform=win-64 --output-dir ./env_installer",
"check_version_match": "node scripts/buildutil.js --check-version-match"
},
"build": {
"productName": "JupyterLab",
Expand All @@ -43,9 +44,7 @@
"!env_installer/JupyterLab*.*"
],
"extraResources": [
"env_installer/JupyterLabAppServer-3.1.12-MacOSX-x86_64.sh",
"env_installer/JupyterLabAppServer-3.1.12-Linux-x86_64.sh",
"env_installer/JupyterLabAppServer-3.1.12-Windows-x86_64.exe"
"env_installer/JupyterLabAppServer-*[.sh,.exe]"
],
"linux": {
"target": [
Expand Down Expand Up @@ -114,11 +113,14 @@
"repository": "github:jupyterlab/jupyterlab",
"license": "BSD-3-Clause",
"devDependencies": {
"@yarnpkg/lockfile": "~1.1.0",
"css-loader": "~5.1.1",
"electron": "^10.1.3",
"electron-builder": "^22.10.5",
"file-loader": "~6.2.0",
"fs-extra": "~9.1.0",
"js-yaml": "^4.1.0",
"meow": "^6.0.1",
"mini-css-extract-plugin": "^1.3.9",
"node-watch": "^0.7.1",
"raw-loader": "^4.0.2",
Expand Down
160 changes: 160 additions & 0 deletions scripts/buildutil.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
const meow = require("meow");
const fs = require("fs-extra");
const path = require("path");
const semver = require("semver");
const lockfile = require("@yarnpkg/lockfile");
const yaml = require("js-yaml");

const platform = process.platform;

const cli = meow(
`
Usage
$ node buildutil <options>
Options
--check-version-match check for JupyterLab version match
Other options:
--help show usage information
--version show version information
Examples
$ node buildutil --check-version-match
`,
{
flags: {
checkVersionMatch: {
type: "boolean",
default: false,
},
},
}
);

const searchTextInFile = (filePath, text) => {
try {
const fileContent = fs.readFileSync(filePath, "utf8");
return fileContent.includes(text);
} catch (e) {
console.error('Error searching for file content', e);
}

return false;
};

if (cli.flags.checkVersionMatch) {
// parse App version
const pkgjsonFilePath = path.resolve(__dirname, "../package.json");
const pkgjsonFileData = fs.existsSync(pkgjsonFilePath)
? fs.readJSONSync(pkgjsonFilePath)
: undefined;
if (!pkgjsonFileData) {
console.error("package.json not found!");
process.exit(1);
}

const appVersion = pkgjsonFileData["version"];
console.log(`JupyterLab App version: ${appVersion}`);

// parse JupyterLab version bundled to App UI
const yarnlockFilePath = path.resolve(__dirname, "../yarn.lock");
if (!fs.existsSync(yarnlockFilePath)) {
console.error("yarn.lock not found!");
process.exit(1);
}

const yarnLockFileContent = fs.readFileSync(yarnlockFilePath, "utf8");
const yarnLockData = lockfile.parse(yarnLockFileContent).object;
const yarnPackages = Object.keys(yarnLockData);
const metapackage = yarnPackages.find((pkg) =>
pkg.startsWith("@jupyterlab/metapackage")
);
if (!metapackage) {
console.error("@jupyterlab/metapackage not found!");
process.exit(1);
}

const jlabVersion = yarnLockData[metapackage].version;
console.log(`JupyterLab version: ${jlabVersion}`);

if (
!semver.valid(appVersion) ||
!semver.valid(jlabVersion) ||
semver.major(appVersion) !== semver.major(jlabVersion) ||
semver.minor(appVersion) !== semver.minor(jlabVersion) ||
semver.patch(appVersion) !== semver.patch(jlabVersion)
) {
console.error(
`App package version ${appVersion} doesn't match bundled JupyterLab version ${jlabVersion}`
);
process.exit(1);
}

// check JupyterLab version bundled to App Server
const constructorData = yaml.load(
fs.readFileSync(
path.resolve(__dirname, "../env_installer/construct.yaml"),
"utf8"
)
);
const appServerVersion = constructorData["version"];
console.log(`App Server version: ${appServerVersion}`);

if (appServerVersion !== appVersion) {
console.error(
`App Server version ${appServerVersion} doesn't match App version ${appVersion}`
);
process.exit(1);
}

const jlabCondaPkg = constructorData["specs"].find((pkg) => pkg.startsWith("jupyterlab"));
if (!jlabCondaPkg) {
console.error("jupyterlab conda package not found in environment specs!");
process.exit(1);
}
const specParts = jlabCondaPkg.split(" ");
const appServerJLabVersion = specParts[1];
console.log(`App Server JupyterLab version: ${appServerJLabVersion}`);

if (appServerJLabVersion !== jlabVersion) {
console.error(
`App Server package version ${appServerJLabVersion} doesn't match bundled JupyterLab version ${jlabVersion}`
);
process.exit(1);
}

// check JupyterLab versions in scripts
const envInstallerScriptName =
platform === "darwin"
? "postinstall"
: platform === "win32"
? "electron-builder-scripts/wininstall.nsh"
: "electron-builder-scripts/linux_after_install.sh";
const envInstallScriptPath = path.resolve(
__dirname,
`../electron-builder-scripts/${envInstallerScriptName}`
);
let searchString = `JupyterLabAppServer-${appVersion}-`;
if (!searchTextInFile(envInstallScriptPath, searchString)) {
console.error(
`Script file ${envInstallScriptPath} doesn't contain correct App version ${appVersion}`
);
process.exit(1);
}

searchString = `"appVersion": "${appVersion}",`;
if (
!searchTextInFile(
path.resolve(__dirname, `../src/browser/index.html`),
searchString
)
) {
console.error(
`src/index.html doesn't contain correct App version ${appVersion}`
);
process.exit(1);
}

process.exit(0);
}
2 changes: 1 addition & 1 deletion src/browser/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<title>JupyterLab</title>

<script id="jupyter-config-data" type="application/json">{
"appVersion": "3.1.12",
"appVersion": "3.1.12-1",
"publicUrl": "../../build",
"themesUrl": "../../themes/",
"pageUrl": "lab/",
Expand Down
49 changes: 49 additions & 0 deletions tbump.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# github_url = "https://github.com/jupyterlab/jupyterlab_app/"

[version]
current = "3.1.12-1"

regex = '''
(?P<major>\d+)
\.
(?P<minor>\d+)
\.
(?P<patch>\d+)
\-
(?P<build>\d+)
'''

[git]
message_template = "Bump to {new_version}"
tag_template = "v{new_version}"

[[file]]
src = "package.json"
search = '"version": "{current_version}"'
[[file]]
src = "electron-builder-scripts/linux_after_install.sh"
search = 'JupyterLabAppServer-{current_version}-Linux'
[[file]]
src = "electron-builder-scripts/postinstall"
search = 'JupyterLabAppServer-{current_version}-MacOSX'
[[file]]
src = "electron-builder-scripts/wininstall.nsh"
search = 'JupyterLabAppServer-{current_version}-Windows'
[[file]]
src = "env_installer/construct.yaml"
search = 'version: {current_version}'
[[file]]
src = "env_installer/construct.yaml"
version_template = "{major}.{minor}.{patch}"
search = '- jupyterlab {current_version}'
[[file]]
src = "src/browser/index.html"
search = '"appVersion": "{current_version}"'

# [[before_commit]]
# name = "check changelog"
# cmd = "grep -q {new_version} Changelog.rst"

# [[after_push]]
# name = "publish"
# cmd = "./publish.sh"
Loading

0 comments on commit 3db6ee6

Please sign in to comment.