From c3fcb6804e1eff15233df1e7657adcacd60d416d Mon Sep 17 00:00:00 2001 From: Jeremy Tuloup Date: Sun, 22 Dec 2024 11:24:47 +0100 Subject: [PATCH 1/4] Allow opening a PR against a branch --- .../workflows/upgrade-jupyterlab-dependencies.yml | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/.github/workflows/upgrade-jupyterlab-dependencies.yml b/.github/workflows/upgrade-jupyterlab-dependencies.yml index 2790bdbf15..15e15ad553 100644 --- a/.github/workflows/upgrade-jupyterlab-dependencies.yml +++ b/.github/workflows/upgrade-jupyterlab-dependencies.yml @@ -35,18 +35,15 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 + with: + branch: ${{ inputs.branch || 'main' }} - name: Set up Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: '3.11' - - name: Install required dependencies - run: | - python -m pip install jupyterlab - sudo apt-get install hub - - name: Install Node uses: actions/setup-node@v2 with: @@ -54,7 +51,9 @@ jobs: - name: Install npm dependencies and build buildutils run: | - jlpm install + python -m pip install -e ".[dev]" + + jlpm jlpm run build:utils - name: Check for new releases and update From a83bf174b173dce6576312c64bcfec78601f54c3 Mon Sep 17 00:00:00 2001 From: Jeremy Tuloup Date: Sun, 22 Dec 2024 12:10:42 +0100 Subject: [PATCH 2/4] better handle pre-releases --- buildutils/package.json | 2 + buildutils/src/get-latest-lab-version.ts | 56 +++++++++++++++++++----- 2 files changed, 46 insertions(+), 12 deletions(-) diff --git a/buildutils/package.json b/buildutils/package.json index f043a5a11b..e71a9dda84 100644 --- a/buildutils/package.json +++ b/buildutils/package.json @@ -32,11 +32,13 @@ "@jupyterlab/buildutils": "~4.4.0-alpha.1", "commander": "^6.2.0", "fs-extra": "^9.1.0", + "semver": "^7.5.4", "typescript": "~5.0.2" }, "devDependencies": { "@types/fs-extra": "^9.0.10", "@types/node": "^14.6.1", + "@types/semver": "^7.5.6", "rimraf": "^3.0.2" } } diff --git a/buildutils/src/get-latest-lab-version.ts b/buildutils/src/get-latest-lab-version.ts index 166e035a59..df8469e8e0 100644 --- a/buildutils/src/get-latest-lab-version.ts +++ b/buildutils/src/get-latest-lab-version.ts @@ -1,18 +1,46 @@ +import * as fs from 'fs-extra'; +import * as semver from 'semver'; + +function convertPythonVersion(version: string): string { + return version + .replace('a', '-alpha') + .replace('b', '-beta') + .replace('rc', '-rc'); +} + function extractVersionFromReleases( releases: any, - versionTag: string + versionTag: string, + currentVersion: string ): string | null { - for (const release of releases) { - const tagName: string = release['tag_name']; - if (versionTag === 'latest') { - if (!release['prerelease'] && !release['draft']) { - return tagName; - } - } else if (versionTag === tagName) { - return tagName; - } + const npmCurrentVersion = convertPythonVersion(currentVersion); + const isCurrentPreRelease = semver.prerelease(npmCurrentVersion) !== null; + + if (versionTag === 'latest') { + // Find first version that is newer than current and matches pre-release criteria + const release = releases.find((r: any) => { + const version = r['tag_name'].substring(1); // Remove 'v' prefix for semver + const npmVersion = convertPythonVersion(version); + return ( + (isCurrentPreRelease || !r['prerelease']) && + semver.gte(npmVersion, npmCurrentVersion) + ); + }); + return release ? release['tag_name'] : null; + } else { + // Find exact version match + const release = releases.find((r: any) => r['tag_name'] === versionTag); + return release ? release['tag_name'] : null; } - return null; +} + +function extractCurrentJupyterLabVersion(): string { + const toml = fs.readFileSync('pyproject.toml', 'utf8'); + const match = toml.match(/jupyterlab>=([^,]+)/); + if (!match) { + throw new Error('Could not find JupyterLab version in pyproject.toml'); + } + return match[1]; } async function findVersion(versionTag: string): Promise { @@ -22,10 +50,14 @@ async function findVersion(versionTag: string): Promise { const error_message = `Failed to fetch package.json from ${url}. HTTP status code: ${response.status}`; throw new Error(error_message); } + + const currentVersion = extractCurrentJupyterLabVersion(); + const releases: any = await response.json(); const version: string | null = extractVersionFromReleases( releases, - versionTag + versionTag, + currentVersion ); if (version === null) { const error_message = 'Invalid release tag'; From 4362372aa7aab152e7e47aa1bace4dc61542068c Mon Sep 17 00:00:00 2001 From: Jeremy Tuloup Date: Sun, 22 Dec 2024 12:28:16 +0100 Subject: [PATCH 3/4] update yarn.lock --- buildutils/package.json | 4 ++-- yarn.lock | 21 ++++++++++++++++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/buildutils/package.json b/buildutils/package.json index e71a9dda84..b1604526e5 100644 --- a/buildutils/package.json +++ b/buildutils/package.json @@ -32,13 +32,13 @@ "@jupyterlab/buildutils": "~4.4.0-alpha.1", "commander": "^6.2.0", "fs-extra": "^9.1.0", - "semver": "^7.5.4", + "semver": "^7.6.3", "typescript": "~5.0.2" }, "devDependencies": { "@types/fs-extra": "^9.0.10", "@types/node": "^14.6.1", - "@types/semver": "^7.5.6", + "@types/semver": "^7.5.8", "rimraf": "^3.0.2" } } diff --git a/yarn.lock b/yarn.lock index 05471a98e6..54a04baf5e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2269,9 +2269,11 @@ __metadata: "@jupyterlab/buildutils": ~4.4.0-alpha.1 "@types/fs-extra": ^9.0.10 "@types/node": ^14.6.1 + "@types/semver": ^7.5.8 commander: ^6.2.0 fs-extra: ^9.1.0 rimraf: ^3.0.2 + semver: ^7.6.3 typescript: ~5.0.2 languageName: unknown linkType: soft @@ -6726,10 +6728,10 @@ __metadata: languageName: node linkType: hard -"@types/semver@npm:^7.1.0, @types/semver@npm:^7.3.12": - version: 7.5.3 - resolution: "@types/semver@npm:7.5.3" - checksum: 349fdd1ab6c213bac5c991bac766bd07b8b12e63762462bb058740dcd2eb09c8193d068bb226f134661275f2022976214c0e727a4e5eb83ec1b131127c980d3e +"@types/semver@npm:^7.1.0, @types/semver@npm:^7.3.12, @types/semver@npm:^7.5.8": + version: 7.5.8 + resolution: "@types/semver@npm:7.5.8" + checksum: ea6f5276f5b84c55921785a3a27a3cd37afee0111dfe2bcb3e03c31819c197c782598f17f0b150a69d453c9584cd14c4c4d7b9a55d2c5e6cacd4d66fdb3b3663 languageName: node linkType: hard @@ -17660,7 +17662,7 @@ __metadata: languageName: node linkType: hard -"semver@npm:7.5.4, semver@npm:^7.0.0, semver@npm:^7.1.1, semver@npm:^7.1.2, semver@npm:^7.3.2, semver@npm:^7.3.4, semver@npm:^7.3.5, semver@npm:^7.3.7, semver@npm:^7.3.8, semver@npm:^7.5.3, semver@npm:^7.5.4": +"semver@npm:7.5.4": version: 7.5.4 resolution: "semver@npm:7.5.4" dependencies: @@ -17680,6 +17682,15 @@ __metadata: languageName: node linkType: hard +"semver@npm:^7.0.0, semver@npm:^7.1.1, semver@npm:^7.1.2, semver@npm:^7.3.2, semver@npm:^7.3.4, semver@npm:^7.3.5, semver@npm:^7.3.7, semver@npm:^7.3.8, semver@npm:^7.5.3, semver@npm:^7.5.4, semver@npm:^7.6.3": + version: 7.6.3 + resolution: "semver@npm:7.6.3" + bin: + semver: bin/semver.js + checksum: 4110ec5d015c9438f322257b1c51fe30276e5f766a3f64c09edd1d7ea7118ecbc3f379f3b69032bacf13116dc7abc4ad8ce0d7e2bd642e26b0d271b56b61a7d8 + languageName: node + linkType: hard + "send@npm:0.18.0": version: 0.18.0 resolution: "send@npm:0.18.0" From ae3fc39fdcf7ce698cabf694158a47f1587853d4 Mon Sep 17 00:00:00 2001 From: Jeremy Tuloup Date: Mon, 23 Dec 2024 09:02:46 +0100 Subject: [PATCH 4/4] Update upgrade-jupyterlab-dependencies.yml --- .github/workflows/upgrade-jupyterlab-dependencies.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/upgrade-jupyterlab-dependencies.yml b/.github/workflows/upgrade-jupyterlab-dependencies.yml index 15e15ad553..cd35dd57a7 100644 --- a/.github/workflows/upgrade-jupyterlab-dependencies.yml +++ b/.github/workflows/upgrade-jupyterlab-dependencies.yml @@ -37,7 +37,7 @@ jobs: - name: Checkout code uses: actions/checkout@v4 with: - branch: ${{ inputs.branch || 'main' }} + ref: ${{ inputs.branch || 'main' }} - name: Set up Python uses: actions/setup-python@v5