Skip to content

Commit bf759a6

Browse files
committed
publish to NPM via Action
1 parent 9250455 commit bf759a6

File tree

5 files changed

+206
-43
lines changed

5 files changed

+206
-43
lines changed

.github/workflows/publish.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Publish to npm
2+
3+
on:
4+
release:
5+
types: [published]
6+
workflow_dispatch:
7+
8+
jobs:
9+
publish:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v4
15+
16+
- name: Setup Node.js
17+
uses: actions/setup-node@v4
18+
with:
19+
node-version: '18'
20+
registry-url: 'https://registry.npmjs.org'
21+
22+
- name: Cache node modules
23+
uses: actions/cache@v3
24+
with:
25+
path: ~/.npm
26+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
27+
restore-keys: |
28+
${{ runner.os }}-node-
29+
30+
- name: Install dependencies
31+
run: npm ci
32+
33+
- name: Build library
34+
run: npm run build-package
35+
36+
- name: Test library
37+
run: npm test -- --watch=false --browsers=ChromeHeadless
38+
39+
- name: Publish to npm
40+
run: |
41+
cd dist/ngx-angular-query-builder
42+
npm publish
43+
env:
44+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

PUBLISH.md

Lines changed: 138 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,30 @@
1-
# Publishing to GitHub Package Registry
1+
# Publishing to npm Registry
22

3-
This guide explains how to publish the `ngx-angular-query-builder` library to GitHub Package Registry.
3+
This guide explains how to publish the `@csfloat/ngx-angular-query-builder` library to the npm registry.
44

55
## Prerequisites
66

