Skip to content

Commit ee901ab

Browse files
Merge pull request #6 from Codegyan-LLC/dev
v1.0.6
2 parents f5609ae + fcb2ecd commit ee901ab

File tree

1 file changed

+69
-27
lines changed

1 file changed

+69
-27
lines changed

.github/workflows/npm-publish.yml

Lines changed: 69 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,76 @@
1-
name: Git Package Release & Publish oon NPM
1+
# 🚀 Release & Publish Workflow
2+
#
3+
# This GitHub Actions workflow automates the full release process:
4+
#
5+
# 1. On every push to the `main` branch:
6+
# - Bumps the version in `package.json` automatically (patch level: v1.0.6 → v1.0.7).
7+
# - Commits and pushes the new version + Git tag back to `main`.
8+
# - Creates a GitHub Release with the new tag.
9+
#
10+
# 2. Build Job:
11+
# - Runs `npm install` and `npm run build`.
12+
# - Archives the build output (`dist/`) as an artifact to pass to the next job.
13+
#
14+
# 3. Publish to NPM:
15+
# - Downloads the build artifact (`dist/`).
16+
# - Publishes it to the npm registry using the `NPM_AUTH_TOKEN` secret.
17+
#
18+
# 🔑 Requirements:
19+
# - `secrets.PERSONAL_TOKEN` → A GitHub Personal Access Token with `repo` scope (used to push to protected `main`).
20+
# - `secrets.NPM_AUTH_TOKEN` → An npm token with publish rights.
21+
#
22+
# ✅ This ensures every commit to `main` automatically:
23+
# → bumps the version
24+
# → creates a GitHub Release
25+
# → builds the package
26+
# → publishes the compiled output to npm.
27+
#
28+
# ------------------------------------------------------------------------
29+
30+
31+
name: Release Git Package & Publish on NPM
232

333
on:
434
push:
535
branches:
636
- main
737

8-
permissions:
9-
contents: write # needed to push commits, tags, and create releases
10-
packages: write # needed for publishing GitHub packages (optional)
11-
1238
jobs:
1339
release:
1440
runs-on: ubuntu-latest
1541
outputs:
1642
version: ${{ steps.version.outputs.new_version }}
1743

1844
steps:
19-
# Checkout repo
2045
- name: Checkout code
2146
uses: actions/checkout@v4
2247

23-
# Setup Node.js
2448
- name: Setup Node.js
2549
uses: actions/setup-node@v4
2650
with:
27-
node-version: '24'
51+
node-version: 24
2852

29-
# Git identity (required for npm version)
3053
- name: Setup Git identity
3154
run: |
3255
git config user.name "github-actions[bot]"
3356
git config user.email "github-actions[bot]@users.noreply.github.com"
3457
35-
# Install dependencies
3658
- name: Install dependencies
3759
run: npm install
3860

39-
# Bump version dynamically
4061
- name: Bump version
4162
id: version
4263
run: |
4364
NEW_VERSION=$(npm version patch -m "chore(release): v%s [skip ci]")
4465
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
4566
46-
# Push changes (commit + tag)
47-
- name: Push changes
67+
- name: Push version bump and tag
4868
uses: ad-m/github-push-action@v0.8.0
4969
with:
50-
github_token: ${{ secrets.GITHUB_TOKEN }}
70+
github_token: ${{ secrets.PERSONAL_TOKEN }} # ← use PAT, since main is protected
5171
branch: main
5272
tags: true
5373

54-
# Create GitHub Release
5574
- name: Create GitHub Release
5675
uses: softprops/action-gh-release@v2
5776
with:
@@ -60,27 +79,50 @@ jobs:
6079
env:
6180
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6281

63-
publish-npm:
64-
needs: release # ⬅ Runs only after release is successful
82+
build:
83+
needs: release
6584
runs-on: ubuntu-latest
66-
6785
steps:
68-
- name: Checkout code
69-
uses: actions/checkout@v4
86+
- uses: actions/checkout@v4
7087

71-
- name: Setup Node.js
72-
uses: actions/setup-node@v4
88+
- uses: actions/setup-node@v4
7389
with:
74-
node-version: '24'
75-
registry-url: 'https://registry.npmjs.org/'
90+
node-version: 24
7691

7792
- name: Install dependencies
7893
run: npm install
7994

8095
- name: Build package
8196
run: npm run build
8297

83-
- name: Publish to NPM
84-
run: npm publish --access public
98+
- name: Archive build
99+
run: tar -czf dist.tar.gz dist
100+
- name: Upload artifact
101+
uses: actions/upload-artifact@v4
102+
with:
103+
name: dist
104+
path: dist.tar.gz
105+
106+
publish-npm:
107+
needs: build
108+
runs-on: ubuntu-latest
109+
steps:
110+
- uses: actions/checkout@v4
111+
112+
- uses: actions/setup-node@v4
113+
with:
114+
node-version: 24
115+
registry-url: https://registry.npmjs.org/
116+
117+
- name: Download build artifact
118+
uses: actions/download-artifact@v4
119+
with:
120+
name: dist
121+
122+
- name: Extract build
123+
run: tar -xzf dist.tar.gz
124+
125+
- name: Publish to npm
126+
run: npm publish dist --access public
85127
env:
86-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
128+
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}

0 commit comments

Comments
 (0)