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

Convert JS package to yarn workspace #5160

Merged
merged 11 commits into from
Feb 14, 2024
Prev Previous commit
Next Next commit
rework js build/publish on CI
  • Loading branch information
jprochazk committed Feb 13, 2024
commit aa1e4070e15a60b7ea9b9f2643e934b494768b46
2 changes: 1 addition & 1 deletion .github/workflows/on_pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:
build-js:
name: "Build JS"
if: github.event.pull_request.head.repo.owner.login == 'rerun-io'
uses: ./.github/workflows/reusable_build_npm.yml
uses: ./.github/workflows/reusable_build_js.yml
with:
CONCURRENCY: pr-${{ github.event.pull_request.number }}
secrets: inherit
Expand Down
21 changes: 21 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ jobs:
echo "current=$current" >> "$GITHUB_OUTPUT"
echo "final=$final" >> "$GITHUB_OUTPUT"

- name: Update JS package versions
shell: bash
run: |
pixi run node rerun_js/scripts/version.mjs "${{ steps.versioning.outputs.current }}"

- name: Update rerun_c version
shell: bash
# Configuring CMake is enough to change the version on rerun.h!
Expand Down Expand Up @@ -264,6 +269,15 @@ jobs:
concurrency: ${{ github.ref_name }}
secrets: inherit

publish-js:
name: "Publish JS"
needs: [version]
uses: ./.github/workflows/reusable_publish_js.yml
with:
release-commit: ${{ needs.version.outputs.current }}
concurrency: ${{ github.ref_name }}
secrets: inherit

update-latest-branch:
name: "Update Latest Branch"
if: inputs.release-type == 'final'
Expand All @@ -276,6 +290,7 @@ jobs:
publish-web,
publish-rerun_c,
publish-rerun-cli,
publish-js,
]
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -304,6 +319,7 @@ jobs:
publish-web,
publish-rerun_c,
publish-rerun-cli,
publish-js,
]
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -348,6 +364,7 @@ jobs:
publish-web,
publish-rerun_c,
publish-rerun-cli,
publish-js,
github-release,
]
runs-on: ubuntu-latest
Expand Down Expand Up @@ -404,6 +421,7 @@ jobs:
publish-web,
publish-rerun_c,
publish-rerun-cli,
publish-js,
]
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -433,11 +451,13 @@ jobs:
fi
wheels_link="https://pypi.org/project/rerun-sdk/${{ needs.version.outputs.current }}"
crates_link="https://crates.io/crates/rerun/${{ needs.version.outputs.current }}"
npm_link="https://www.npmjs.com/package/@rerun-io/web-viewer/v/${{ needs.version.outputs.current }}"
rs_docs_link="https://docs.rs/rerun/${{ needs.version.outputs.current }}"
cpp_sdk_zip_link="https://build.rerun.io/commit/$short_commit_hash/rerun_cpp_sdk.zip"

pip_install="pip install rerun-sdk==${{ needs.version.outputs.current }}"
cargo_install="cargo install rerun-cli@${{ needs.version.outputs.current }}"
npm_install="npm install @rerun-io/web-viewer@${{ needs.version.outputs.current }}"

cat <<EOF > comment-body.txt
Version ${{ needs.version.outputs.current }} published successfully.
Expand All @@ -447,6 +467,7 @@ jobs:
| [web app]($web_app_link) | |
| [wheels]($wheels_link) | $pip_install |
| [crates]($crates_link) | $cargo_install |
| [npm]($npm_link) | $npm_install |
| [docs]($rerun_io_docs_link) | |
| [py docs]($py_docs_link) | |
| [rs docs]($rs_docs_link) | |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Reusable Build Web
name: Reusable Build JS

on:
workflow_call:
Expand Down Expand Up @@ -53,10 +53,14 @@ jobs:
workload_identity_provider: ${{ secrets.GOOGLE_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ secrets.GOOGLE_SERVICE_ACCOUNT }}

- uses: prefix-dev/[email protected]
with:
pixi-version: v0.13.0

- name: Install dependencies
shell: bash
run: yarn --cwd rerun_js install
run: pixi run yarn --cwd rerun_js install

- name: Build package
shell: bash
run: yarn --cwd rerun_js workspaces run build
run: pixi run yarn --cwd rerun_js workspaces run build
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build and publish NPM
name: Build and publish JS

on:
workflow_call:
Expand All @@ -12,7 +12,7 @@ on:
required: true

concurrency:
group: ${{ inputs.concurrency }}-publish-npm
group: ${{ inputs.concurrency }}-publish-js
cancel-in-progress: true

permissions:
Expand Down Expand Up @@ -48,7 +48,9 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: "20.x"
registry-url: "https://registry.npmjs.org"

- name: Install Yarn
run: npm install -g yarn

- name: Set up Rust
uses: ./.github/actions/setup-rust
Expand All @@ -67,4 +69,4 @@ jobs:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
shell: bash
run: |
pixi run node rerun_js/web-viewer/scripts/publish.mjs
pixi run node rerun_js/scripts/publish.mjs
5 changes: 1 addition & 4 deletions rerun_js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,5 @@
"workspaces": [
"web-viewer",
"web-viewer-react"
],
"scripts": {
"bump": "node scripts/version.mjs"
}
]
}
23 changes: 23 additions & 0 deletions rerun_js/scripts/common.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,29 @@ export function stripSemverBuildMetadata(version) {
}
}

