|
| 1 | +# Publishing cortex-auth Package |
| 2 | + |
| 3 | +This guide explains how to publish the auth package to npm and GitHub Packages. |
| 4 | + |
| 5 | +## Configuration Overview |
| 6 | + |
| 7 | +The auth package is configured for publishing to: |
| 8 | +- **npm**: Published as `cortex-auth` (manual via script) |
| 9 | +- **GitHub Packages**: Published as `@cortex-reply/auth` (automatic via GitHub Actions) |
| 10 | + |
| 11 | +## Prerequisites |
| 12 | + |
| 13 | +### 1. NPM Token for npm Registry |
| 14 | +1. Go to [npmjs.com](https://www.npmjs.com) |
| 15 | +2. Create an account if you don't have one |
| 16 | +3. Navigate to Access Tokens → Generate New Token |
| 17 | +4. Choose "Automation" or "Publish" level access |
| 18 | +5. Add as a GitHub Actions secret named `NPM_TOKEN` |
| 19 | + |
| 20 | +### 2. GitHub Token |
| 21 | +The `GITHUB_TOKEN` is automatically provided by GitHub Actions for publishing to GitHub Packages. |
| 22 | + |
| 23 | +## Publishing |
| 24 | + |
| 25 | +### Publish to npm |
| 26 | +```bash |
| 27 | +# Set your npm token |
| 28 | +export NPM_TOKEN=<your-npm-token> |
| 29 | + |
| 30 | +# Run from the root directory |
| 31 | +bash scripts/publish-auth.sh |
| 32 | +``` |
| 33 | + |
| 34 | +### Publish to GitHub Packages (Automatic) |
| 35 | +Publishing to GitHub Packages happens automatically via GitHub Actions workflow when you create a tag matching `auth-v*`. |
| 36 | + |
| 37 | +```bash |
| 38 | +# Create a release tag |
| 39 | +git tag auth-v0.0.2 |
| 40 | +git push origin auth-v0.0.2 |
| 41 | +``` |
| 42 | + |
| 43 | +This will trigger the workflow defined in [.github/workflows/publish-auth.yml](.github/workflows/publish-auth.yml). |
| 44 | + |
| 45 | +#### Or trigger manually: |
| 46 | +Go to Actions → "Publish Auth Package" → Run workflow → Select branch and click "Run workflow" |
| 47 | + |
| 48 | +## Installation for Users |
| 49 | + |
| 50 | +### Install from npm |
| 51 | +```bash |
| 52 | +npm install cortex-auth |
| 53 | +# or |
| 54 | +yarn add cortex-auth |
| 55 | +# or |
| 56 | +pnpm add cortex-auth |
| 57 | +``` |
| 58 | + |
| 59 | +### Install from GitHub Packages |
| 60 | +Add to `.npmrc`: |
| 61 | +``` |
| 62 | +@cortex-reply:registry=https://npm.pkg.github.com |
| 63 | +//npm.pkg.github.com/:_authToken=<your-github-token> |
| 64 | +``` |
| 65 | + |
| 66 | +Then install: |
| 67 | +```bash |
| 68 | +npm install @cortex-reply/auth |
| 69 | +# or |
| 70 | +yarn add @cortex-reply/auth |
| 71 | +# or |
| 72 | +pnpm add @cortex-reply/auth |
| 73 | +``` |
| 74 | + |
| 75 | +## Package Configuration Details |
| 76 | + |
| 77 | +### package.json Fields |
| 78 | +- **name**: `cortex-auth` (for npm) |
| 79 | +- **publishConfig**: Specifies npm registry and public access |
| 80 | +- **repository**: Links to the GitHub repository with the package directory |
| 81 | +- **keywords**: Helps with npm discoverability |
| 82 | + |
| 83 | +### .npmrc Configuration |
| 84 | +The `.npmrc` file in `packages/auth/` handles: |
| 85 | +- Routing `@cortex-reply` scope to GitHub Packages |
| 86 | +- Using the `GITHUB_TOKEN` environment variable for authentication |
| 87 | +- Default registry pointing to npm |
| 88 | + |
| 89 | +## Troubleshooting |
| 90 | + |
| 91 | +### Authentication Errors |
| 92 | +- Verify `NPM_TOKEN` is set correctly for npm publishing |
| 93 | +- GitHub token is automatically provided by GitHub Actions |
| 94 | + |
| 95 | +### Version Already Published |
| 96 | +- Increment the version in `packages/auth/package.json` |
| 97 | +- Create a new tag for GitHub Packages: `git tag auth-v<new-version>` |
| 98 | + |
| 99 | +### Workflow Not Triggering |
| 100 | +- Verify the tag matches the pattern `auth-v*` |
| 101 | +- Check workflow permissions in repository settings |
| 102 | + |
| 103 | +## Setting Up GitHub Secrets |
| 104 | + |
| 105 | +1. Go to Settings → Secrets and variables → Actions |
| 106 | +2. Click "New repository secret" |
| 107 | +3. Add `NPM_TOKEN` with your npm token value |
| 108 | +4. GitHub provides `GITHUB_TOKEN` automatically |
| 109 | + |
| 110 | +## Workflow Details |
| 111 | + |
| 112 | +The GitHub Actions workflow (`.github/workflows/publish-auth.yml`): |
| 113 | +1. Triggers on tags matching `auth-v*` or manual workflow dispatch |
| 114 | +2. Checks out the code |
| 115 | +3. Sets up Node.js with GitHub Packages registry |
| 116 | +4. Installs dependencies |
| 117 | +5. Builds the auth package |
| 118 | +6. Temporarily updates the package name to `@cortex-reply/auth` |
| 119 | +7. Publishes to GitHub Packages |
| 120 | +8. Restores the original package name |
| 121 | +9. Creates a GitHub Release |
0 commit comments