|
| 1 | +# GitHub Actions CI/CD Setup |
| 2 | + |
| 3 | +This project uses GitHub Actions for automated testing, building, and publishing to npm. |
| 4 | + |
| 5 | +## Workflows |
| 6 | + |
| 7 | +### 1. CI Workflow (`.github/workflows/ci.yml`) |
| 8 | + |
| 9 | +Runs on every push and pull request to `main` and `develop` branches. |
| 10 | + |
| 11 | +**What it does:** |
| 12 | +- Tests on Node.js 18.x and 20.x |
| 13 | +- Installs dependencies |
| 14 | +- Runs linter |
| 15 | +- Builds the library |
| 16 | +- Runs tests |
| 17 | +- Uploads build artifacts |
| 18 | + |
| 19 | +### 2. Publish Workflow (`.github/workflows/publish.yml`) |
| 20 | + |
| 21 | +Runs when a GitHub release is published or manually triggered. |
| 22 | + |
| 23 | +**What it does:** |
| 24 | +- Builds the library |
| 25 | +- Runs tests and linter |
| 26 | +- Publishes to npm with provenance |
| 27 | +- Creates a release summary |
| 28 | + |
| 29 | +## Setup Instructions |
| 30 | + |
| 31 | +### 1. Add NPM Token to GitHub Secrets |
| 32 | + |
| 33 | +1. **Generate npm token:** |
| 34 | + ```bash |
| 35 | + npm login |
| 36 | + npm token create |
| 37 | + ``` |
| 38 | + |
| 39 | +2. **Add to GitHub:** |
| 40 | + - Go to your repository → Settings → Secrets and variables → Actions |
| 41 | + - Click "New repository secret" |
| 42 | + - Name: `NPM_TOKEN` |
| 43 | + - Value: Your npm token from step 1 |
| 44 | + |
| 45 | +### 2. Publishing a New Version |
| 46 | + |
| 47 | +#### Option A: Using GitHub Releases (Recommended) |
| 48 | + |
| 49 | +1. **Update version in package.json:** |
| 50 | + ```bash |
| 51 | + npm version patch # or minor, or major |
| 52 | + ``` |
| 53 | + |
| 54 | +2. **Push changes and tags:** |
| 55 | + ```bash |
| 56 | + git push && git push --tags |
| 57 | + ``` |
| 58 | + |
| 59 | +3. **Create GitHub Release:** |
| 60 | + - Go to repository → Releases → Draft a new release |
| 61 | + - Choose the tag you just pushed |
| 62 | + - Add release notes |
| 63 | + - Click "Publish release" |
| 64 | + |
| 65 | + The workflow will automatically publish to npm! |
| 66 | + |
| 67 | +#### Option B: Manual Workflow Dispatch |
| 68 | + |
| 69 | +1. Go to Actions → Publish to NPM → Run workflow |
| 70 | +2. Enter the tag (e.g., `v1.0.0`) |
| 71 | +3. Click "Run workflow" |
| 72 | + |
| 73 | +### 3. Publishing Checklist |
| 74 | + |
| 75 | +Before publishing: |
| 76 | +- [ ] Update version in `package.json` |
| 77 | +- [ ] Update `CHANGELOG.md` with changes |
| 78 | +- [ ] Run `npm run build` locally to verify |
| 79 | +- [ ] Run tests with `npm test` |
| 80 | +- [ ] Commit and push all changes |
| 81 | +- [ ] Create and push git tag |
| 82 | +- [ ] Create GitHub release |
| 83 | + |
| 84 | +## NPM Package Settings |
| 85 | + |
| 86 | +The workflow publishes with: |
| 87 | +- **Provenance**: Cryptographic signatures linking the package to the source code |
| 88 | +- **Public access**: Package is publicly available |
| 89 | +- **Registry**: https://registry.npmjs.org |
| 90 | + |
| 91 | +## Troubleshooting |
| 92 | + |
| 93 | +### Build fails in CI |
| 94 | +- Check the Actions tab for error logs |
| 95 | +- Ensure all dependencies are in `package.json` |
| 96 | +- Verify the build works locally: `npm run build` |
| 97 | + |
| 98 | +### Publish fails |
| 99 | +- Verify `NPM_TOKEN` secret is set correctly |
| 100 | +- Ensure you're logged in to npm: `npm whoami` |
| 101 | +- Check if the version already exists on npm |
| 102 | +- Verify package name is available |
| 103 | + |
| 104 | +### Tests fail |
| 105 | +- Tests are currently set to `continue-on-error: true` |
| 106 | +- They won't block the build, but should be fixed |
| 107 | + |
| 108 | +## Local Testing |
| 109 | + |
| 110 | +Test the build process locally before pushing: |
| 111 | + |
| 112 | +```bash |
| 113 | +# Install dependencies |
| 114 | +npm ci |
| 115 | + |
| 116 | +# Run linter |
| 117 | +npm run lint |
| 118 | + |
| 119 | +# Build |
| 120 | +npm run build |
| 121 | + |
| 122 | +# Test (if available) |
| 123 | +npm test |
| 124 | + |
| 125 | +# Dry run publish (doesn't actually publish) |
| 126 | +npm publish --dry-run |
| 127 | +``` |
0 commit comments