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