Skip to content

Commit abd1b8c

Browse files
authored
Fix workflow to update the JupyterLab version (jupyter#7548)
* Update workflow * fix workflow name
1 parent f11252b commit abd1b8c

File tree

4 files changed

+87
-12
lines changed

4 files changed

+87
-12
lines changed

.github/workflows/upgrade-juypterlab-dependencies.yml renamed to .github/workflows/upgrade-jupyterlab-dependencies.yml

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,17 @@ on:
1010
default: latest
1111
required: true
1212
type: string
13+
branch:
14+
description: 'The branch to target'
15+
default: main
16+
required: false
17+
type: string
1318

1419
env:
1520
version_tag: 'latest'
1621

1722
permissions:
23+
actions: write
1824
contents: write
1925
pull-requests: write
2026

@@ -52,20 +58,23 @@ jobs:
5258
set -eux
5359
for version in ${{ inputs.version || env.version_tag }}
5460
do
55-
export LATEST=$(node buildutils/lib/get-latest-lab-version.js --set-version $version)
61+
if [[ "${version}" == "latest" ]]; then
62+
export LATEST=$(jlpm run get:lab:version --set-version ${version})
63+
else
64+
export LATEST=${version}
65+
fi
5666
done
5767
5868
echo "latest=${LATEST}" >> $GITHUB_ENV
59-
node buildutils/lib/upgrade-lab-dependencies.js --set-version ${LATEST}
69+
jlpm upgrade:lab:dependencies --set-version ${LATEST}
6070
if [[ ! -z "$(git status --porcelain package.json)" ]]; then
6171
jlpm install
72+
jlpm deduplicate
6273
fi
6374
6475
- name: Create a PR
65-
shell: bash
6676
env:
67-
GITHUB_USER: ${{ secrets.G_USER }}
68-
GITHUB_TOKEN: ${{ secrets.G_TOKEN }}
77+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6978
run: |
7079
set -eux
7180
@@ -80,13 +89,15 @@ jobs:
8089
else
8190
# new branch is created
8291
git checkout -b "${BRANCH_NAME}"
83-
git config user.name "Jupyter Bot"
84-
git config user.email 'jupyterlab-bot@users.noreply.github.com'
92+
git config user.name "github-actions[bot]"
93+
git config user.email 'github-actions[bot]@users.noreply.github.com'
8594
8695
git commit . -m "Update to JupyterLab v${LATEST}"
8796
8897
git push --set-upstream origin "${BRANCH_NAME}"
89-
hub pull-request -m "Update to JupyterLab v${LATEST}" \
90-
-m "New JupyterLab release [v${LATEST}](https://github.com/jupyterlab/jupyterlab/releases/tag/v${LATEST}) is available. Please review the lock file carefully.".
98+
gh pr create \
99+
--base ${{ inputs.branch || 'main' }} \
100+
--title "Update to JupyterLab v${LATEST}" \
101+
--body "New JupyterLab release [v${LATEST}](https://github.com/jupyterlab/jupyterlab/releases/tag/v${LATEST}) is available. Please review the lock file carefully."
91102
fi
92103
fi

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,4 @@ repos:
8282
name: integrity
8383
entry: 'npm run integrity --force'
8484
language: node
85-
stages: [push]
85+
stages: [pre-push]

buildutils/src/upgrade-lab-dependencies.ts

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,54 @@ const PACKAGE_JSON_PATHS: string[] = [
2121

2222
const DEPENDENCY_GROUP = '@jupyterlab';
2323

24+
interface IVersion {
25+
major: number;
26+
minor: number;
27+
patch: number;
28+
preRelease?: string;
29+
}
30+
31+
function parseVersion(version: string): IVersion {
32+
const match = version.match(/^(\d+)\.(\d+)\.(\d+)(?:(a|b|rc)(\d+))?$/);
33+
if (!match) {
34+
throw new Error(`Invalid version format: ${version}`);
35+
}
36+
37+
const [, major, minor, patch, type, preVersion] = match;
38+
const baseVersion = {
39+
major: parseInt(major, 10),
40+
minor: parseInt(minor, 10),
41+
patch: parseInt(patch, 10),
42+
};
43+
44+
if (type && preVersion) {
45+
return {
46+
...baseVersion,
47+
preRelease: `${type}${preVersion}`,
48+
};
49+
}
50+
51+
return baseVersion;
52+
}
53+
54+
function getVersionRange(version: IVersion): string {
55+
const baseVersion = `${version.major}.${version.minor}.${version.patch}${
56+
version.preRelease ?? ''
57+
}`;
58+
return `>=${baseVersion},<${version.major}.${version.minor + 1}`;
59+
}
60+
61+
function updateVersionInFile(
62+
filePath: string,
63+
pattern: RegExp,
64+
version: IVersion
65+
): void {
66+
const content = fs.readFileSync(filePath, 'utf-8');
67+
const versionRange = getVersionRange(version);
68+
const updatedContent = content.replace(pattern, `$1${versionRange}`);
69+
fs.writeFileSync(filePath, updatedContent);
70+
}
71+
2472
async function updatePackageJson(newVersion: string): Promise<void> {
2573
const url = `https://raw.githubusercontent.com/jupyterlab/jupyterlab/v${newVersion}/jupyterlab/staging/package.json`;
2674
const response = await fetch(url);
@@ -89,6 +137,18 @@ function absoluteVersion(version: string): string {
89137
return version;
90138
}
91139

140+
async function updatePyprojectToml(version: IVersion): Promise<void> {
141+
const filePath = path.resolve('pyproject.toml');
142+
const pattern = /(jupyterlab>=)[\d.]+(?:a|b|rc\d+)?,<[\d.]+/g;
143+
updateVersionInFile(filePath, pattern, version);
144+
}
145+
146+
async function updatePreCommitConfig(version: IVersion): Promise<void> {
147+
const filePath = path.resolve('.pre-commit-config.yaml');
148+
const pattern = /(jupyterlab)(?:>=|==)[\d.]+(?:,<[\d.]+)?(?="|,|\s|$)/;
149+
updateVersionInFile(filePath, pattern, version);
150+
}
151+
92152
async function upgradeLabDependencies(): Promise<void> {
93153
const args: string[] = process.argv.slice(2);
94154

@@ -97,8 +157,10 @@ async function upgradeLabDependencies(): Promise<void> {
97157
process.exit(1);
98158
}
99159

100-
const newVersion: string = args[1];
101-
await updatePackageJson(newVersion);
160+
const version = parseVersion(args[1]);
161+
await updatePackageJson(args[1]); // Keep original string version for package.json
162+
await updatePyprojectToml(version);
163+
await updatePreCommitConfig(version);
102164
}
103165

104166
upgradeLabDependencies();

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"eslint": "eslint . --ext .ts,.tsx --fix",
3232
"eslint:check": "eslint . --ext .ts,.tsx",
3333
"eslint:files": "eslint --fix",
34+
"get:lab:version": "node ./buildutils/lib/get-latest-lab-version.js",
3435
"integrity": "node buildutils/lib/ensure-repo.js",
3536
"prettier": "prettier --write \"**/*{.ts,.tsx,.js,.jsx,.css,.json,.md}\"",
3637
"prettier:check": "prettier --list-different \"**/*{.ts,.tsx,.js,.jsx,.css,.json,.md}\"",
@@ -39,6 +40,7 @@
3940
"release:patch": "node ./buildutils/lib/release-patch.js",
4041
"test": "lerna run test",
4142
"update:dependency": "node ./node_modules/@jupyterlab/buildutils/lib/update-dependency.js --lerna",
43+
"upgrade:lab:dependencies": "node ./buildutils/lib/upgrade-lab-dependencies.js",
4244
"watch": "run-p watch:lib watch:app",
4345
"watch:app": "lerna exec --stream --scope \"@jupyter-notebook/app\" jlpm watch",
4446
"watch:lib": "lerna exec --stream --scope @jupyter-notebook/metapackage jlpm watch"

0 commit comments

Comments
 (0)