From cf4153a9baeebddd02935b54abfbd4da5bd65854 Mon Sep 17 00:00:00 2001 From: Aleksander Grygier Date: Fri, 20 Nov 2026 15:46:18 +0100 Subject: [PATCH] ui: publish llama-ui as an alias of @ggml-org/llama-ui (#32667) The unscoped llama-ui on npm is a 0.0.1 placeholder. After the scoped publish, the workflow renames the same build and publishes it again at the same version, with a readme note pointing at the scoped package. Assisted-by: Claude (Opus 5.5 Medium) --- .github/workflows/ui-lib-publish.yml | 50 ++++++++++++++++++++++++++++ ui/lib/ui/scripts/alias-package.mjs | 43 ++++++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 ui/lib/ui/scripts/alias-package.mjs diff --git a/.github/workflows/ui-lib-publish.yml b/.github/workflows/ui-lib-publish.yml index 00afed3ab..a1258cda4 100644 --- a/.github/workflows/ui-lib-publish.yml +++ b/.github/workflows/ui-lib-publish.yml @@ -18,6 +18,10 @@ name: UI Lib Publish # ui-lib-publish.yml, and Environment left blank - this job names no environment, since creating # one needs repository admin. Merging this workflow before that exists leaves the publish step # red on master: the release is late rather than wrong, and re-running the job publishes it. +# +# The unscoped llama-ui is an alias: once the scoped package is out, the same build is renamed +# and published again at the same version, so the two never drift. It is a package of its own +# on npm, and needs the same trusted publisher set on it. on: workflow_dispatch: @@ -128,6 +132,30 @@ jobs: npm publish --access public --provenance --ignore-scripts --tag "$TAG" working-directory: ${{ env.LIB_DIR }} + - name: Rename the build to the unscoped alias + # after the scoped publish, so nothing above sees the changed name. Not on a PR: the + # advisory check there is about the version, which the alias shares. + if: github.event_name != 'pull_request' + run: node scripts/alias-package.mjs + working-directory: ${{ env.LIB_DIR }} + + - name: Compare the alias with npm + id: alias + if: github.event_name != 'pull_request' + run: node scripts/npm-version-check.mjs + working-directory: ${{ env.LIB_DIR }} + + - name: Publish the alias + # its own verdict rather than the scoped one's, so an alias that fell behind catches up + # on the next run instead of waiting for a bump + if: github.ref == 'refs/heads/master' && steps.alias.outputs.should_publish == 'true' && inputs.dry_run != true + env: + TAG: ${{ steps.alias.outputs.tag }} + run: | + test -d dist || { echo "dist/ is missing: nothing was built, so nothing is published"; exit 1; } + npm publish --access public --provenance --ignore-scripts --tag "$TAG" + working-directory: ${{ env.LIB_DIR }} + - name: Report if: always() # every value reaches the shell through env, not through the script, so a package name @@ -140,6 +168,11 @@ jobs: NOTE: ${{ steps.version.outputs.note }} SHOULD: ${{ steps.version.outputs.should_publish }} DRY: ${{ inputs.dry_run }} + ALIAS_LATEST: ${{ steps.alias.outputs.latest }} + ALIAS_VERDICT: ${{ steps.alias.outputs.verdict || 'not reached' }} + ALIAS_NOTE: ${{ steps.alias.outputs.note }} + ALIAS_SHOULD: ${{ steps.alias.outputs.should_publish }} + EVENT: ${{ github.event_name }} run: | if [ "$DRY" = "true" ]; then published="no (dry run)" elif [ "$SHOULD" = "true" ]; then published=yes @@ -156,6 +189,23 @@ jobs: echo echo "> $NOTE" } >> "$GITHUB_STEP_SUMMARY" + [ "$EVENT" = "pull_request" ] && exit 0 + if [ "$DRY" = "true" ]; then published="no (dry run)" + elif [ "$ALIAS_SHOULD" = "true" ]; then published=yes + else published=no + fi + { + echo + echo "### llama-ui (alias) $VERSION" + echo + echo "| | |" + echo "| --- | --- |" + echo "| npm latest was | ${ALIAS_LATEST:-nothing published yet} |" + echo "| verdict | \`$ALIAS_VERDICT\` |" + echo "| published | $published |" + echo + echo "> $ALIAS_NOTE" + } >> "$GITHUB_STEP_SUMMARY" - name: Mind the verdict if: always() && github.event_name != 'pull_request' && steps.version.outcome == 'success' diff --git a/ui/lib/ui/scripts/alias-package.mjs b/ui/lib/ui/scripts/alias-package.mjs new file mode 100644 index 000000000..f3e94131e --- /dev/null +++ b/ui/lib/ui/scripts/alias-package.mjs @@ -0,0 +1,43 @@ +#!/usr/bin/env node +// Turns this checkout of the library into its unscoped alias, llama-ui, for +// .github/workflows/ui-lib-publish.yml: the same build, published a second time under the +// name people type first. Only the name in package.json changes, and the readme gains a note +// saying which package is the real one. Run it after the scoped publish and never commit the +// result. + +import { readFileSync, writeFileSync } from 'node:fs'; +import { fileURLToPath } from 'node:url'; + +const ALIAS = 'llama-ui'; + +const pkgPath = fileURLToPath(new URL('../package.json', import.meta.url)); +const readmePath = fileURLToPath(new URL('../README.md', import.meta.url)); + +const raw = readFileSync(pkgPath, 'utf8'); +const pkg = JSON.parse(raw); +const scoped = pkg.name; + +if (scoped === ALIAS) { + console.log(`package.json is already named ${ALIAS}`); + process.exit(0); +} +if (!scoped?.endsWith(`/${ALIAS}`)) { + console.error(`expected a scoped ${ALIAS} package to alias, got ${scoped}`); + process.exit(1); +} + +pkg.name = ALIAS; +// keep the file's own indentation so the diff is the name alone +const indent = raw.match(/^[ \t]+/m)?.[0] ?? '\t'; +writeFileSync(pkgPath, JSON.stringify(pkg, null, indent) + '\n'); + +const note = [ + `> \`${ALIAS}\` is an alias of [\`${scoped}\`](https://www.npmjs.com/package/${scoped}): the same`, + `> build at the same version, published under both names. Prefer \`${scoped}\`; the examples`, + `> below use it, and work with \`${ALIAS}\` in its place.`, + '', + '', +].join('\n'); +writeFileSync(readmePath, note + readFileSync(readmePath, 'utf8')); + +console.log(`${scoped}@${pkg.version} is now named ${ALIAS}`);