-
Notifications
You must be signed in to change notification settings - Fork 8
Add automated rollback logic to publish workflow and update TypeScript settings #109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -68,3 +68,49 @@ jobs: | |||||||||||||||||||||
| tag_name: v${{ steps.get_version.outputs.VERSION }} | ||||||||||||||||||||||
| env: | ||||||||||||||||||||||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| - name: Rollback release on failure | ||||||||||||||||||||||
| if: failure() | ||||||||||||||||||||||
| shell: bash | ||||||||||||||||||||||
| run: | | ||||||||||||||||||||||
| VERSION=$(node -e "console.log(JSON.parse(require('fs').readFileSync('./package.json', 'utf8')).version)") | ||||||||||||||||||||||
| TAG="v$VERSION" | ||||||||||||||||||||||
| RELEASE_SHA=$(git rev-parse HEAD) | ||||||||||||||||||||||
| COMMIT_MSG=$(git log -1 --pretty=%B "$RELEASE_SHA") | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if echo "$COMMIT_MSG" | grep -q "chore: release v$VERSION"; then | ||||||||||||||||||||||
| echo "Workflow failed. Attempting to roll back release $TAG..." | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # Delete remote tag if it exists | ||||||||||||||||||||||
| git push origin :refs/tags/"$TAG" || true | ||||||||||||||||||||||
|
Comment on lines
+84
to
+85
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. GitHub Release artifact is not deleted, only the tag. The 🛠️ Proposed fix to delete the GitHub Release # Delete remote tag if it exists
git push origin :refs/tags/"$TAG" || true
+
+ # Delete GitHub Release if it exists
+ RELEASE_ID=$(gh release view "$TAG" --json id -q '.id' 2>/dev/null || true)
+ if [ -n "$RELEASE_ID" ]; then
+ gh release delete "$TAG" --yes || echo "Failed to delete GitHub Release"
+ fiNote: This requires the 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # Fetch latest remote changes | ||||||||||||||||||||||
| git fetch origin main | ||||||||||||||||||||||
| REMOTE_SHA=$(git rev-parse origin/main) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # Ensure local working directory is clean | ||||||||||||||||||||||
| git reset --hard HEAD | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if [ "$REMOTE_SHA" = "$RELEASE_SHA" ]; then | ||||||||||||||||||||||
| echo "Release commit is the latest on origin/main. Force-pushing HEAD~1..." | ||||||||||||||||||||||
| if git push origin HEAD~1:main --force; then | ||||||||||||||||||||||
| echo "Rollback successful: release commit removed." | ||||||||||||||||||||||
| else | ||||||||||||||||||||||
| echo "Force-push failed (likely due to branch protection). Creating a revert commit instead..." | ||||||||||||||||||||||
| git revert --no-edit HEAD | ||||||||||||||||||||||
| git push origin HEAD:main | ||||||||||||||||||||||
|
Comment on lines
+99
to
+101
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Revert fallback after failed force-push doesn't sync with remote first. If force-push fails due to branch protection (line 96), the fallback immediately runs 🐛 Proposed fix to sync before revert else
echo "Force-push failed (likely due to branch protection). Creating a revert commit instead..."
+ git fetch origin main
+ git checkout main
+ git reset --hard origin/main
git revert --no-edit HEAD
- git push origin HEAD:main
+ git revert --no-edit "$RELEASE_SHA"
+ git push origin main
fiWait—after reset to 🤖 Prompt for AI Agents |
||||||||||||||||||||||
| fi | ||||||||||||||||||||||
|
Comment on lines
+94
to
+102
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TOCTOU race between fetch and force-push. Between 🔒 Proposed fix using --force-with-lease- if git push origin HEAD~1:main --force; then
+ if git push origin HEAD~1:main --force-with-lease=main:"$REMOTE_SHA"; thenThis ensures the push only succeeds if 🤖 Prompt for AI Agents |
||||||||||||||||||||||
| else | ||||||||||||||||||||||
| if git merge-base --is-ancestor "$RELEASE_SHA" origin/main; then | ||||||||||||||||||||||
| echo "Release commit exists on origin/main but is not the latest. Reverting it..." | ||||||||||||||||||||||
| git checkout main | ||||||||||||||||||||||
| git pull origin main | ||||||||||||||||||||||
| git revert --no-edit "$RELEASE_SHA" | ||||||||||||||||||||||
| git push origin HEAD:main | ||||||||||||||||||||||
| else | ||||||||||||||||||||||
| echo "Release commit was not pushed to origin/main. No rollback needed." | ||||||||||||||||||||||
| fi | ||||||||||||||||||||||
| fi | ||||||||||||||||||||||
| else | ||||||||||||||||||||||
| echo "No release commit found on HEAD. No rollback needed." | ||||||||||||||||||||||
| fi | ||||||||||||||||||||||
|
Comment on lines
+72
to
+116
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial | ⚖️ Poor tradeoff No handling for workflow cancellation mid-rollback. If the workflow is cancelled while the rollback script is executing, the repository could be left in a partially rolled-back state (e.g., tag deleted but branch not reverted). Consider adding a trap to handle 🤖 Prompt for AI Agents |
||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick | 🔵 Trivial | 💤 Low value
Version extraction duplicated; consider reusing step output.
The version is already extracted in the
get_versionstep (lines 58-62). You could reference${{ steps.get_version.outputs.VERSION }}via an environment variable instead of re-parsingpackage.json. However, sincefailure()context might not preserve all step outputs reliably, verify this works in your CI environment.🤖 Prompt for AI Agents