Skip to content

Commit 8b7eddf

Browse files
author
Brian J.
committed
Add publish action
1 parent 004b4d0 commit 8b7eddf

File tree

3 files changed

+74
-1
lines changed

3 files changed

+74
-1
lines changed

.github/workflows/publish.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Publish to NPM
2+
3+
permissions:
4+
contents: read
5+
id-token: write
6+
7+
on:
8+
push:
9+
tags:
10+
- 'v*' # Trigger on version tags like v1.0.0, v1.2.3, etc.
11+
12+
jobs:
13+
publish:
14+
environment: Release
15+
name: Publish to NPM
16+
runs-on: ubuntu-latest
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+
registry-url: 'https://registry.npmjs.org'
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: npm run lint
37+
38+
- name: Publish to NPM
39+
run: npm publish

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,33 @@ npm test
3939
npx vitest run --coverage
4040
```
4141

42+
#### Release Process
43+
44+
This package is automatically published to NPM via GitHub Actions when a new version tag is pushed.
45+
46+
To publish a new version:
47+
48+
1. **Bump the version** using one of these commands:
49+
50+
```bash
51+
npm run version:patch # For bug fixes (0.4.0 → 0.4.1)
52+
npm run version:minor # For new features (0.4.0 → 0.5.0)
53+
npm run version:major # For breaking changes (0.4.0 → 1.0.0)
54+
```
55+
56+
2. **Push the changes and tags**:
57+
58+
```bash
59+
npm run release
60+
```
61+
62+
This will run tests, linting, and push both commits and tags to GitHub.
63+
64+
3. **GitHub Actions will automatically**:
65+
- Run tests and linting
66+
- Publish to NPM with provenance
67+
- Use OIDC authentication for secure publishing
68+
4269
### ⚠️ **SECURITY WARNING**
4370

4471
**The `rawNumber` field contains UNSANITIZED user input and poses XSS risks if displayed in web applications.**

package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
"author": "bajohnson@hearsaycorp.com",
55
"license": "BSD-3-Clause",
66
"description": "Utility for extracting and validating phone numbers",
7+
"publishConfig": {
8+
"access": "public"
9+
},
710
"type": "module",
811
"main": "src",
912
"exports": {
@@ -22,7 +25,11 @@
2225
"test": "TZ=America/Los_Angeles vitest",
2326
"build": "node -e \"console.log('No build script for vanilla JS')\"",
2427
"prepare": "husky",
25-
"make-badges": "istanbul-badges-readme"
28+
"make-badges": "istanbul-badges-readme",
29+
"version:patch": "npm version patch",
30+
"version:minor": "npm version minor",
31+
"version:major": "npm version major",
32+
"release": "npm run test && npm run lint && git push && git push --tags"
2633
},
2734
"devDependencies": {
2835
"@eslint/js": "^9.38.0",

0 commit comments

Comments
 (0)