7-
1. **GitHub Repository**: Ensure your code is pushed to a GitHub repository
8-
2. **GitHub Personal Access Token**: Create a token with `write:packages` scope
9-
3. **Updated Configuration**: Make sure all configuration files are properly set up
7+
1. **npm Account**: Create an account at [npmjs.com](https://www.npmjs.com/)
8+
2. **npm Access Token**: Create an automation token from your npm account settings
9+
3. **GitHub Repository**: Ensure your code is pushed to a GitHub repository
10+
4. **Organization Access**: Ensure you have publish permissions for the `@csfloat` organization on npm
1011

11-
## Local Publishing (Manual)
12+
## Setup Steps
13+
14+
### 1. Configure npm Token for GitHub Actions
15+
16+
1. **Create npm Access Token:**
17+
- Go to [npmjs.com](https://www.npmjs.com/) → Account Settings → Access Tokens
18+
- Click "Generate New Token" → "Automation"
19+
- Copy the token
20+
21+
2. **Add token to GitHub Secrets:**
22+
- Go to your GitHub repository → Settings → Secrets and variables → Actions
23+
- Click "New repository secret"
24+
- Name: `NPM_TOKEN`
25+
- Value: Your npm access token
26+
27+
### 2. Local Publishing (Manual)
1228

1329
If you want to publish manually:
1430

@@ -22,45 +38,142 @@ If you want to publish manually:
2238
cd dist/ngx-angular-query-builder
2339
```
2440

25-
3. **Login to GitHub Package Registry:**
41+
3. **Login to npm:**
2642
```bash
27-
npm login --registry=https://npm.pkg.github.com
43+
npm login
2844
```
29-
- Username: Your GitHub username (lowercase)
30-
- Password: Your GitHub Personal Access Token (classic)
45+
- Username: Your npm username
46+
- Password: Your npm password
47+
- Email: Your npm email
48+
- One-time password: If you have 2FA enabled
3149

3250
4. **Publish:**
3351
```bash
3452
npm publish
3553
```
3654

37-
## Installation for Users
55+
### 3. Automated Publishing (Recommended)
56+
57+
The project is configured for automated publishing via GitHub Actions.
3858

39-
Once published, users can install your package by:
59+
#### Publishing Process:
4060

41-
1. **Creating `.npmrc` in their project:**
61+
1. **Update version number:**
62+
```bash
63+
# Update version in projects/ngx-angular-query-builder/package.json
64+
# For example, change "19.0.0" to "19.0.1"
4265
```
43-
@YOUR_GITHUB_USERNAME:registry=https://npm.pkg.github.com
44-
//npm.pkg.github.com/:_authToken=THEIR_GITHUB_TOKEN
66+
67+
2. **Create a new release:**
68+
- Go to your GitHub repository
69+
- Click "Releases" → "Create a new release"
70+
- Tag version: `v19.0.1` (match your package version)
71+
- Release title: `Release v19.0.1`
72+
- Describe the changes
73+
- Click "Publish release"
74+
75+
3. **GitHub Actions will automatically:**
76+
- Install dependencies
77+
- Build the library
78+
- Run tests
79+
- Publish to npm
80+
81+
#### Manual Trigger:
82+
You can also manually trigger the workflow:
83+
- Go to Actions tab in your GitHub repository
84+
- Select "Publish to npm" workflow
85+
- Click "Run workflow"
86+
87+
## Version Management
88+
89+
Before publishing a new version:
90+
91+
1. **Update the library package.json:**
92+
```json
93+
// projects/ngx-angular-query-builder/package.json
94+
{
95+
"version": "19.0.1" // Update this
96+
}
4597
```
4698

47-
2. **Installing the package:**
99+
2. **Commit and tag:**
48100
```bash
49-
npm install @YOUR_GITHUB_USERNAME/ngx-angular-query-builder
101+
git add .
102+
git commit -m "Release v19.0.1"
103+
git tag v19.0.1
104+
git push origin main --tags
50105
```
51106

107+
## Installation for Users
108+
109+
Once published, users can install your package easily:
110+
111+
```bash
112+
npm install @csfloat/ngx-angular-query-builder
113+
```
114+
115+
No authentication required! 🎉
116+
52117
## Troubleshooting
53118

54119
### Common Issues:
55120

56121
1. **Authentication Error:**
57-
- Ensure you are using a GitHub classic access token with `write:packages` scope
58-
- Verify the token is not expired
122+
- Ensure your npm token is valid and has publish permissions
123+
- Check that the NPM_TOKEN secret is correctly set in GitHub
124+
- Verify you have access to publish under the `@csfloat` organization
125+
126+
2. **Organization Access:**
127+
- You must be a member of the `@csfloat` organization on npm
128+
- The organization must exist on npm
129+
- Your npm token must have permission to publish to the organization
130+
131+
3. **Version Already Published:**
132+
- You cannot publish the same version twice
133+
- Increment the version number in package.json
134+
135+
4. **Build Errors:**
136+
- Run `npm run build-package` locally to check for issues
137+
- Ensure all dependencies are correctly specified
138+
139+
### Useful Commands:
140+
141+
```bash
142+
# Check what will be published
143+
cd dist/ngx-angular-query-builder
144+
npm pack --dry-run
145+
146+
# View package info
147+
npm view @csfloat/ngx-angular-query-builder
148+
149+
# List published versions
150+
npm view @csfloat/ngx-angular-query-builder versions --json
151+
152+
# Check if organization exists
153+
npm org ls @csfloat
154+
```
155+
156+
## Security Notes
157+
158+
- Never commit npm tokens to your repository
159+
- Use GitHub secrets for sensitive information
160+
- Regularly rotate your npm access tokens
161+
- Consider enabling 2FA on your npm account
162+
163+
## Organization Setup
164+
165+
If the `@csfloat` organization doesn't exist on npm yet:
166+
167+
1. **Create the organization:**
168+
- Go to [npmjs.com](https://www.npmjs.com/)
169+
- Click your profile → "Add Organization"
170+
- Name: `csfloat`
171+
- Choose organization type (free for public packages)
59172

60-
2. **Package Not Found:**
61-
- Check the package name includes the @csfloat scope
62-
- Ensure the repository is public and you have access to it
173+
2. **Add team members:**
174+
- Invite other CSFloat team members to the organization
175+
- Set appropriate permissions for each member
63176

64-
4. **Workflow Failures:**
65-
- Check the Actions tab for detailed error logs
66-
- Ensure GITHUB_TOKEN has sufficient permissions
177+
3. **Configure organization settings:**
178+
- Set up organization profile and description
179+
- Configure package access policies if needed

README.md

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,10 @@ Use the following versions depending upon your angular version
3434

3535
# Installation
3636

37-
## From GitHub Package Registry
38-
39-
To install from GitHub Package Registry, you need to:
40-
41-
1. Create a `.npmrc` file in your project root with:
42-
```
43-
@your-github-username:registry=https://npm.pkg.github.com
44-
//npm.pkg.github.com/:_authToken=YOUR_GITHUB_TOKEN
45-
```
46-
47-
2. Install the package:
4837
```bash
4938
npm install @csfloat/ngx-angular-query-builder
5039
```
5140

52-
**Note:** You'll need a [GitHub Personal Access Token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token) with `read:packages` scope to install packages from GitHub Package Registry.
53-
5441
# Examples
5542

5643
npm install ngx-angular-query-builder
@@ -60,7 +47,7 @@ npm install ngx-angular-query-builder
6047
##### `app.module.ts`
6148

6249
```javascript
63-
import { NgxAngularQueryBuilderModule } from "ngx-angular-query-builder";
50+
import { NgxAngularQueryBuilderModule } from "@csfloat/ngx-angular-query-builder";
6451
import { AppComponent } from "./app.component"
6552

6653
@NgModule(imports: [
@@ -81,7 +68,7 @@ export class AppModule { }
8168
##### `app.component.ts`
8269

8370
```javascript
84-
import { QueryBuilderConfig } from 'ngx-angular-query-builder';
71+
import { QueryBuilderConfig } from '@csfloat/ngx-angular-query-builder';
8572

8673
export class AppComponent {
8774
query = {

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
"watch-package": "ng build ngx-angular-query-builder --watch --configuration development",
1010
"watch-demo": "ng build demo --watch --configuration development",
1111
"test": "ng test",
12-
"prettier": "npx prettier --write **"
12+
"prettier": "npx prettier --write **",
13+
"publish:dry-run": "npm run build-package && cd dist/ngx-angular-query-builder && npm pack --dry-run",
14+
"publish:local": "npm run build-package && cd dist/ngx-angular-query-builder && npm publish",
15+
"check:package": "npm view @csfloat/ngx-angular-query-builder",
16+
"check:org": "npm org ls @csfloat"
1317
},
1418
"private": true,
1519
"dependencies": {
@@ -44,4 +48,4 @@
4448
"ng-packagr": "19.2.2",
4549
"typescript": "5.8.3"
4650
}
47-
}
51+
}

projects/ngx-angular-query-builder/package.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,23 @@
77
"type": "git",
88
"url": "git+https://github.com/csfloat/ngx-angular-query-builder.git"
99
},
10+
"author": "CSFloat",
11+
"keywords": [
12+
"angular",
13+
"query-builder",
14+
"ngx",
15+
"typescript",
16+
"angular-query-builder",
17+
"query",
18+
"builder",
19+
"filter"
20+
],
21+
"homepage": "https://github.com/csfloat/ngx-angular-query-builder",
22+
"bugs": {
23+
"url": "https://github.com/csfloat/ngx-angular-query-builder/issues"
24+
},
1025
"publishConfig": {
11-
"registry": "https://npm.pkg.github.com"
26+
"access": "public"
1227
},
1328
"peerDependencies": {
1429
"@angular/common": "^19.2.14",

0 commit comments

Comments
 (0)