Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve update script #7556

Merged
merged 4 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions .github/workflows/upgrade-jupyterlab-dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,25 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{ 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:
node-version: '20.x'

- 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
Expand Down
2 changes: 2 additions & 0 deletions buildutils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@
"@jupyterlab/buildutils": "~4.4.0-alpha.1",
"commander": "^6.2.0",
"fs-extra": "^9.1.0",
"semver": "^7.6.3",
"typescript": "~5.0.2"
},
"devDependencies": {
"@types/fs-extra": "^9.0.10",
"@types/node": "^14.6.1",
"@types/semver": "^7.5.8",
"rimraf": "^3.0.2"
}
}
56 changes: 44 additions & 12 deletions buildutils/src/get-latest-lab-version.ts
Original file line number Diff line number Diff line change
@@ -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<string> {
Expand All @@ -22,10 +50,14 @@ async function findVersion(versionTag: string): Promise<string> {
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';
Expand Down
21 changes: 16 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand All @@ -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"
Expand Down
Loading