Skip to content

Commit d06f2f4

Browse files
committed
feat: Add npm publishing workflow and fix notification registry tests
- Add GitHub Actions workflow for automatic npm publishing on version tags - Add release workflow with manual dispatch option - Add comprehensive publishing documentation - Fix notification registry test issues: - Fix trigger cleanup between tests - Handle table name mapping for UwU model - Fix TypeScript type errors and linting issues - Remove redundant example files - Update registry type definitions for better type safety
1 parent a501abc commit d06f2f4

11 files changed

Lines changed: 923 additions & 413 deletions

File tree

.github/PUBLISHING.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Publishing to npm
2+
3+
This repository is configured to automatically publish to npm when releases are created.
4+
5+
## Setup
6+
7+
### 1. NPM Token
8+
9+
You need to add an NPM automation token as a GitHub secret:
10+
11+
1. Log in to [npmjs.com](https://www.npmjs.com/)
12+
2. Go to your account settings → Access Tokens
13+
3. Generate a new token:
14+
- Type: `Automation`
15+
- Description: `pg-typesafe-triggers GitHub Actions`
16+
4. Copy the token
17+
5. Go to your GitHub repository → Settings → Secrets and variables → Actions
18+
6. Add a new secret:
19+
- Name: `NPM_TOKEN`
20+
- Value: The token you copied
21+
22+
## Publishing Methods
23+
24+
### Method 1: npm version (Recommended)
25+
26+
```bash
27+
# Bump version, create commit and tag
28+
npm version patch # or minor, major, or specific version like 0.3.1
29+
30+
# Push commit and tag
31+
git push origin main --tags
32+
```
33+
34+
The GitHub Actions workflow will automatically:
35+
- Run tests
36+
- Build the package
37+
- Publish to npm
38+
39+
### Method 2: GitHub Release
40+
41+
1. Create a GitHub release:
42+
- Go to Releases → Create a new release
43+
- Create a new tag (e.g., `v0.3.1`)
44+
- Write release notes
45+
- Publish release
46+
47+
### Method 3: Manual Workflow Dispatch
48+
49+
1. Go to Actions → Release workflow
50+
2. Click "Run workflow"
51+
3. Enter the version number (e.g., `0.3.1`)
52+
4. Click "Run workflow"
53+
54+
This will:
55+
- Update package.json version
56+
- Run tests
57+
- Build and publish to npm
58+
- Create a GitHub release
59+
60+
## Version Guidelines
61+
62+
- Follow [Semantic Versioning](https://semver.org/)
63+
- Patch releases (0.3.x): Bug fixes
64+
- Minor releases (0.x.0): New features (backwards compatible)
65+
- Major releases (x.0.0): Breaking changes
66+
67+
## Pre-publish Checklist
68+
69+
- [ ] All tests pass locally
70+
- [ ] Version number updated in package.json
71+
- [ ] CHANGELOG.md updated with release notes
72+
- [ ] README.md updated if needed
73+
- [ ] No uncommitted changes
74+
75+
## Troubleshooting
76+
77+
### "Version already exists" error
78+
79+
This means the version in package.json was already published. Update to a new version number.
80+
81+
### Authentication failed
82+
83+
Check that the NPM_TOKEN secret is correctly set in GitHub settings.
84+
85+
### Tests failing
86+
87+
The publish workflow runs tests first. Fix any failing tests before publishing.

.github/workflows/ci.yml

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ name: CI
33
on:
44
push:
55
branches: [main]
6+
tags:
7+
- 'v*'
68
pull_request:
79
branches: [main]
810

@@ -65,4 +67,34 @@ jobs:
6567
run: bun install
6668

6769
- name: Type check
68-
run: bunx tsc --noEmit
70+
run: bunx tsc --noEmit
71+
72+
publish:
73+
needs: [test, lint]
74+
runs-on: ubuntu-latest
75+
if: startsWith(github.ref, 'refs/tags/v')
76+
steps:
77+
- uses: actions/checkout@v4
78+
79+
- uses: oven-sh/setup-bun@v1
80+
with:
81+
bun-version: latest
82+
83+
- name: Install dependencies
84+
run: bun install
85+
86+
- name: Generate Prisma Client
87+
run: bunx prisma generate
88+
89+
- name: Build
90+
run: bun run build
91+
92+
- name: Configure npm
93+
run: |
94+
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
95+
npm whoami
96+
97+
- name: Publish to npm
98+
run: npm publish
99+
env:
100+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/release.yml

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
name: Release
2+
3+
on:
4+
release:
5+
types: [created]
6+
workflow_dispatch:
7+
inputs:
8+
version:
9+
description: 'Version to publish (e.g., 0.3.1)'
10+
required: true
11+
type: string
12+
13+
jobs:
14+
publish:
15+
runs-on: ubuntu-latest
16+
17+
services:
18+
postgres:
19+
image: postgres:15
20+
env:
21+
POSTGRES_USER: postgres
22+
POSTGRES_PASSWORD: postgres
23+
POSTGRES_DB: test
24+
options: >-
25+
--health-cmd pg_isready
26+
--health-interval 10s
27+
--health-timeout 5s
28+
--health-retries 5
29+
ports:
30+
- 5432:5432
31+
32+
steps:
33+
- uses: actions/checkout@v4
34+
35+
- uses: oven-sh/setup-bun@v1
36+
with:
37+
bun-version: latest
38+
39+
- uses: actions/setup-node@v4
40+
with:
41+
node-version: '20'
42+
registry-url: 'https://registry.npmjs.org'
43+
44+
- name: Install dependencies
45+
run: bun install
46+
47+
- name: Generate Prisma Client
48+
run: bunx prisma generate
49+
50+
- name: Push schema to database
51+
run: bunx prisma db push
52+
env:
53+
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/test
54+
55+
- name: Run tests
56+
run: bun test
57+
env:
58+
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/test
59+
TEST_DATABASE_URL: postgresql://postgres:postgres@localhost:5432/test
60+
61+
- name: Build
62+
run: bun run build
63+
64+
- name: Update version if manual trigger
65+
if: github.event_name == 'workflow_dispatch'
66+
run: |
67+
npm version ${{ github.event.inputs.version }} --no-git-tag-version
68+
echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_ENV
69+
70+
- name: Get version from package.json
71+
if: github.event_name == 'release'
72+
run: |
73+
echo "VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_ENV
74+
75+
- name: Check if version exists on npm
76+
run: |
77+
if npm view pg-typesafe-triggers@${{ env.VERSION }} > /dev/null 2>&1; then
78+
echo "Version ${{ env.VERSION }} already exists on npm"
79+
exit 1
80+
fi
81+
82+
- name: Publish to npm
83+
run: npm publish
84+
env:
85+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
86+
87+
- name: Create GitHub Release (if manual)
88+
if: github.event_name == 'workflow_dispatch'
89+
uses: actions/create-release@v1
90+
env:
91+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
92+
with:
93+
tag_name: v${{ env.VERSION }}
94+
release_name: Release v${{ env.VERSION }}
95+
body: |
96+
## What's Changed
97+
98+
See [CHANGELOG.md](https://github.com/bewinxed/pg-typesafe-triggers/blob/main/CHANGELOG.md) for details.
99+
100+
## Installation
101+
102+
```bash
103+
npm install pg-typesafe-triggers@${{ env.VERSION }}
104+
# or
105+
bun add pg-typesafe-triggers@${{ env.VERSION }}
106+
```
107+
draft: false
108+
prerelease: false

examples/basic-usage.ts

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)