From 460ee23235ada8fe2c76736f81e9838700b15f62 Mon Sep 17 00:00:00 2001 From: RayanHnide Date: Thu, 7 May 2026 13:48:11 +0400 Subject: [PATCH] chore: dual-publish package docs and workflow Add a GitHub Packages publish path that keeps npm as the primary registry while generating an owner-scoped package for GitHub. Document both install methods and auth setup so users can consume from either registry. Co-authored-by: Cursor --- .github/workflows/publish.yml | 46 ++++++++++++++++++++++++++++++++++- README.md | 17 +++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 4f7e0eb..6f3b482 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,4 +1,4 @@ -name: Publish to npm +name: Publish packages on: push: @@ -9,6 +9,7 @@ permissions: contents: write issues: write pull-requests: write + packages: write jobs: publish: @@ -47,3 +48,46 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + + - name: Setup Node for GitHub Packages + uses: actions/setup-node@v4 + with: + node-version: 22 + registry-url: "https://npm.pkg.github.com" + scope: "@${{ github.repository_owner }}" + + - name: Publish to GitHub Packages + env: + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }} + run: | + PKG_NAME="$(node -p "require('./package.json').name")" + OWNER_LC="$(printf '%s' "$GITHUB_REPOSITORY_OWNER" | tr '[:upper:]' '[:lower:]')" + BASE_NAME="${PKG_NAME#@*/}" + GH_PKG_NAME="@$OWNER_LC/$BASE_NAME" + PACK_JSON="$(npm pack --json)" + TARBALL="$(node -e "const data = JSON.parse(process.argv[1]); console.log(data[0].filename);" "$PACK_JSON")" + WORK_DIR="$(mktemp -d)" + trap 'rm -rf "$WORK_DIR" "$TARBALL"' EXIT + + tar -xzf "$TARBALL" -C "$WORK_DIR" + GH_PKG_DIR="$WORK_DIR/package" + + node -e " + const fs = require('node:fs'); + const path = process.argv[1]; + const nextName = process.argv[2]; + const pkg = JSON.parse(fs.readFileSync(path, 'utf8')); + pkg.name = nextName; + pkg.publishConfig = { ...(pkg.publishConfig || {}), registry: 'https://npm.pkg.github.com' }; + fs.writeFileSync(path, JSON.stringify(pkg, null, 2) + '\n'); + " "$GH_PKG_DIR/package.json" "$GH_PKG_NAME" + + GH_PKG_VERSION="$(node -e "console.log(require(process.argv[1]).version)" "$GH_PKG_DIR/package.json")" + + if npm view "$GH_PKG_NAME@$GH_PKG_VERSION" version --registry=https://npm.pkg.github.com >/dev/null 2>&1; then + echo "Version $GH_PKG_VERSION is already published to GitHub Packages as $GH_PKG_NAME. Skipping." + exit 0 + fi + + npm publish "$GH_PKG_DIR" --registry=https://npm.pkg.github.com diff --git a/README.md b/README.md index 269e242..163fc64 100644 --- a/README.md +++ b/README.md @@ -22,10 +22,27 @@ It is dev-first and production-safe by default (`includeInProduction: false`). ## Install +From npm (recommended): + ```bash npm install @rayan_hn/render-inspector ``` +From GitHub Packages: + +```bash +npm install @rayanhnide/render-inspector --registry=https://npm.pkg.github.com +``` + +If you use GitHub Packages, add this to your user `.npmrc`: + +```ini +@rayanhnide:registry=https://npm.pkg.github.com +//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN} +``` + +Then set `GITHUB_TOKEN` in your shell to a GitHub token with `read:packages`. + ## 20-Second Outcome Demo ```tsx