Skip to content

Commit dd4ea82

Browse files
committed
rollback version too
1 parent e4a275f commit dd4ea82

File tree

1 file changed

+67
-24
lines changed

1 file changed

+67
-24
lines changed

.github/workflows/release.yml

Lines changed: 67 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ jobs:
4242
with:
4343
enable-cache: true
4444

45-
- name: 📝 Calculate and update version in pyproject.toml
45+
- name: 📝 Calculate new version
46+
id: version
4647
run: |
4748
BUMP_TYPE="${{ github.event.inputs.bump_type }}"
4849
echo "Bump type: $BUMP_TYPE"
@@ -75,17 +76,22 @@ jobs:
7576
esac
7677
7778
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
78-
echo "New version: $NEW_VERSION"
79+
echo "New version will be: $NEW_VERSION"
7980
80-
# Update version in pyproject.toml
81+
# Store versions for later use
82+
echo "CURRENT_VERSION=$CURRENT_VERSION" >> $GITHUB_ENV
83+
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
84+
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
85+
echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
86+
87+
- name: 📝 Update version in pyproject.toml (local only)
88+
run: |
89+
# Update version in pyproject.toml locally (don't commit yet)
8190
sed -i "s/version = \".*\"/version = \"$NEW_VERSION\"/" pyproject.toml
8291
8392
# Verify the version was updated
8493
grep "version = \"$NEW_VERSION\"" pyproject.toml || exit 1
85-
echo "✅ Version updated from $CURRENT_VERSION to $NEW_VERSION"
86-
87-
# Set as environment variable for subsequent steps
88-
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
94+
echo "✅ Version updated locally from $CURRENT_VERSION to $NEW_VERSION"
8995
9096
- name: 🧹 Clean previous builds
9197
run: |
@@ -127,28 +133,15 @@ jobs:
127133
exit 1
128134
fi
129135
130-
- name: 🏷️ Create and push git tag
131-
run: |
132-
git config user.name "github-actions[bot]"
133-
git config user.email "github-actions[bot]@users.noreply.github.com"
134-
135-
# Commit version change
136-
git add pyproject.toml
137-
git commit -m "🔖 Bump version to $NEW_VERSION"
138-
139-
# Create and push tag
140-
git tag "v$NEW_VERSION"
141-
git push origin main
142-
git push origin "v$NEW_VERSION"
143-
echo "✅ Git tag v$NEW_VERSION created and pushed"
144-
145136
- name: 📦 Publish to PyPI
137+
id: pypi_publish
146138
uses: pypa/gh-action-pypi-publish@release/v1
147139
with:
148140
print-hash: true
149141
verbose: true
150142

151143
- name: ✅ Verify PyPI publication
144+
id: verify_pypi
152145
run: |
153146
echo "⏳ Waiting for PyPI to update..."
154147
sleep 30
@@ -157,6 +150,7 @@ jobs:
157150
for i in {1..10}; do
158151
if pip index versions fluid-top | grep -q "$NEW_VERSION"; then
159152
echo "✅ Package version $NEW_VERSION found on PyPI"
153+
echo "pypi_verified=true" >> $GITHUB_OUTPUT
160154
break
161155
else
162156
echo "⏳ Attempt $i: Package not yet available, waiting..."
@@ -165,11 +159,13 @@ jobs:
165159
166160
if [ $i -eq 10 ]; then
167161
echo "❌ Package not found on PyPI after 5 minutes"
162+
echo "pypi_verified=false" >> $GITHUB_OUTPUT
168163
exit 1
169164
fi
170165
done
171166
172167
- name: 🧪 Test PyPI installation
168+
if: steps.verify_pypi.outputs.pypi_verified == 'true'
173169
run: |
174170
echo "🧪 Testing installation from PyPI..."
175171
@@ -189,7 +185,26 @@ jobs:
189185
rm -rf test_env
190186
echo "✅ PyPI installation test passed"
191187
188+
- name: 🏷️ Create and push git tag
189+
if: steps.verify_pypi.outputs.pypi_verified == 'true'
190+
id: git_tag
191+
run: |
192+
git config user.name "github-actions[bot]"
193+
git config user.email "github-actions[bot]@users.noreply.github.com"
194+
195+
# Commit version change
196+
git add pyproject.toml
197+
git commit -m "🔖 Bump version to $NEW_VERSION"
198+
199+
# Create and push tag
200+
git tag "v$NEW_VERSION"
201+
git push origin main
202+
git push origin "v$NEW_VERSION"
203+
echo "✅ Git tag v$NEW_VERSION created and pushed"
204+
echo "git_tagged=true" >> $GITHUB_OUTPUT
205+
192206
- name: 📋 Generate release notes
207+
if: steps.git_tag.outputs.git_tagged == 'true'
193208
run: |
194209
cat > release_notes.md << EOF
195210
# FluidTop v$NEW_VERSION
@@ -230,7 +245,7 @@ jobs:
230245
EOF
231246
232247
- name: 🎉 Create GitHub Release
233-
if: ${{ github.event.inputs.create_github_release == 'true' }}
248+
if: ${{ github.event.inputs.create_github_release == 'true' && steps.git_tag.outputs.git_tagged == 'true' }}
234249
uses: softprops/action-gh-release@v1
235250
with:
236251
tag_name: v${{ env.NEW_VERSION }}
@@ -246,6 +261,7 @@ jobs:
246261
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
247262

