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
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
0 commit comments