-
Notifications
You must be signed in to change notification settings - Fork 37
138 lines (117 loc) · 4.71 KB
/
changesets.yml
File metadata and controls
138 lines (117 loc) · 4.71 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
name: Changesets Release
on:
push:
branches:
- main
concurrency: ${{ github.workflow }}-${{ github.ref }}
jobs:
release:
name: Create Release PR
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout Repository
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: "20"
cache: "npm"
cache-dependency-path: |
package-lock.json
src/frontend/package-lock.json
- name: Check for changesets
id: check_changesets
run: |
if ls .changeset/*.md 1> /dev/null 2>&1; then
# Exclude README.md from the count
count=$(ls .changeset/*.md 2>/dev/null | grep -v "README.md" | wc -l)
if [ "$count" -gt 0 ]; then
echo "has_changesets=true" >> $GITHUB_OUTPUT
echo "Found $count changeset(s)"
else
echo "has_changesets=false" >> $GITHUB_OUTPUT
echo "No changesets found (only README.md exists)"
fi
else
echo "has_changesets=false" >> $GITHUB_OUTPUT
echo "No changesets found"
fi
- name: Install Dependencies
if: steps.check_changesets.outputs.has_changesets == 'true'
run: |
# Install root dependencies (includes @changesets/cli)
npm install
# Install workspace dependencies
npm install --workspace=src/frontend
- name: Create Version PR
if: steps.check_changesets.outputs.has_changesets == 'true'
id: changesets
run: |
# Run changeset version from root (where .changeset folder is)
# It will update src/frontend/package.json based on workspace config
npx changeset version
# Sync root package.json version with frontend
NEW_VERSION=$(node -p "require('./src/frontend/package.json').version")
npm version "$NEW_VERSION" --no-git-tag-version
echo "Synced root package.json to $NEW_VERSION"
# Sync pyproject.toml version
if [ -f "pyproject.toml" ]; then
sed -i "s/^version = \"[0-9.]*\"/version = \"${NEW_VERSION}\"/" pyproject.toml
echo "Synced pyproject.toml to $NEW_VERSION"
fi
# Sync .vscode/launch.json dev version
if [ -f ".vscode/launch.json" ]; then
sed -i "s/main.version=[0-9.]*-dev/main.version=${NEW_VERSION}-dev/" .vscode/launch.json
echo "Synced .vscode/launch.json to ${NEW_VERSION}-dev"
fi
# Check if there are changes
if [[ -n $(git status --porcelain) ]]; then
echo "has_changes=true" >> $GITHUB_OUTPUT
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "Changes detected:"
git status --short
else
echo "has_changes=false" >> $GITHUB_OUTPUT
echo "No changes were made by changesets"
fi
- name: Create Pull Request
if: steps.changesets.outputs.has_changes == 'true'
env:
GH_TOKEN: ${{ secrets.PAT_TOKEN }}
run: |
# Configure git
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Create and checkout new branch
BRANCH_NAME="changeset-release/main"
git checkout -b "$BRANCH_NAME"
# Commit changes
git add .
git commit -m "chore: version packages"
# Push branch
git push -f origin "$BRANCH_NAME"
# Create PR body
PR_BODY="This PR was automatically generated by the Changesets workflow.
Merging this PR will:
- Update package versions in \`src/frontend/package.json\`, root \`package.json\`, and \`pyproject.toml\`
- Update \`CHANGELOG.md\` with the changes
- Update \`.vscode/launch.json\` dev version
Once merged, a release tag (\`v${{ steps.changesets.outputs.version }}\`) will be created automatically, triggering the DMG and Linux release builds."
# Create PR using GitHub CLI
gh pr create \
--title "chore: version packages" \
--body "$PR_BODY" \
--base main \
--head "$BRANCH_NAME" \
--label release \
|| echo "PR may already exist"
- name: No changesets found
if: steps.check_changesets.outputs.has_changesets != 'true'
run: |
echo "No changesets found - skipping version PR creation"
echo "This is normal if no changes requiring a release were made."