-
Notifications
You must be signed in to change notification settings - Fork 11
172 lines (146 loc) · 5.5 KB
/
release.yml
File metadata and controls
172 lines (146 loc) · 5.5 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
name: Release
on:
push:
branches: [master]
concurrency: ${{ github.workflow }}-${{ github.ref }}
jobs:
release:
name: Release
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
id-token: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install pnpm
uses: pnpm/action-setup@v4
- name: Use Node.js 22
uses: actions/setup-node@v4
with:
node-version: 22
registry-url: 'https://registry.npmjs.org'
cache: 'pnpm'
# Ensure npm 11.5.1 or later for trusted publishing
- name: Install npm
run: npm install -g npm@latest
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build
run: pnpm build --filter='!@tiny-design/docs'
- name: Auto-generate changesets for modified packages
run: |
# Find the latest version tag to diff against
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || git rev-list --max-parents=0 HEAD)
echo "Comparing against: $LAST_TAG"
# Skip if there are already changeset files (manually created)
EXISTING=$(find .changeset -name '*.md' ! -name 'README.md' | head -1)
if [ -n "$EXISTING" ]; then
echo "Changeset files already exist, skipping auto-generation"
exit 0
fi
CHANGED_PACKAGES=""
for pkg_json in packages/*/package.json; do
pkg_dir=$(dirname "$pkg_json")
pkg_name=$(node -p "require('./$pkg_json').name")
# Check if any source files changed in this package
if git diff --quiet "$LAST_TAG" -- "$pkg_dir/src" 2>/dev/null; then
echo "No changes in $pkg_name"
else
echo "Changes detected in $pkg_name"
CHANGED_PACKAGES="$CHANGED_PACKAGES $pkg_name"
fi
done
if [ -z "$CHANGED_PACKAGES" ]; then
echo "No packages changed, skipping changeset generation"
exit 0
fi
# Collect commits since last tag for changed packages
REPO_URL="https://github.com/${{ github.repository }}"
FEATURES=""
FIXES=""
REFACTORS=""
OTHER=""
for pkg in $CHANGED_PACKAGES; do
pkg_dir=$(echo "$pkg" | sed 's|@[^/]*/||') # e.g. @tiny-design/react -> react
pkg_path="packages/$pkg_dir"
while IFS= read -r line; do
[ -z "$line" ] && continue
hash=$(echo "$line" | cut -d' ' -f1)
msg=$(echo "$line" | cut -d' ' -f2-)
short_hash=$(echo "$hash" | cut -c1-7)
link="[$short_hash]($REPO_URL/commit/$hash)"
# Strip conventional commit prefix and optional scope for the description
desc=$(echo "$msg" | sed -E 's/^(feat|fix|refactor|chore|docs|style|perf|test|ci|build)(\([^)]*\))?[!]?:\s*//')
entry=$(printf '\n* %s (%s)' "$desc" "$link")
case "$msg" in
feat*) FEATURES="$FEATURES$entry" ;;
fix*) FIXES="$FIXES$entry" ;;
refactor*) REFACTORS="$REFACTORS$entry" ;;
*) OTHER="$OTHER$entry" ;;
esac
done <<< "$(git log "$LAST_TAG"..HEAD --pretty=format:'%H %s' -- "$pkg_path/src" | awk '!seen[$0]++')"
done
# Build the changeset file
RANDOM_ID=$(head -c 8 /dev/urandom | od -An -tx1 | tr -d ' \n')
CHANGESET_FILE=".changeset/auto-${RANDOM_ID}.md"
{
echo "---"
for pkg in $CHANGED_PACKAGES; do
echo "'${pkg}': patch"
done
echo "---"
echo ""
if [ -n "$FEATURES" ]; then
echo "### Features"
echo "$FEATURES"
echo ""
fi
if [ -n "$FIXES" ]; then
echo "### Bug Fixes"
echo "$FIXES"
echo ""
fi
if [ -n "$REFACTORS" ]; then
echo "### Refactors"
echo "$REFACTORS"
echo ""
fi
if [ -n "$OTHER" ]; then
echo "$OTHER"
echo ""
fi
# Fallback if no commits found
if [ -z "$FEATURES" ] && [ -z "$FIXES" ] && [ -z "$REFACTORS" ] && [ -z "$OTHER" ]; then
echo "* Patch updates"
fi
} > "$CHANGESET_FILE"
echo "Generated $CHANGESET_FILE for:$CHANGED_PACKAGES"
cat "$CHANGESET_FILE"
- name: Version packages
run: |
CHANGESETS=$(find .changeset -name '*.md' ! -name 'README.md' | head -1)
if [ -z "$CHANGESETS" ]; then
echo "No changesets found, skipping"
echo "HAS_CHANGES=false" >> "$GITHUB_ENV"
exit 0
fi
pnpm changeset version
echo "HAS_CHANGES=true" >> "$GITHUB_ENV"
- name: Commit version bump
if: env.HAS_CHANGES == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add -A
git commit -m "chore: version packages [skip ci]"
git push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Publish to npm
if: env.HAS_CHANGES == 'true'
run: pnpm release
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}