Skip to content

Commit 7a19601

Browse files
committed
feat: add comprehensive CI/CD pipeline and release automation
1 parent a51bc1e commit 7a19601

File tree

7 files changed

+586
-68
lines changed

7 files changed

+586
-68
lines changed

.github/workflows/ci.yml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: CI/CD
2+
3+
on:
4+
push:
5+
branches: [main]
6+
tags: ['v*']
7+
pull_request:
8+
branches: [main]
9+
10+
jobs:
11+
test:
12+
name: Test
13+
runs-on: ubuntu-latest
14+
defaults:
15+
run:
16+
working-directory: ./lib
17+
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v4
21+
22+
- name: Setup Node.js
23+
uses: actions/setup-node@v4
24+
with:
25+
node-version: '20'
26+
cache: 'npm'
27+
cache-dependency-path: './lib/package-lock.json'
28+
29+
- name: Install dependencies
30+
run: npm ci
31+
32+
- name: Run tests
33+
run: npm test
34+
35+
- name: Run linting
36+
run: npx biome check .
37+
38+
- name: Build package
39+
run: npm run build
40+
41+
publish:
42+
name: Publish to npm
43+
runs-on: ubuntu-latest
44+
needs: test
45+
if: startsWith(github.ref, 'refs/tags/v')
46+
defaults:
47+
run:
48+
working-directory: ./lib
49+
50+
steps:
51+
- name: Checkout code
52+
uses: actions/checkout@v4
53+
54+
- name: Setup Node.js
55+
uses: actions/setup-node@v4
56+
with:
57+
node-version: '20'
58+
registry-url: 'https://registry.npmjs.org'
59+
cache: 'npm'
60+
cache-dependency-path: './lib/package-lock.json'
61+
62+
- name: Install dependencies
63+
run: npm ci
64+
65+
- name: Run tests
66+
run: npm test
67+
68+
- name: Build package
69+
run: npm run build
70+
71+
- name: Publish to npm
72+
run: npm publish --access public
73+
env:
74+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
75+
76+
release:
77+
name: Create Release
78+
runs-on: ubuntu-latest
79+
needs: publish
80+
if: startsWith(github.ref, 'refs/tags/v')
81+
steps:
82+
- name: Checkout code
83+
uses: actions/checkout@v4
84+
85+
- name: Create Release
86+
uses: actions/create-release@v1
87+
env:
88+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
89+
with:
90+
tag_name: ${{ github.ref }}
91+
release_name: Release ${{ github.ref }}
92+
draft: false
93+
prerelease: false

.github/workflows/example.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Example Build
2+
3+
on:
4+
push:
5+
branches: [main]
6+
paths: ['example/**']
7+
pull_request:
8+
branches: [main]
9+
paths: ['example/**']
10+
11+
jobs:
12+
build-example:
13+
name: Build Example
14+
runs-on: ubuntu-latest
15+
defaults:
16+
run:
17+
working-directory: ./example
18+
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
23+
- name: Setup Node.js
24+
uses: actions/setup-node@v4
25+
with:
26+
node-version: '20'
27+
cache: 'npm'
28+
cache-dependency-path: './example/package-lock.json'
29+
30+
- name: Install dependencies
31+
run: npm ci
32+
33+
- name: Build example
34+
run: npm run build

.github/workflows/release.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags: ['v*']
6+
7+
jobs:
8+
release:
9+
name: Release
10+
runs-on: ubuntu-latest
11+
defaults:
12+
run:
13+
working-directory: ./lib
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Setup Node.js
22+
uses: actions/setup-node@v4
23+
with:
24+
node-version: '20'
25+
registry-url: 'https://registry.npmjs.org'
26+
cache: 'npm'
27+
cache-dependency-path: './lib/package-lock.json'
28+
29+
- name: Install dependencies
30+
run: npm ci
31+
32+
- name: Run tests
33+
run: npm test
34+
35+
- name: Build package
36+
run: npm run build
37+
38+
- name: Publish to npm
39+
run: npm publish --access public
40+
env:
41+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
42+
43+
- name: Create GitHub Release
44+
uses: actions/create-release@v1
45+
env:
46+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
47+
with:
48+
tag_name: ${{ github.ref }}
49+
release_name: Release ${{ github.ref }}
50+
body: |
51+
## What's Changed
52+
53+
This release includes:
54+
- OpenTelemetry instrumentation for postgres.js
55+
- Query performance monitoring
56+
- Connection tracking
57+
- Comprehensive metrics and traces
58+
59+
## Installation
60+
61+
```bash
62+
npm install otel-instrumentation-postgres
63+
```
64+
65+
## Quick Start
66+
67+
```typescript
68+
import postgres from "postgres";
69+
import { createOTELEmitter } from "otel-instrumentation-postgres";
70+
71+
const sql = postgres(process.env.DATABASE_URL);
72+
const instrumentedSql = createOTELEmitter(sql);
73+
74+
// All queries are now tracked automatically
75+
const users = await instrumentedSql`SELECT * FROM users`;
76+
```
77+
draft: false
78+
prerelease: false

docs/CI-CD-SETUP.md

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
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 already configured:
31+
32+
### `ci.yml` - Continuous Integration
33+
- **Triggers**: Push to main, pull requests, version tags
34+
- **Actions**: Runs tests, linting, and builds
35+
- **Purpose**: Ensures code quality on every change
36+
37+
### `release.yml` - Automated Releases
38+
- **Triggers**: Version tags (e.g., `v1.0.0`)
39+
- **Actions**: Publishes to npm, creates GitHub release
40+
- **Purpose**: Automated package publishing
41+
42+
### `example.yml` - Example Build
43+
- **Triggers**: Changes to example directory
44+
- **Actions**: Builds the example application
45+
- **Purpose**: Ensures example code works
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+
### Getting Help
119+
120+
1. Check the GitHub Actions logs for detailed error messages
121+
2. Verify all secrets are set correctly
122+
3. Ensure you're on the main branch when releasing
123+
4. Check that the working directory is clean
124+
125+
## Best Practices
126+
127+
1. **Always test locally** before pushing
128+
2. **Use semantic versioning** (patch/minor/major)
129+
3. **Write good commit messages** for better release notes
130+
4. **Review the generated release notes** before publishing
131+
5. **Test the published package** in a new project
132+
133+
## Security Notes
134+
135+
- Never commit the `NPM_TOKEN` to your repository
136+
- Use GitHub Secrets for all sensitive data
137+
- Regularly rotate your npm tokens
138+
- Review GitHub Actions permissions
139+
140+
## Next Steps
141+
142+
After your first successful release:
143+
144+
1. **Monitor the package**: Check npm downloads and GitHub stars
145+
2. **Respond to issues**: Set up issue templates and contribution guidelines
146+
3. **Documentation**: Keep README and examples up to date
147+
4. **Community**: Engage with users and contributors

0 commit comments

Comments
 (0)