Skip to content

Commit 3d276a9

Browse files
facundofariasclaude
andcommitted
ci: Add automated npm publishing workflow
Add separate publish workflow that depends on CI passing: Features: - Runs automatically when code merges to main - Waits for CI workflow to complete successfully - Publishes to npm with NPM_TOKEN secret - Creates GitHub Release with version tag - Verifies package contents before publishing Setup: - Add .github/workflows/publish.yml - Add .github/workflows/README.md with setup instructions - Requires NPM_TOKEN secret in GitHub repository settings Workflow dependency chain: 1. CI workflow runs tests and builds 2. Publish workflow waits for CI success 3. Package published to npm 4. GitHub release created automatically See .github/workflows/README.md for setup instructions 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent d998693 commit 3d276a9

File tree

2 files changed

+233
-0
lines changed

2 files changed

+233
-0
lines changed

.github/workflows/README.md

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
# GitHub Actions CI/CD Workflows
2+
3+
This repository uses GitHub Actions for continuous integration and automated npm publishing.
4+
5+
## Workflows
6+
7+
### 1. CI Workflow (`ci.yml`)
8+
9+
**Triggers**: Push or PR to `main` or `develop` branches
10+
11+
**What it does**:
12+
- Runs on Node.js 18.x, 20.x, and 22.x
13+
- Lints code with ESLint
14+
- Type checks with TypeScript
15+
- Runs full test suite (108 tests)
16+
- Builds the project
17+
- Verifies build artifacts exist
18+
- Tests module loading
19+
20+
**Status**: Must pass before code can be merged
21+
22+
### 2. Publish Workflow (`publish.yml`)
23+
24+
**Triggers**: Automatically after CI workflow succeeds on `main` branch
25+
26+
**What it does**:
27+
1. Waits for CI workflow to complete successfully
28+
2. Checks out code and installs dependencies
29+
3. Builds the project
30+
4. Extracts version from `package.json`
31+
5. Verifies package contents with `npm pack --dry-run`
32+
6. Publishes to npm registry (public package)
33+
7. Creates GitHub Release with tag `v{version}`
34+
35+
**Dependencies**: Only runs if CI workflow passes
36+
37+
## Setup Requirements
38+
39+
### npm Token (Required for Publishing)
40+
41+
You need to add an `NPM_TOKEN` secret to your GitHub repository:
42+
43+
1. **Generate npm token**:
44+
```bash
45+
npm login
46+
npm token create --type automation
47+
```
48+
49+
2. **Add to GitHub**:
50+
- Go to: `https://github.com/deployhq/deployhq-mcp-server/settings/secrets/actions`
51+
- Click "New repository secret"
52+
- Name: `NPM_TOKEN`
53+
- Value: Your npm automation token
54+
55+
### GitHub Token (Automatic)
56+
57+
The `GITHUB_TOKEN` is automatically provided by GitHub Actions - no setup needed.
58+
59+
## Publishing Process
60+
61+
### Automatic Publishing (Recommended)
62+
63+
When you merge to `main`:
64+
65+
```bash
66+
# 1. Create PR with version bump
67+
git checkout -b release/v1.0.1
68+
npm version patch # or minor, major
69+
git push origin release/v1.0.1
70+
71+
# 2. Create and merge PR to main
72+
# GitHub Actions will automatically:
73+
# - Run CI tests
74+
# - Publish to npm (if CI passes)
75+
# - Create GitHub release
76+
```
77+
78+
### Manual Publishing (Not Recommended)
79+
80+
If you need to publish manually:
81+
82+
```bash
83+
npm run build
84+
npm publish
85+
```
86+
87+
## Version Management
88+
89+
Follow semantic versioning (SemVer):
90+
91+
- **Patch** (`1.0.x`): Bug fixes, small changes
92+
```bash
93+
npm version patch
94+
```
95+
96+
- **Minor** (`1.x.0`): New features, backwards compatible
97+
```bash
98+
npm version minor
99+
```
100+
101+
- **Major** (`x.0.0`): Breaking changes
102+
```bash
103+
npm version major
104+
```
105+
106+
## Workflow Diagram
107+
108+
```
109+
┌─────────────────────────────────────────────────────┐
110+
│ Push/PR to main/develop │
111+
└────────────────┬────────────────────────────────────┘
112+
113+
114+
┌─────────────────────────────────────────────────────┐
115+
│ CI Workflow (ci.yml) │
116+
│ ├─ Lint │
117+
│ ├─ Type Check │
118+
│ ├─ Test (108 tests) │
119+
│ ├─ Build │
120+
│ └─ Verify artifacts │
121+
└────────────────┬────────────────────────────────────┘
122+
123+
│ (only on main branch)
124+
125+
┌─────────────────────────────────────────────────────┐
126+
│ Publish Workflow (publish.yml) │
127+
│ ├─ Wait for CI to succeed │
128+
│ ├─ Build project │
129+
│ ├─ Verify package │
130+
│ ├─ Publish to npm │
131+
│ └─ Create GitHub Release │
132+
└─────────────────────────────────────────────────────┘
133+
```
134+
135+
## Monitoring
136+
137+
### View Workflow Runs
138+
- GitHub Actions tab: https://github.com/deployhq/deployhq-mcp-server/actions
139+
140+
### Check Published Packages
141+
- npm package: https://www.npmjs.com/package/deployhq-mcp-server
142+
- GitHub Releases: https://github.com/deployhq/deployhq-mcp-server/releases
143+
144+
## Troubleshooting
145+
146+
### Publish workflow doesn't run
147+
- Verify CI workflow completed successfully
148+
- Check that push was to `main` branch
149+
- Check GitHub Actions tab for workflow status
150+
151+
### npm publish fails
152+
- Verify `NPM_TOKEN` secret is set correctly
153+
- Check token hasn't expired: `npm token list`
154+
- Verify package name isn't taken
155+
- Check version hasn't been published already
156+
157+
### GitHub Release fails
158+
- Usually safe to ignore if npm publish succeeded
159+
- Can manually create release from GitHub UI
160+
- Check `GITHUB_TOKEN` permissions
161+
162+
## Security Notes
163+
164+
- Never commit `NPM_TOKEN` to repository
165+
- Use automation tokens for CI/CD, not personal tokens
166+
- Rotate tokens regularly
167+
- Limit token scope to publishing only

