|
| 1 | +# Publishing CI/CD Documentation |
| 2 | + |
| 3 | +This document describes how the npm publishing workflows operate and the manual steps required for setup. |
| 4 | + |
| 5 | +## Current Behavior (User Perspective) |
| 6 | + |
| 7 | +### On Pull Request |
| 8 | + |
| 9 | +When you create or update a pull request: |
| 10 | + |
| 11 | +1. **Canary Release** — A canary version is automatically published to npm |
| 12 | + - Version format: `0.0.0-canary-<short-sha>` |
| 13 | + - npm tag: `pr_<pr-number>` (e.g., `pr_123`) |
| 14 | + - A comment is posted to the PR with the npm link: |
| 15 | + > Deployed canary version [0.0.0-canary-abc1234](https://www.npmjs.com/package/@cube-dev/ui-kit/v/0.0.0-canary-abc1234) |
| 16 | + - Install via: `npm install @cube-dev/ui-kit@pr_<pr-number>` |
| 17 | + |
| 18 | +2. **Tests & Lint** — Linting and unit tests run in parallel |
| 19 | + |
| 20 | +3. **Storybook Review** — Storybook is deployed to Chromatic for visual review |
| 21 | + - A comment is posted with review and preview links |
| 22 | + |
| 23 | +4. **Size Limit** — Bundle size is measured and reported in a PR comment |
| 24 | + |
| 25 | +### On Push to `main` Branch |
| 26 | + |
| 27 | +When changes are pushed to `main` (typically via merged PRs): |
| 28 | + |
| 29 | +1. **Changesets Processing** — The workflow checks for pending changesets: |
| 30 | + |
| 31 | + **If there are pending changesets:** |
| 32 | + - A "Release Pull Request" is created/updated automatically |
| 33 | + - This PR contains version bumps and changelog updates |
| 34 | + - No npm publish happens yet |
| 35 | + |
| 36 | + **If there are no pending changesets (Release PR was just merged):** |
| 37 | + - The package is built and published to npm |
| 38 | + - Uses the version specified in `package.json` (updated by the Release PR) |
| 39 | + - Published with the `latest` tag |
| 40 | + |
| 41 | +2. **Storybook Deployment** — If no publish happened, Storybook is deployed to Chromatic production |
| 42 | + - Auto-accepts visual changes since this is the main branch |
| 43 | + |
| 44 | +### Release Workflow Summary |
| 45 | + |
| 46 | +``` |
| 47 | +Developer creates PR → Canary published → PR merged to main |
| 48 | + ↓ |
| 49 | + Has pending changesets? |
| 50 | + ├── Yes → Create/update Release PR |
| 51 | + └── No → Publish to npm |
| 52 | +``` |
| 53 | + |
| 54 | +## Ignored Paths |
| 55 | + |
| 56 | +Pull request workflows are skipped for changes only in: |
| 57 | +- `.changeset/**` |
| 58 | +- `.husky/**` |
| 59 | + |
| 60 | +--- |
| 61 | + |
| 62 | +## Trusted Publishing Migration |
| 63 | + |
| 64 | +### What Changed |
| 65 | + |
| 66 | +Publishing logic has been moved to a dedicated `publish.yml` workflow file to support npm's [Trusted Publishing](https://docs.npmjs.com/trusted-publishers) feature. |
| 67 | + |
| 68 | +### Benefits |
| 69 | + |
| 70 | +- **No more NPM_TOKEN secret** — Authentication uses OIDC tokens |
| 71 | +- **Automatic provenance** — npm automatically generates provenance attestations |
| 72 | +- **Enhanced security** — Short-lived tokens instead of long-lived secrets |
| 73 | +- **Audit trail** — Cryptographic proof of build origin |
| 74 | + |
| 75 | +--- |
| 76 | + |
| 77 | +## Manual Setup Steps |
| 78 | + |
| 79 | +Complete these steps **before** merging the trusted publishing changes: |
| 80 | + |
| 81 | +### Step 1: Configure Trusted Publisher on npmjs.com |
| 82 | + |
| 83 | +> ⚠️ **Important**: This must be done BEFORE the first publish attempt with the new workflow. |
| 84 | +
|
| 85 | +1. Log in to [npmjs.com](https://www.npmjs.com) with an account that has publish access |
| 86 | +2. Go to: https://www.npmjs.com/package/@cube-dev/ui-kit/settings |
| 87 | +3. Scroll to the **"Trusted Publisher"** section |
| 88 | +4. Click the **"GitHub Actions"** button |
| 89 | +5. Fill in the configuration **exactly** as shown: |
| 90 | + |
| 91 | + | Field | Value | |
| 92 | + |-------|-------| |
| 93 | + | Organization or user | `cube-js` | |
| 94 | + | Repository | `cube-ui-kit` | |
| 95 | + | Workflow filename | `publish.yml` | |
| 96 | + | Environment name | _(leave empty)_ | |
| 97 | + |
| 98 | +6. Click **Save** (or the equivalent button) |
| 99 | + |
| 100 | +### Step 2: Verify the Setup with a Test PR |
| 101 | + |
| 102 | +1. Create a test branch and PR with minimal changes |
| 103 | +2. Watch the GitHub Actions for the canary release job |
| 104 | +3. Verify the canary package appears on npm with the correct version |
| 105 | +4. Check that provenance badge appears on the npm package page |
| 106 | + |
| 107 | +### Step 3: Test Full Release Flow |
| 108 | + |
| 109 | +1. Add a changeset to your test branch: `pnpm changeset` |
| 110 | +2. Merge the test PR to `main` |
| 111 | +3. Verify a "Release Pull Request" is created automatically |
| 112 | +4. Merge the Release PR |
| 113 | +5. Verify the package is published with: |
| 114 | + - Correct version |
| 115 | + - Provenance attestation (visible on npm package page) |
| 116 | + |
| 117 | +### Step 4: (Recommended) Restrict Token Access |
| 118 | + |
| 119 | +After verifying trusted publishing works for both canary and release: |
| 120 | + |
| 121 | +1. Go to npm package settings → **Publishing access** |
| 122 | +2. Select **"Require two-factor authentication and disallow tokens"** |
| 123 | +3. Click **Update Package Settings** |
| 124 | + |
| 125 | +> This prevents accidental token-based publishes and enhances security. |
| 126 | +
|
| 127 | +### Step 5: Clean Up NPM_TOKEN Secret |
| 128 | + |
| 129 | +Once everything is working: |
| 130 | + |
| 131 | +1. Go to GitHub repo: Settings → Secrets and variables → Actions |
| 132 | +2. Delete the `NPM_TOKEN` secret |
| 133 | +3. This is optional but recommended for security |
| 134 | + |
| 135 | +> ⚠️ Keep the token until you're 100% confident the new setup works. |
| 136 | +
|
| 137 | +--- |
| 138 | + |
| 139 | +## Workflow Files |
| 140 | + |
| 141 | +| File | Purpose | |
| 142 | +|------|---------| |
| 143 | +| `publish.yml` | Reusable workflow for npm publishing (canary and release) | |
| 144 | +| `main.yml` | Release workflow triggered on push to main | |
| 145 | +| `pull-request.yml` | PR workflow for tests, canary releases, and Chromatic | |
| 146 | +| `size-limit.yml` | Bundle size measurement | |
| 147 | +| `codeql-analysis.yml` | Security analysis | |
| 148 | + |
| 149 | +--- |
| 150 | + |
| 151 | +## Pre-Merge Checklist |
| 152 | + |
| 153 | +Before merging the trusted publishing PR, verify: |
| 154 | + |
| 155 | +- [ ] You have maintainer access to the package on npmjs.com (to configure trusted publisher) |
| 156 | +- [ ] Trusted publisher configured on npmjs.com for `publish.yml` |
| 157 | +- [ ] Configuration matches exactly: `cube-js/cube-ui-kit/publish.yml` |
| 158 | + |
| 159 | +--- |
| 160 | + |
| 161 | +## Troubleshooting |
| 162 | + |
| 163 | +### "Unable to authenticate" error |
| 164 | + |
| 165 | +- Verify the workflow filename matches **exactly** (`publish.yml`, not `Publish.yml`) |
| 166 | +- Ensure all fields are case-sensitive and match exactly |
| 167 | +- Check that you're using GitHub-hosted runners (not self-hosted) |
| 168 | +- Verify the repository and organization names are correct (`cube-js`, `cube-ui-kit`) |
| 169 | + |
| 170 | +### Provenance not generated |
| 171 | + |
| 172 | +- Provenance is only generated for **public** repositories |
| 173 | +- Ensure the package is public |
| 174 | +- Private repositories cannot generate provenance even for public packages |
| 175 | + |
| 176 | +### Canary releases failing |
| 177 | + |
| 178 | +- Check that the workflow has `id-token: write` permission |
| 179 | +- Verify the trusted publisher is configured for `publish.yml` |
| 180 | +- Ensure npm version is 11.5.1+ (the workflow updates this automatically) |
| 181 | + |
| 182 | +### Changesets action not publishing |
| 183 | + |
| 184 | +- Changesets action uses npm internally, so trusted publishing should work |
| 185 | +- If issues persist, check GitHub Actions logs for OIDC token errors |
| 186 | +- Verify `GITHUB_TOKEN` is passed (needed for creating Release PRs) |
| 187 | + |
| 188 | +### Workflow file validation failed |
| 189 | + |
| 190 | +npm does not validate the trusted publisher configuration when you save it. Double-check: |
| 191 | +- Repository name matches exactly |
| 192 | +- Organization/username matches exactly |
| 193 | +- Workflow filename includes `.yml` extension |
| 194 | +- No trailing spaces in any field |
0 commit comments