Skip to content

Commit 31a5f2b

Browse files
committed
feat: improve release
1 parent 0f66a80 commit 31a5f2b

4 files changed

Lines changed: 259 additions & 43 deletions

File tree

.changeset/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"commit": false,
55
"fixed": [],
66
"linked": [],
7-
"access": "restricted",
7+
"access": "public",
88
"baseBranch": "main",
99
"updateInternalDependencies": "patch",
1010
"ignore": [

.github/workflows/release.yaml

Lines changed: 135 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,20 @@ on:
44
workflow_dispatch:
55
inputs:
66
release_type:
7-
description: "Type of release (prerelease, prepatch, patch, minor, preminor, major)"
7+
description: "Type of release (auto, prerelease, patch, minor, major)"
88
required: true
9-
default: "patch"
9+
default: "auto"
10+
type: choice
11+
options:
12+
- auto
13+
- prerelease
14+
- patch
15+
- minor
16+
- major
17+
prerelease_tag:
18+
description: "Prerelease tag (e.g., rc, beta, alpha) - only used for prerelease"
19+
required: false
20+
default: "rc"
1021
dry_run:
1122
description: "Dry run (no actual publishing or commits)"
1223
required: false
@@ -21,6 +32,7 @@ jobs:
2132
with:
2233
submodules: true
2334
token: ${{ secrets.GITHUB_TOKEN }}
35+
fetch-depth: 0
2436

2537
- uses: pnpm/action-setup@v3
2638
with:
@@ -89,9 +101,38 @@ jobs:
89101
git config user.name "${{ github.actor }}"
90102
git config user.email "${{ github.actor }}@users.noreply.github.com"
91103
92-
- name: "Setup npm for npmjs"
104+
- name: Determine release strategy
105+
id: release-strategy
106+
run: |
107+
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
108+
echo "Current branch: $CURRENT_BRANCH"
109+
110+
# Determine if we should use prerelease mode
111+
if [[ "$CURRENT_BRANCH" != "main" && "${{ github.event.inputs.release_type }}" == "auto" ]]; then
112+
echo "Non-main branch detected, will use prerelease mode"
113+
echo "use_prerelease=true" >> $GITHUB_OUTPUT
114+
115+
# Extract version from branch name if it's a release branch
116+
if [[ "$CURRENT_BRANCH" =~ ^release/([0-9]+\.[0-9]+) ]]; then
117+
echo "prerelease_tag=${BASH_REMATCH[1]}-rc" >> $GITHUB_OUTPUT
118+
else
119+
# Use branch name as prerelease tag (sanitized)
120+
SANITIZED_BRANCH=$(echo "$CURRENT_BRANCH" | sed 's/[^a-zA-Z0-9-]/-/g')
121+
echo "prerelease_tag=$SANITIZED_BRANCH" >> $GITHUB_OUTPUT
122+
fi
123+
elif [[ "${{ github.event.inputs.release_type }}" == "prerelease" ]]; then
124+
echo "Manual prerelease requested"
125+
echo "use_prerelease=true" >> $GITHUB_OUTPUT
126+
echo "prerelease_tag=${{ github.event.inputs.prerelease_tag }}" >> $GITHUB_OUTPUT
127+
else
128+
echo "Standard release mode"
129+
echo "use_prerelease=false" >> $GITHUB_OUTPUT
130+
fi
131+
132+
- name: "Setup npm authentication"
93133
run: |
94134
npm config set registry https://registry.npmjs.org/
135+
npm config set //registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}
95136
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
96137
97138
- name: Install Protobuf Compiler
@@ -100,87 +141,141 @@ jobs:
100141
- name: Install dependencies
101142
run: pnpm install
102143

103-
- name: Check for packages to be bumped
104-
id: check-status
144+
- name: Enter prerelease mode if needed
145+
if: steps.release-strategy.outputs.use_prerelease == 'true'
146+
run: |
147+
PRERELEASE_TAG="${{ steps.release-strategy.outputs.prerelease_tag }}"
148+
echo "Entering prerelease mode with tag: $PRERELEASE_TAG"
149+
150+
if [ "${{ github.event.inputs.dry_run }}" != "true" ]; then
151+
pnpm changeset pre enter "$PRERELEASE_TAG"
152+
else
153+
echo "DRY RUN: Would enter prerelease mode with tag $PRERELEASE_TAG"
154+
fi
155+
156+
- name: Check for changesets
157+
id: check-changesets
105158
run: |
106-
# Run changeset status and capture output
107-
STATUS=$(pnpm changeset status)
108-
echo "Changeset status:"
109-
echo "$STATUS"
110-
111-
# Check if we have packages to bump
112-
if echo "$STATUS" | grep -q "NO packages to be bumped at patch" && \
113-
echo "$STATUS" | grep -q "NO packages to be bumped at minor" && \
114-
echo "$STATUS" | grep -q "NO packages to be bumped at major"; then
115-
echo "No packages need to be bumped at any level. Exiting workflow."
116-
echo "has_changes=false" >> $GITHUB_OUTPUT
159+
# Check if there are any changesets
160+
if [ -z "$(ls -A .changeset/*.md 2>/dev/null | grep -v README.md)" ]; then
161+
echo "No changesets found. Nothing to release."
162+
echo "has_changesets=false" >> $GITHUB_OUTPUT
117163
exit 0
118164
else
119-
echo "Found packages that need to be bumped. Continuing workflow."
120-
echo "has_changes=true" >> $GITHUB_OUTPUT
165+
echo "Found changesets to process."
166+
echo "has_changesets=true" >> $GITHUB_OUTPUT
121167
fi
122168
123169
- name: Version packages
170+
if: steps.check-changesets.outputs.has_changesets == 'true'
124171
id: changesets-version
125172
run: |
126-
# Apply version bump based on release type
127-
pnpm changeset version
128-
129-
# If this is a dry run, revert the version changes
130-
if [ "${{ github.event.inputs.dry_run }}" == "true" ]; then
131-
echo "DRY RUN: Would version packages to ${NEW_VERSION}"
132-
git checkout -- .
173+
echo "Running changeset version..."
174+
175+
if [ "${{ github.event.inputs.dry_run }}" != "true" ]; then
176+
pnpm changeset version
177+
178+
# If we're in prerelease mode and on a non-main branch, we might need to force version bumps
179+
if [ "${{ steps.release-strategy.outputs.use_prerelease }}" == "true" ]; then
180+
echo "Prerelease versioning completed"
181+
fi
182+
else
183+
echo "DRY RUN: Would run changeset version"
184+
# Show what would be versioned
185+
pnpm changeset status --verbose
133186
fi
134187
135188
- name: Commit changes
136-
if: ${{ github.event.inputs.dry_run != 'true' }}
189+
if: ${{ github.event.inputs.dry_run != 'true' && steps.check-changesets.outputs.has_changesets == 'true' }}
137190
run: |
138191
if git diff --quiet && git diff --staged --quiet; then
139192
echo "No changes to commit"
140193
else
141194
git add .
142195
git commit -m "chore: release"
143-
git push origin refs/heads/main:refs/heads/main
196+
197+
# Push to the current branch
198+
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
199+
git push origin "refs/heads/$CURRENT_BRANCH:refs/heads/$CURRENT_BRANCH"
144200
fi
145201
146202
- name: Publish to npm
147-
if: ${{ github.event.inputs.dry_run != 'true' }}
148-
run: pnpm release
203+
if: ${{ github.event.inputs.dry_run != 'true' && steps.check-changesets.outputs.has_changesets == 'true' }}
204+
run: |
205+
echo "Publishing packages..."
206+
# Changesets will only publish packages that are not ignored in config
207+
pnpm changeset publish
149208
env:
150209
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
210+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
151211

152212
- name: Dry run - Show npm publish
153-
if: ${{ github.event.inputs.dry_run == 'true' }}
213+
if: ${{ github.event.inputs.dry_run == 'true' && steps.check-changesets.outputs.has_changesets == 'true' }}
154214
run: |
155215
echo "DRY RUN: Would publish the following packages to npm:"
156-
pnpm release:dry-run
216+
# Show what changesets would publish
217+
pnpm changeset publish --dry-run
218+
env:
219+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
220+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
157221

158-
- name: Create and push tag
159-
if: ${{ github.event.inputs.dry_run != 'true' }}
222+
- name: Create and push tags
223+
if: ${{ github.event.inputs.dry_run != 'true' && steps.check-changesets.outputs.has_changesets == 'true' }}
160224
run: |
225+
echo "Creating tags..."
161226
pnpm changeset tag
162227
git push --tags
163228
229+
- name: Exit prerelease mode if needed
230+
if: steps.release-strategy.outputs.use_prerelease == 'true' && github.event.inputs.dry_run != 'true' && steps.check-changesets.outputs.has_changesets == 'true'
231+
run: |
232+
echo "Exiting prerelease mode"
233+
pnpm changeset pre exit || true
234+
235+
# Commit the pre.json removal if it exists
236+
if [ -f .changeset/pre.json ]; then
237+
git add .changeset/pre.json
238+
git commit -m "chore: exit prerelease mode" || true
239+
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
240+
git push origin "refs/heads/$CURRENT_BRANCH:refs/heads/$CURRENT_BRANCH" || true
241+
fi
242+
164243
- name: Trigger release creation
165-
if: ${{ github.event.inputs.dry_run != 'true' }}
244+
if: ${{ github.event.inputs.dry_run != 'true' && steps.check-changesets.outputs.has_changesets == 'true' }}
166245
run: |
167246
# Get all tags that were just created
168247
TAGS=$(git tag --points-at HEAD | grep '@dojoengine/' || true)
169248
170249
# For each tag, trigger the release workflow
250+
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
171251
for TAG in $TAGS; do
172252
echo "Triggering release for tag: $TAG"
173253
gh workflow run create_release.yaml \
174-
--ref main \
254+
--ref "$CURRENT_BRANCH" \
175255
-f tag="$TAG"
176256
done
177257
env:
178258
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
179259

180-
- name: Dry run - Show git changes
181-
if: ${{ github.event.inputs.dry_run == 'true' }}
260+
- name: Dry run - Summary
261+
if: ${{ github.event.inputs.dry_run == 'true' && steps.check-changesets.outputs.has_changesets == 'true' }}
182262
run: |
183-
TAGS=$(pnpm changeset tag)
184-
echo "DRY RUN: Would commit changes with message: chore: release"
185-
echo "DRY RUN: Would create and push tag: $TAGS"
263+
echo "DRY RUN SUMMARY:"
264+
echo "================"
265+
266+
if [ "${{ steps.release-strategy.outputs.use_prerelease }}" == "true" ]; then
267+
echo "Would enter prerelease mode: ${{ steps.release-strategy.outputs.prerelease_tag }}"
268+
fi
269+
270+
echo "Would version packages according to changesets"
271+
echo "Would commit with message: chore: release"
272+
echo "Would create and push tags"
273+
echo "Would publish packages to npm"
274+
275+
if [ "${{ steps.release-strategy.outputs.use_prerelease }}" == "true" ]; then
276+
echo "Would exit prerelease mode after publishing"
277+
fi
278+
279+
echo ""
280+
echo "Current git status:"
186281
git status

RELEASE_PROCESS.md

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# Release Process with Changesets
2+
3+
This repository uses [Changesets](https://github.com/changesets/changesets) to manage versions and releases across multiple packages, with support for different versioning strategies on different branches.
4+
5+
## Overview
6+
7+
- **Main branch**: Stable releases (1.5.0, 1.6.0, etc.)
8+
- **Release branches** (`release/*`): Patch releases and release candidates
9+
- **Feature branches**: Prerelease versions for testing
10+
11+
## Creating Changesets
12+
13+
When you make changes that should be included in a release:
14+
15+
```bash
16+
pnpm changeset
17+
```
18+
19+
This will prompt you to:
20+
1. Select which packages have changed
21+
2. Choose the version bump type (major, minor, patch)
22+
3. Write a summary for the changelog
23+
24+
## Release Workflow
25+
26+
### Automatic Branch Detection
27+
28+
The release workflow automatically detects your branch and applies the appropriate versioning strategy:
29+
30+
- On `main`: Standard releases
31+
- On `release/*`: Prereleases with RC tags (e.g., 1.6.0-rc.0)
32+
- On other branches: Prereleases with branch name tags
33+
34+
### Manual Release Process
35+
36+
1. **Trigger the Release Workflow**
37+
- Go to Actions → "Publish packages and create tags"
38+
- Click "Run workflow"
39+
- Select options:
40+
- `release_type`: Choose "auto" for automatic detection or specify manually
41+
- `prerelease_tag`: Custom tag for prereleases (default: "rc")
42+
- `dry_run`: Test the release without publishing
43+
44+
2. **What Happens**
45+
- Changesets are consumed and versions are bumped
46+
- For non-main branches: Enters prerelease mode automatically
47+
- Commits version changes
48+
- Publishes to npm
49+
- Creates git tags
50+
- Triggers GitHub releases
51+
52+
### Release Types
53+
54+
- **auto**: Automatically determines strategy based on branch
55+
- **prerelease**: Force prerelease mode with custom tag
56+
- **patch/minor/major**: Force specific version bump
57+
58+
## Branch Strategies
59+
60+
### Main Branch
61+
Standard releases following semver:
62+
```
63+
1.5.0 → 1.6.0 (minor)
64+
1.6.0 → 1.6.1 (patch)
65+
1.6.1 → 2.0.0 (major)
66+
```
67+
68+
### Release Branches
69+
For maintenance and release candidates:
70+
```
71+
release/1.6 → 1.6.0-rc.0 → 1.6.0-rc.1 → 1.6.0
72+
release/1.5 → 1.5.1, 1.5.2 (patches only)
73+
```
74+
75+
### Feature Branches
76+
For testing features before merge:
77+
```
78+
feat/new-api → 1.7.0-feat-new-api.0
79+
fix/bug-123 → 1.6.1-fix-bug-123.0
80+
```
81+
82+
## Local Commands
83+
84+
```bash
85+
# Create a changeset
86+
pnpm changeset
87+
88+
# Version packages locally (consumes changesets)
89+
pnpm version
90+
91+
# Publish to npm (after versioning)
92+
pnpm release
93+
94+
# Dry run to see what would be published
95+
pnpm release:dry-run
96+
```
97+
98+
## Best Practices
99+
100+
1. **Always create changesets** for changes that affect the public API
101+
2. **Use conventional commit messages** for better tracking
102+
3. **Test prereleases** on feature/release branches before merging
103+
4. **Don't commit version changes manually** - let the workflow handle it
104+
5. **Review changeset summaries** - they become your changelog
105+
106+
## Troubleshooting
107+
108+
### No packages to release
109+
- Ensure you have uncommitted changesets in `.changeset/`
110+
- Check that packages aren't ignored in `.changeset/config.json`
111+
112+
### Prerelease versions not working
113+
- Verify you're not on the main branch
114+
- Check if `.changeset/pre.json` exists (indicates prerelease mode)
115+
116+
### Version conflicts
117+
- Don't manually edit package.json versions
118+
- Let changesets handle all version bumps
119+
- If needed, delete `.changeset/pre.json` and start fresh

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
"prettier-check": "pnpx prettier --check packages examples",
1111
"format": "turbo format",
1212
"format:check": "turbo format:check",
13-
"release": "pnpm build:deps && pnpm -F './packages/**' publish -r --force --no-git-checks",
14-
"release:dry-run": "pnpm -F './packages/**' publish -r --force --dry-run",
13+
"changeset": "changeset",
14+
"version": "changeset version",
15+
"release": "pnpm build:deps && changeset publish",
16+
"release:dry-run": "pnpm build:deps && changeset publish --dry-run",
1517
"dev": "turbo watch dev --concurrency 20",
1618
"dev:deps": "turbo watch build:deps --concurrency 20",
1719
"docs": "turbo run docs --ui stream && typedoc --entryPointStrategy merge 'docs-json/*.json'",

0 commit comments

Comments
 (0)