248263
- name: 🎊 Release Summary
264+
if: steps.git_tag.outputs.git_tagged == 'true'
249265
run: |
250266
echo "## 🎉 Release v$NEW_VERSION Complete! " >> $GITHUB_STEP_SUMMARY
251267
echo "" >> $GITHUB_STEP_SUMMARY
@@ -254,13 +270,40 @@ jobs:
254270
echo "- [x] Updated version in pyproject.toml" >> $GITHUB_STEP_SUMMARY
255271
echo "- [x] Built distribution packages" >> $GITHUB_STEP_SUMMARY
256272
echo "- [x] Tested package build" >> $GITHUB_STEP_SUMMARY
257-
echo "- [x] Created and pushed git tag v$NEW_VERSION" >> $GITHUB_STEP_SUMMARY
258273
echo "- [x] Published to PyPI" >> $GITHUB_STEP_SUMMARY
259274
echo "- [x] Verified PyPI publication" >> $GITHUB_STEP_SUMMARY
260275
echo "- [x] Tested PyPI installation" >> $GITHUB_STEP_SUMMARY
276+
echo "- [x] Created and pushed git tag v$NEW_VERSION" >> $GITHUB_STEP_SUMMARY
261277
echo "- [x] Created GitHub release" >> $GITHUB_STEP_SUMMARY
262278
echo "" >> $GITHUB_STEP_SUMMARY
263279
echo "### 🔗 Links" >> $GITHUB_STEP_SUMMARY
264280
echo "- **PyPI Package:** https://pypi.org/project/fluid-top/$NEW_VERSION/" >> $GITHUB_STEP_SUMMARY
265281
echo "- **GitHub Release:** https://github.com/FluidInference/fluidtop/releases/tag/v$NEW_VERSION" >> $GITHUB_STEP_SUMMARY
266282
echo "- **Install Command:** \`pip install fluid-top==$NEW_VERSION\`" >> $GITHUB_STEP_SUMMARY
283+
284+
# Rollback section - only runs if PyPI publish succeeded but later steps failed
285+
- name: 🔄 Rollback: Revert git changes
286+
if: failure() && steps.pypi_publish.outcome == 'success'
287+
run: |
288+
echo "⚠️ Rolling back git changes due to failure after successful PyPI publish"
289+
290+
# Reset pyproject.toml to original version
291+
git checkout HEAD -- pyproject.toml
292+
echo "✅ Reverted pyproject.toml to original version"
293+
294+
echo "❌ Release failed after PyPI publication. Manual cleanup may be required."
295+
echo "Published version $NEW_VERSION is available on PyPI but git was not tagged."
296+
297+
- name: ❌ Failure Summary
298+
if: failure()
299+
run: |
300+
echo "## ❌ Release v$NEW_VERSION Failed" >> $GITHUB_STEP_SUMMARY
301+
echo "" >> $GITHUB_STEP_SUMMARY
302+
echo "The release process encountered an error. Check the logs above for details." >> $GITHUB_STEP_SUMMARY
303+
echo "" >> $GITHUB_STEP_SUMMARY
304+
if [[ "${{ steps.pypi_publish.outcome }}" == "success" ]]; then
305+
echo "⚠️ **Note:** Package was successfully published to PyPI but git tagging failed." >> $GITHUB_STEP_SUMMARY
306+
echo "You may need to manually create the git tag or handle the published package." >> $GITHUB_STEP_SUMMARY
307+
else
308+
echo "✅ No changes were committed to git since PyPI publication failed." >> $GITHUB_STEP_SUMMARY
309+
fi

0 commit comments

Comments
 (0)