Skip to content

Commit 8611052

Browse files
👷 Added CI and CD for build, test and publishing
1 parent 0c2473d commit 8611052

File tree

2 files changed

+225
-0
lines changed

2 files changed

+225
-0
lines changed

.github/workflows/ci.yml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
name: Test
12+
runs-on: ubuntu-latest
13+
14+
strategy:
15+
matrix:
16+
node-version: [18, 20, 22]
17+
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v4
21+
22+
- name: Setup Bun
23+
uses: oven-sh/setup-bun@v2
24+
with:
25+
bun-version: latest
26+
27+
- name: Install dependencies
28+
run: bun install --frozen-lockfile
29+
30+
- name: Run tests
31+
run: bun test
32+
33+
- name: Type check
34+
run: bun run tsc --noEmit
35+
36+
- name: Build package
37+
run: bun run build
38+
39+
- name: Check build artifacts
40+
run: |
41+
if [ ! -d "dist" ]; then
42+
echo "Build failed: dist directory not found"
43+
exit 1
44+
fi
45+
if [ ! -f "dist/index.js" ]; then
46+
echo "Build failed: dist/index.js not found"
47+
exit 1
48+
fi
49+
if [ ! -f "dist/index.d.ts" ]; then
50+
echo "Build failed: dist/index.d.ts not found"
51+
exit 1
52+
fi
53+
echo "Build artifacts verified successfully"
54+
55+
# Test with Node.js as well to ensure compatibility
56+
test-node:
57+
name: Test with Node.js
58+
runs-on: ubuntu-latest
59+
60+
strategy:
61+
matrix:
62+
node-version: [18, 20, 22]
63+
64+
steps:
65+
- name: Checkout code
66+
uses: actions/checkout@v4
67+
68+
- name: Setup Node.js
69+
uses: actions/setup-node@v4
70+
with:
71+
node-version: ${{ matrix.node-version }}
72+
cache: "npm"
73+
74+
- name: Install dependencies
75+
run: npm ci
76+
77+
- name: Run tests
78+
run: npm test
79+
80+
- name: Type check
81+
run: npx tsc --noEmit
82+
83+
- name: Build package
84+
run: npm run build

.github/workflows/release.yml

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
name: Release and Publish
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*" # Triggers on version tags like v1.0.0, v1.2.3, etc.
7+
8+
jobs:
9+
release:
10+
name: Release and Publish
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: write # Needed to create releases
14+
id-token: write # Needed for npm provenance
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0 # Fetch full history for changelog generation
21+
22+
- name: Setup Bun
23+
uses: oven-sh/setup-bun@v2
24+
with:
25+
bun-version: latest
26+
27+
- name: Install dependencies
28+
run: bun install --frozen-lockfile
29+
30+
- name: Run tests
31+
run: bun test
32+
33+
- name: Type check
34+
run: bun run tsc --noEmit
35+
36+
- name: Build package
37+
run: bun run build
38+
39+
- name: Verify build artifacts
40+
run: |
41+
if [ ! -d "dist" ]; then
42+
echo "Build failed: dist directory not found"
43+
exit 1
44+
fi
45+
if [ ! -f "dist/index.js" ]; then
46+
echo "Build failed: dist/index.js not found"
47+
exit 1
48+
fi
49+
if [ ! -f "dist/index.d.ts" ]; then
50+
echo "Build failed: dist/index.d.ts not found"
51+
exit 1
52+
fi
53+
echo "Build artifacts verified successfully"
54+
55+
- name: Extract version from tag
56+
id: get_version
57+
run: |
58+
VERSION=${GITHUB_REF#refs/tags/v}
59+
echo "version=$VERSION" >> $GITHUB_OUTPUT
60+
echo "tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
61+
62+
- name: Update package.json version
63+
run: |
64+
bun run --bun -- -e "
65+
const pkg = require('./package.json');
66+
pkg.version = '${{ steps.get_version.outputs.version }}';
67+
require('fs').writeFileSync('./package.json', JSON.stringify(pkg, null, 2) + '\n');
68+
"
69+
70+
- name: Setup Node.js for npm publishing
71+
uses: actions/setup-node@v4
72+
with:
73+
node-version: "20"
74+
registry-url: "https://registry.npmjs.org"
75+
76+
- name: Publish to npm
77+
run: npm publish --provenance --access public
78+
env:
79+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
80+
81+
- name: Generate changelog
82+
id: changelog
83+
run: |
84+
# Simple changelog generation - you can enhance this
85+
echo "## What's Changed" > CHANGELOG.md
86+
echo "" >> CHANGELOG.md
87+
88+
# Get commits since last tag
89+
LAST_TAG=$(git tag --sort=-version:refname | sed -n '2p')
90+
if [ -z "$LAST_TAG" ]; then
91+
# If no previous tag, get all commits
92+
git log --pretty=format:"- %s (%h)" --no-merges >> CHANGELOG.md
93+
else
94+
# Get commits since last tag
95+
git log "${LAST_TAG}..${{ steps.get_version.outputs.tag }}" --pretty=format:"- %s (%h)" --no-merges >> CHANGELOG.md
96+
fi
97+
98+
echo "" >> CHANGELOG.md
99+
echo "**Full Changelog**: https://github.com/max-programming/id-ts/compare/${LAST_TAG:-$(git rev-list --max-parents=0 HEAD)}...${{ steps.get_version.outputs.tag }}" >> CHANGELOG.md
100+
101+
# Set changelog content for release
102+
{
103+
echo 'changelog<<EOF'
104+
cat CHANGELOG.md
105+
echo EOF
106+
} >> $GITHUB_OUTPUT
107+
108+
- name: Create GitHub Release
109+
uses: softprops/action-gh-release@v2
110+
with:
111+
tag_name: ${{ steps.get_version.outputs.tag }}
112+
name: Release ${{ steps.get_version.outputs.tag }}
113+
body: ${{ steps.changelog.outputs.changelog }}
114+
draft: false
115+
prerelease: false
116+
files: |
117+
dist/index.js
118+
dist/index.d.ts
119+
dist/index.cjs
120+
env:
121+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
122+
123+
# Notify on successful release
124+
notify:
125+
name: Notify Success
126+
runs-on: ubuntu-latest
127+
needs: release
128+
if: success()
129+
130+
steps:
131+
- name: Extract version from tag
132+
id: get_version
133+
run: |
134+
VERSION=${GITHUB_REF#refs/tags/v}
135+
echo "version=$VERSION" >> $GITHUB_OUTPUT
136+
137+
- name: Notify
138+
run: |
139+
echo "🎉 Successfully released id-ts v${{ steps.get_version.outputs.version }}"
140+
echo "📦 Published to npm: https://www.npmjs.com/package/id-ts"
141+
echo "🏷️ GitHub Release: https://github.com/max-programming/id-ts/releases/tag/v${{ steps.get_version.outputs.version }}"

0 commit comments

Comments
 (0)