-
Notifications
You must be signed in to change notification settings - Fork 7
208 lines (170 loc) · 8.54 KB
/
Copy pathauto-changeset.yml
File metadata and controls
208 lines (170 loc) · 8.54 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
name: Auto Generate Changeset
on:
pull_request:
types: [labeled]
permissions:
contents: write
pull-requests: write
jobs:
auto-changeset:
runs-on: ubuntu-latest
if: |
github.event.pull_request.head.repo.full_name == github.repository &&
(contains(github.event.pull_request.labels.*.name, 'patch') ||
contains(github.event.pull_request.labels.*.name, 'minor') ||
contains(github.event.pull_request.labels.*.name, 'major') ||
contains(github.event.pull_request.labels.*.name, 'patch:sdk') ||
contains(github.event.pull_request.labels.*.name, 'patch:wallets') ||
contains(github.event.pull_request.labels.*.name, 'patch:render-helper') ||
contains(github.event.pull_request.labels.*.name, 'patch:ui') ||
contains(github.event.pull_request.labels.*.name, 'minor:sdk') ||
contains(github.event.pull_request.labels.*.name, 'minor:wallets') ||
contains(github.event.pull_request.labels.*.name, 'minor:render-helper') ||
contains(github.event.pull_request.labels.*.name, 'minor:ui') ||
contains(github.event.pull_request.labels.*.name, 'major:sdk') ||
contains(github.event.pull_request.labels.*.name, 'major:wallets') ||
contains(github.event.pull_request.labels.*.name, 'major:render-helper') ||
contains(github.event.pull_request.labels.*.name, 'major:ui'))
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 0
persist-credentials: true
- uses: pnpm/action-setup@v3
with:
version: 11.5.0
run_install: false
- uses: actions/setup-node@v4
with:
node-version: 24
cache: pnpm
cache-dependency-path: pnpm-lock.yaml
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Generate changeset
env:
PR_TITLE: ${{ github.event.pull_request.title }}
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_LABELS: ${{ toJson(github.event.pull_request.labels.*.name) }}
run: |
set -e
LABELS=$(echo "$PR_LABELS" | jq -r '.[]')
# Use associative array to track per-package bump types
declare -A PACKAGE_BUMPS
DEFAULT_BUMP="patch"
# Helper function to set bump type with conflict detection
# Uses precedence: major > minor > patch
set_bump() {
local package=$1
local new_bump=$2
local current_bump="${PACKAGE_BUMPS[$package]}"
if [ -n "$current_bump" ] && [ "$current_bump" != "$new_bump" ]; then
echo "⚠️ Conflicting labels for $package: $current_bump and $new_bump"
# Use precedence: major > minor > patch
if [ "$new_bump" = "major" ] || [ "$current_bump" = "patch" -a "$new_bump" = "minor" ]; then
echo " → Using higher severity: $new_bump"
PACKAGE_BUMPS[$package]=$new_bump
else
echo " → Keeping higher severity: $current_bump"
fi
else
PACKAGE_BUMPS[$package]=$new_bump
fi
}
# Check package-specific labels
if echo "$LABELS" | grep -q "patch:sdk"; then set_bump "@ecency/sdk" "patch"; fi
if echo "$LABELS" | grep -q "minor:sdk"; then set_bump "@ecency/sdk" "minor"; fi
if echo "$LABELS" | grep -q "major:sdk"; then set_bump "@ecency/sdk" "major"; fi
if echo "$LABELS" | grep -q "patch:wallets"; then set_bump "@ecency/wallets" "patch"; fi
if echo "$LABELS" | grep -q "minor:wallets"; then set_bump "@ecency/wallets" "minor"; fi
if echo "$LABELS" | grep -q "major:wallets"; then set_bump "@ecency/wallets" "major"; fi
if echo "$LABELS" | grep -q "patch:render-helper"; then set_bump "@ecency/render-helper" "patch"; fi
if echo "$LABELS" | grep -q "minor:render-helper"; then set_bump "@ecency/render-helper" "minor"; fi
if echo "$LABELS" | grep -q "major:render-helper"; then set_bump "@ecency/render-helper" "major"; fi
if echo "$LABELS" | grep -q "patch:ui"; then set_bump "@ecency/ui" "patch"; fi
if echo "$LABELS" | grep -q "minor:ui"; then set_bump "@ecency/ui" "minor"; fi
if echo "$LABELS" | grep -q "major:ui"; then set_bump "@ecency/ui" "major"; fi
# If no package-specific labels, check generic labels and detect changed packages
if [ ${#PACKAGE_BUMPS[@]} -eq 0 ]; then
if echo "$LABELS" | grep -q "major"; then
DEFAULT_BUMP="major"
elif echo "$LABELS" | grep -q "minor"; then
DEFAULT_BUMP="minor"
fi
git fetch origin ${{ github.event.pull_request.base.ref }}
CHANGED_FILES=$(git diff --name-only origin/${{ github.event.pull_request.base.ref }}...HEAD)
if echo "$CHANGED_FILES" | grep -q "^packages/sdk/"; then set_bump "@ecency/sdk" "$DEFAULT_BUMP"; fi
if echo "$CHANGED_FILES" | grep -q "^packages/wallets/"; then set_bump "@ecency/wallets" "$DEFAULT_BUMP"; fi
if echo "$CHANGED_FILES" | grep -q "^packages/render-helper/"; then set_bump "@ecency/render-helper" "$DEFAULT_BUMP"; fi
if echo "$CHANGED_FILES" | grep -q "^packages/ui/"; then set_bump "@ecency/ui" "$DEFAULT_BUMP"; fi
fi
if [ ${#PACKAGE_BUMPS[@]} -eq 0 ]; then
echo "No publishable packages changed, skipping changeset generation"
exit 0
fi
CHANGESET_FILE=".changeset/pr-${PR_NUMBER}.md"
rm -f "$CHANGESET_FILE"
echo "---" > "$CHANGESET_FILE"
for pkg in "${!PACKAGE_BUMPS[@]}"; do
echo "\"$pkg\": ${PACKAGE_BUMPS[$pkg]}" >> "$CHANGESET_FILE"
done
echo "---" >> "$CHANGESET_FILE"
echo "" >> "$CHANGESET_FILE"
if [[ "$PR_TITLE" == *"(#${PR_NUMBER})"* ]]; then
echo "$PR_TITLE" >> "$CHANGESET_FILE"
else
echo "$PR_TITLE (#${PR_NUMBER})" >> "$CHANGESET_FILE"
fi
cat "$CHANGESET_FILE"
- name: Apply version bumps
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: pnpm changeset version
- name: Rebuild affected packages
run: |
set -e
CHANGED_PACKAGES=""
# Detect which packages were version-bumped by checking git diff on package.json versions
if git diff --name-only | grep -q "^packages/sdk/"; then CHANGED_PACKAGES="$CHANGED_PACKAGES sdk"; fi
if git diff --name-only | grep -q "^packages/wallets/"; then CHANGED_PACKAGES="$CHANGED_PACKAGES wallets"; fi
if git diff --name-only | grep -q "^packages/render-helper/"; then CHANGED_PACKAGES="$CHANGED_PACKAGES render-helper"; fi
if git diff --name-only | grep -q "^packages/ui/"; then CHANGED_PACKAGES="$CHANGED_PACKAGES ui"; fi
if [ -z "$CHANGED_PACKAGES" ]; then
echo "No packages to rebuild"
exit 0
fi
echo "Rebuilding packages:$CHANGED_PACKAGES"
# Build SDK first since wallets depends on it
if echo "$CHANGED_PACKAGES" | grep -q "sdk"; then
echo "Building @ecency/sdk..."
pnpm --filter @ecency/sdk build
fi
# Build wallets and render-helper (can be parallel but sequential is safer in CI)
if echo "$CHANGED_PACKAGES" | grep -q "wallets"; then
echo "Building @ecency/wallets..."
pnpm --filter @ecency/wallets build
fi
if echo "$CHANGED_PACKAGES" | grep -q "render-helper"; then
echo "Building @ecency/render-helper..."
pnpm --filter @ecency/render-helper build
fi
if echo "$CHANGED_PACKAGES" | grep -q "ui"; then
echo "Building @ecency/ui..."
pnpm --filter @ecency/ui build
fi
- name: Commit & push changes (same PR)
if: github.event.pull_request.head.repo.full_name == github.repository
env:
BRANCH_REF: ${{ github.event.pull_request.head.ref }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add -A
if git diff --staged --quiet; then
echo "No changes to commit"
exit 0
fi
git commit -m "chore: apply changeset versioning for PR #${PR_NUMBER}"
git push origin "HEAD:${BRANCH_REF}"