/**
* Returns the appropriate NPM package tag for `version`.
*
* @type {(version: string) => "alpha" | "rc" | "latest"}
*/
export function inferTag(version) {
/** @type {"alpha" | "rc" | "latest"} */
let tag = "latest";

const [, prerelease] = version.split("-");
if (prerelease) {
const [kind, n] = prerelease.split(".");
switch (kind) {
case "alpha":
tag = "alpha";
case "rc":
tag = "rc";
}
}

return tag;
}

/**
* Returns `true` if `package@version` is already published.
*
Expand Down
63 changes: 63 additions & 0 deletions rerun_js/scripts/publish.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env node
// @ts-check

import {
$,
fs,
script_dir,
path,
fail,
inferTag,
isPublished,
} from "./common.mjs";

const root_dir = path.resolve(script_dir, "..");

if (!process.env.NODE_AUTH_TOKEN) {
fail(
`"NODE_AUTH_TOKEN" env is not set. https://docs.npmjs.com/creating-and-viewing-access-tokens`,
);
}

/** @type {{ workspaces: string[] }} */
const root_package_json = JSON.parse(
fs.readFileSync(path.join(root_dir, "package.json"), "utf-8"),
);

const all_packages = await Promise.all(
root_package_json.workspaces.map(async (pkg) => {
const dir = path.join(root_dir, pkg);
const { name, version } = JSON.parse(
fs.readFileSync(path.join(dir, "package.json"), "utf-8"),
);
const published = await isPublished(name, version);

return { dir, name, version, published };
}),
);

const unpublished = all_packages.filter((pkg) => {
if (pkg.published) {
console.log(`${pkg.name}@${pkg.version} is already published`);
return false;
}
return true;
});

if (unpublished.length === 0) {
console.log("nothing to publish");
process.exit(0);
}

$(`yarn install`, { cwd: root_dir });

for (const pkg of unpublished) {
console.log(`building ${pkg.name}@${pkg.version}`);
$(`npm run build`, { cwd: pkg.dir });
}

for (const pkg of unpublished) {
console.log(`publishing ${pkg.name}@${pkg.version}`);
const tag = inferTag(pkg.version);
$(`npm publish --tag ${tag}`, { cwd: pkg.dir });
}
2 changes: 1 addition & 1 deletion rerun_js/web-viewer-react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default function App() {
```

The `rrd` in the snippet above should be a URL pointing to either:
- A hosted `.rrd` file, such as <https://app.rerun.io/version/0.12.1/examples/dna.rrd>
- A hosted `.rrd` file, such as <https://app.rerun.io/version/0.13.0/examples/dna.rrd>
- A WebSocket connection to the SDK opened via the [`serve`](https://www.rerun.io/docs/reference/sdk-operating-modes#serve) API

If `rrd` is not set, the viewer will display the same welcome screen as <https://app.rerun.io>.
Expand Down
15 changes: 7 additions & 8 deletions rerun_js/web-viewer-react/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"name": "@rerun-io/web-viewer-react",
"version": "0.12.1",
"version": "0.13.0",
"description": "Embed the Rerun web viewer in your React app",
"private": false,
"licenses": [
{
"type": "MIT"
Expand All @@ -12,9 +11,8 @@
}
],
"scripts": {
"build:types": "dts-buddy",
"build": "npm run build:types",
"prepublishOnly": "dts-buddy"
"build:types": "tsc --noEmit && dts-buddy",
"build": "npm run build:types"
},
"repository": {
"type": "git",
Expand All @@ -41,11 +39,12 @@
"tsconfig.json"
],
"dependencies": {
"@rerun-io/web-viewer": "0.12.1",
"@rerun-io/web-viewer": "0.13.0",
"@types/react": "^18.2.33",
"react": "^18.2.0"
},
"devDependencies": {
"dts-buddy": "^0.3.0"
"dts-buddy": "^0.3.0",
"typescript": "^5.2.2"
}
}
}
2 changes: 1 addition & 1 deletion rerun_js/web-viewer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ viewer.stop();
```

The `rrd` in the snippet above should be a URL pointing to either:
- A hosted `.rrd` file, such as <https://app.rerun.io/version/0.12.1/examples/dna.rrd>
- A hosted `.rrd` file, such as <https://app.rerun.io/version/0.13.0/examples/dna.rrd>
- A WebSocket connection to the SDK opened via the [`serve`](https://www.rerun.io/docs/reference/sdk-operating-modes#serve) API

If `rrd` is not set, the viewer will display the same welcome screen as <https://app.rerun.io>.
Expand Down
10 changes: 4 additions & 6 deletions rerun_js/web-viewer/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"name": "@rerun-io/web-viewer",
"version": "0.12.1",
"version": "0.13.0",
"description": "Embed the Rerun web viewer in your app",
"private": false,
"licenses": [
{
"type": "MIT"
Expand All @@ -14,9 +13,8 @@
"scripts": {
"build:wasm": "cargo run -p re_build_web_viewer -- --release --module -o rerun_js/web-viewer",
"build:wasm:debug": "cargo run -p re_build_web_viewer -- --debug --module -o rerun_js/web-viewer",
"build:types": "dts-buddy",
"build": "npm run build:wasm && npm run build:types",
"prepublishOnly": "tsc --noEmit && dts-buddy"
"build:types": "tsc --noEmit && dts-buddy",
"build": "npm run build:wasm && npm run build:types"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -55,4 +53,4 @@
"dts-buddy": "^0.3.0",
"typescript": "^5.2.2"
}
}
}
Loading
Loading