Skip to content

Commit 591ee4a

Browse files
committed
Update workflow
1 parent c0ddf01 commit 591ee4a

File tree

4 files changed

+104
-12
lines changed

4 files changed

+104
-12
lines changed

.github/workflows/upgrade-juypterlab-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: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,55 @@ 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+
isGlobal = false
66+
): void {
67+
const content = fs.readFileSync(filePath, 'utf-8');
68+
const versionRange = getVersionRange(version);
69+
const updatedContent = content.replace(pattern, `$1${versionRange}`);
70+
fs.writeFileSync(filePath, updatedContent);
71+
}
72+
2473
async function updatePackageJson(newVersion: string): Promise<void> {
2574
const url = `https://raw.githubusercontent.com/jupyterlab/jupyterlab/v${newVersion}/jupyterlab/staging/package.json`;
2675
const response = await fetch(url);
@@ -89,6 +138,33 @@ function absoluteVersion(version: string): string {
89138
return version;
90139
}
91140

141+
async function updatePyprojectToml(version: IVersion): Promise<void> {
142+
const filePath = path.resolve('pyproject.toml');
143+
const pattern = /(jupyterlab>=)[\d.]+(?:a|b|rc\d+)?,<[\d.]+/g;
144+
updateVersionInFile(filePath, pattern, version, true);
145+
}
146+
147+
async function updatePreCommitConfig(version: IVersion): Promise<void> {
148+
const filePath = path.resolve('.pre-commit-config.yaml');
149+
const pattern = /(jupyterlab)(?:>=|==)[\d.]+(?:,<[\d.]+)?(?="|,|\s|$)/;
150+
updateVersionInFile(filePath, pattern, version);
151+
}
152+
153+
// async function updateWorkflowFiles(version: IVersion): Promise<void> {
154+
// const workflowDir = path.resolve('.github', 'workflows');
155+
// const files = fs.readdirSync(workflowDir);
156+
// const pattern = /(jupyterlab)(?:>=|==)[\d.]+(?:,<[\d.]+)?(?="|,|\s|$)/g;
157+
158+
// for (const file of files) {
159+
// const filePath = path.join(workflowDir, file);
160+
// const content = fs.readFileSync(filePath, 'utf-8');
161+
162+
// if (content.includes('jupyterlab>=')) {
163+
// updateVersionInFile(filePath, pattern, version, true);
164+
// }
165+
// }
166+
// }
167+
92168
async function upgradeLabDependencies(): Promise<void> {
93169
const args: string[] = process.argv.slice(2);
94170

@@ -97,8 +173,11 @@ async function upgradeLabDependencies(): Promise<void> {
97173
process.exit(1);
98174
}
99175

100-
const newVersion: string = args[1];
101-
await updatePackageJson(newVersion);
176+
const version = parseVersion(args[1]);
177+
await updatePackageJson(args[1]); // Keep original string version for package.json
178+
await updatePyprojectToml(version);
179+
await updatePreCommitConfig(version);
180+
// await updateWorkflowFiles(version);
102181
}
103182

104183
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)