Skip to content

Commit 5abc7eb

Browse files
committed
chore(release): add GitHub Actions workflow for automated versioning and publishing
1 parent 5562c84 commit 5abc7eb

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

.github/changeset-version.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// .github/changeset-version.js
2+
import { execSync } from 'node:child_process';
3+
4+
try {
5+
console.log('🔢 Running changeset version...');
6+
execSync('pnpm changeset version', { stdio: 'inherit' });
7+
8+
console.log('📦 Updating lockfile...');
9+
execSync('pnpm install --lockfile-only', { stdio: 'inherit' });
10+
11+
console.log('✅ Versioning completed successfully.');
12+
} catch (err) {
13+
console.error('❌ Error while running version update:', err);
14+
process.exit(1);
15+
}

.github/workflows/release.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
release:
10+
# ✅ Only run in your main repository (prevent auto-release from forks)
11+
if: ${{ github.repository_owner == 'Ohh-889' }}
12+
name: Version & Publish Changed Packages
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: write
16+
pull-requests: write
17+
18+
steps:
19+
# 🧩 Checkout full repository (with history)
20+
- name: Checkout repository
21+
uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 0
24+
25+
# 🧰 Setup Node + pnpm environment
26+
- name: Setup Node.js 20
27+
uses: actions/setup-node@v4
28+
with:
29+
node-version: 20
30+
cache: "pnpm"
31+
32+
- name: Setup pnpm
33+
uses: pnpm/action-setup@v4
34+
with:
35+
version: 9.0.6
36+
37+
# 📦 Install dependencies
38+
- name: Install dependencies
39+
run: pnpm install --frozen-lockfile
40+
41+
# 🔍 Detect which packages will be published
42+
- name: Detect changed packages
43+
id: changed
44+
run: |
45+
CHANGED=$(pnpm changeset status --json | jq -r '.changesets[].releases[].name' | sort | uniq)
46+
echo "changed=$CHANGED" >> $GITHUB_OUTPUT
47+
shell: bash
48+
49+
# 🏗️ Build only changed packages (and their dependencies)
50+
- name: Build changed packages
51+
if: steps.changed.outputs.changed != ''
52+
run: |
53+
for pkg in ${{ steps.changed.outputs.changed }}; do
54+
echo "🏗️ Building $pkg..."
55+
pnpm install --filter "./packages/$pkg..." --frozen-lockfile
56+
pnpm build --filter "./packages/$pkg"
57+
done
58+
shell: bash
59+
60+
# 🏷️ Create version PR or publish to npm
61+
- name: Create Version PR or Publish to npm
62+
id: changesets
63+
uses: changesets/action@v1
64+
with:
65+
commit: "chore(release): version packages"
66+
title: "chore(release): version packages"
67+
version: node .github/changeset-version.js
68+
publish: pnpm changeset publish
69+
env:
70+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
71+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
72+
NODE_ENV: "production"

0 commit comments

Comments
 (0)