|
| 1 | +# CI/CD Setup Guide |
| 2 | + |
| 3 | +This guide will help you set up automated testing, building, and publishing for the `otel-instrumentation-postgres` package. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +1. **GitHub Repository**: Your code should be pushed to GitHub |
| 8 | +2. **npm Account**: You need an npm account to publish packages |
| 9 | +3. **GitHub Actions**: Enabled on your repository |
| 10 | + |
| 11 | +## Step 1: Create npm Token |
| 12 | + |
| 13 | +1. Go to [npmjs.com](https://www.npmjs.com) and log in |
| 14 | +2. Click on your profile picture → "Access Tokens" |
| 15 | +3. Click "Generate New Token" |
| 16 | +4. Select "Automation" token type |
| 17 | +5. Copy the generated token (you won't see it again!) |
| 18 | + |
| 19 | +## Step 2: Add npm Token to GitHub Secrets |
| 20 | + |
| 21 | +1. Go to your GitHub repository |
| 22 | +2. Click "Settings" → "Secrets and variables" → "Actions" |
| 23 | +3. Click "New repository secret" |
| 24 | +4. Name: `NPM_TOKEN` |
| 25 | +5. Value: Paste your npm token from Step 1 |
| 26 | +6. Click "Add secret" |
| 27 | + |
| 28 | +## Step 3: Verify GitHub Actions Workflows |
| 29 | + |
| 30 | +The following workflows are configured: |
| 31 | + |
| 32 | +### `ci.yml` - Continuous Integration |
| 33 | +- **Triggers**: Push to main, pull requests (excludes example directory) |
| 34 | +- **Actions**: Runs tests, linting, and builds |
| 35 | +- **Purpose**: Ensures code quality on every change |
| 36 | + |
| 37 | +### `release.yml` - Release Pipeline |
| 38 | +- **Triggers**: Version tags (e.g., `v1.0.0`) (excludes example directory) |
| 39 | +- **Actions**: Tests, builds, publishes to npm, creates GitHub release |
| 40 | +- **Purpose**: Complete release automation |
| 41 | + |
| 42 | +### Important Notes |
| 43 | +- **Example directory changes do NOT trigger pipelines** - The example is for demonstration only |
| 44 | +- **Only changes to the main library code** will trigger CI workflows |
| 45 | +- **Version tags trigger the complete release process** regardless of what files changed |
| 46 | + |
| 47 | +## Step 4: Test the Setup |
| 48 | + |
| 49 | +1. **Push your code**: |
| 50 | + ```bash |
| 51 | + git add . |
| 52 | + git commit -m "feat: add CI/CD workflows" |
| 53 | + git push origin main |
| 54 | + ``` |
| 55 | + |
| 56 | +2. **Check GitHub Actions**: Go to your repository → "Actions" tab |
| 57 | +3. **Verify the CI workflow runs** and all tests pass |
| 58 | + |
| 59 | +## Step 5: Make Your First Release |
| 60 | + |
| 61 | +### Option A: Using the Release Script (Recommended) |
| 62 | + |
| 63 | +```bash |
| 64 | +# For a patch release (1.0.0 → 1.0.1) |
| 65 | +npm run release:patch |
| 66 | + |
| 67 | +# For a minor release (1.0.0 → 1.1.0) |
| 68 | +npm run release:minor |
| 69 | + |
| 70 | +# For a major release (1.0.0 → 2.0.0) |
| 71 | +npm run release:major |
| 72 | +``` |
| 73 | + |
| 74 | +### Option B: Manual Release |
| 75 | + |
| 76 | +```bash |
| 77 | +# 1. Bump version in lib/package.json |
| 78 | +cd lib |
| 79 | +npm version patch # or minor/major |
| 80 | +cd .. |
| 81 | + |
| 82 | +# 2. Commit and tag |
| 83 | +git add . |
| 84 | +git commit -m "chore: bump version to X.Y.Z" |
| 85 | +git tag vX.Y.Z |
| 86 | + |
| 87 | +# 3. Push |
| 88 | +git push origin main |
| 89 | +git push origin vX.Y.Z |
| 90 | +``` |
| 91 | + |
| 92 | +## What Happens During Release |
| 93 | + |
| 94 | +1. **Tests Run**: All tests must pass |
| 95 | +2. **Package Builds**: TypeScript compilation and bundling |
| 96 | +3. **npm Publish**: Package is published to npm registry |
| 97 | +4. **GitHub Release**: Release notes are created automatically |
| 98 | + |
| 99 | +## Troubleshooting |
| 100 | + |
| 101 | +### Common Issues |
| 102 | + |
| 103 | +**"npm publish failed"** |
| 104 | +- Check that `NPM_TOKEN` secret is set correctly |
| 105 | +- Verify your npm account has permission to publish |
| 106 | +- Ensure package name is available on npm |
| 107 | + |
| 108 | +**"Tests failing"** |
| 109 | +- Run tests locally: `npm test` |
| 110 | +- Check for linting issues: `npm run lint` |
| 111 | +- Fix any failing tests before releasing |
| 112 | + |
| 113 | +**"Build failing"** |
| 114 | +- Check TypeScript compilation: `npm run build` |
| 115 | +- Verify all dependencies are installed |
| 116 | +- Check for missing files in the build |
| 117 | + |
| 118 | +**"Pipeline not triggering"** |
| 119 | +- Ensure you're not only changing files in the `example/` directory |
| 120 | +- Check that your changes are in the `lib/` directory or root files |
| 121 | +- Verify you're pushing to the main branch |
| 122 | + |
| 123 | +### Getting Help |
| 124 | + |
| 125 | +1. Check the GitHub Actions logs for detailed error messages |
| 126 | +2. Verify all secrets are set correctly |
| 127 | +3. Ensure you're on the main branch when releasing |
| 128 | +4. Check that the working directory is clean |
| 129 | + |
| 130 | +## Best Practices |
| 131 | + |
| 132 | +1. **Always test locally** before pushing |
| 133 | +2. **Use semantic versioning** (patch/minor/major) |
| 134 | +3. **Write good commit messages** for better release notes |
| 135 | +4. **Review the generated release notes** before publishing |
| 136 | +5. **Test the published package** in a new project |
| 137 | +6. **Keep example changes separate** from library changes |
| 138 | + |
| 139 | +## Security Notes |
| 140 | + |
| 141 | +- Never commit the `NPM_TOKEN` to your repository |
| 142 | +- Use GitHub Secrets for all sensitive data |
| 143 | +- Regularly rotate your npm tokens |
| 144 | +- Review GitHub Actions permissions |
| 145 | + |
| 146 | +## Next Steps |
| 147 | + |
| 148 | +After your first successful release: |
| 149 | + |
| 150 | +1. **Monitor the package**: Check npm downloads and GitHub stars |
| 151 | +2. **Respond to issues**: Set up issue templates and contribution guidelines |
| 152 | +3. **Documentation**: Keep README and examples up to date |
| 153 | +4. **Community**: Engage with users and contributors |
0 commit comments