Skip to content

Commit 802cfd1

Browse files
committed
ci: auto-generate changesets for modified packages in release workflow
Detects which packages have source changes since the last git tag and generates changeset files automatically, removing the need to run `pnpm changeset` manually before each release.
1 parent 0129863 commit 802cfd1

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ jobs:
1717

1818
steps:
1919
- uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 0
2022

2123
- name: Install pnpm
2224
uses: pnpm/action-setup@v4
@@ -34,6 +36,56 @@ jobs:
3436
- name: Build
3537
run: pnpm build
3638

39+
- name: Auto-generate changesets for modified packages
40+
run: |
41+
# Find the latest version tag to diff against
42+
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || git rev-list --max-parents=0 HEAD)
43+
echo "Comparing against: $LAST_TAG"
44+
45+
# Skip if there are already changeset files (manually created)
46+
EXISTING=$(find .changeset -name '*.md' ! -name 'README.md' | head -1)
47+
if [ -n "$EXISTING" ]; then
48+
echo "Changeset files already exist, skipping auto-generation"
49+
exit 0
50+
fi
51+
52+
CHANGED_PACKAGES=""
53+
54+
for pkg_json in packages/*/package.json; do
55+
pkg_dir=$(dirname "$pkg_json")
56+
pkg_name=$(node -p "require('./$pkg_json').name")
57+
58+
# Check if any source files changed in this package
59+
if git diff --quiet "$LAST_TAG" -- "$pkg_dir/src" 2>/dev/null; then
60+
echo "No changes in $pkg_name"
61+
else
62+
echo "Changes detected in $pkg_name"
63+
CHANGED_PACKAGES="$CHANGED_PACKAGES $pkg_name"
64+
fi
65+
done
66+
67+
if [ -z "$CHANGED_PACKAGES" ]; then
68+
echo "No packages changed, skipping changeset generation"
69+
exit 0
70+
fi
71+
72+
# Build the changeset file
73+
RANDOM_ID=$(head -c 8 /dev/urandom | od -An -tx1 | tr -d ' \n')
74+
CHANGESET_FILE=".changeset/auto-${RANDOM_ID}.md"
75+
76+
{
77+
echo "---"
78+
for pkg in $CHANGED_PACKAGES; do
79+
echo "'${pkg}': patch"
80+
done
81+
echo "---"
82+
echo ""
83+
echo "Auto-detected changes since $LAST_TAG"
84+
} > "$CHANGESET_FILE"
85+
86+
echo "Generated $CHANGESET_FILE for:$CHANGED_PACKAGES"
87+
cat "$CHANGESET_FILE"
88+
3789
- name: Creating .npmrc
3890
run: |
3991
cat << EOF > "$HOME/.npmrc"

0 commit comments

Comments
 (0)