.github/workflows/publish.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Publish to npm
2+
3+
on:
4+
workflow_run:
5+
workflows: ["CI"]
6+
types: [completed]
7+
branches: [main]
8+
9+
jobs:
10+
publish:
11+
name: Publish to npm
12+
runs-on: ubuntu-latest
13+
14+
# Only run if CI workflow succeeded
15+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
21+
- name: Setup Node.js
22+
uses: actions/setup-node@v4
23+
with:
24+
node-version: '20.x'
25+
registry-url: 'https://registry.npmjs.org'
26+
cache: 'npm'
27+
28+
- name: Install dependencies
29+
run: npm ci
30+
31+
- name: Build project
32+
run: npm run build
33+
34+
- name: Get package version
35+
id: package-version
36+
run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
37+
38+
- name: Verify package contents
39+
run: |
40+
echo "Verifying package contents for v${{ steps.package-version.outputs.version }}..."
41+
ls -la dist/
42+
npm pack --dry-run
43+
44+
- name: Publish to npm
45+
run: npm publish --access public
46+
env:
47+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
48+
49+
- name: Create GitHub Release
50+
uses: actions/create-release@v1
51+
env:
52+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
53+
with:
54+
tag_name: v${{ steps.package-version.outputs.version }}
55+
release_name: Release v${{ steps.package-version.outputs.version }}
56+
body: |
57+
🚀 Published to npm: https://www.npmjs.com/package/deployhq-mcp-server/v/${{ steps.package-version.outputs.version }}
58+
59+
## Installation
60+
```bash
61+
npx deployhq-mcp-server
62+
```
63+
64+
See [README](https://github.com/deployhq/deployhq-mcp-server#readme) for full documentation.
65+
draft: false
66+
prerelease: false

0 commit comments

Comments
 (0)