GitHub Actions ↔ GitHub REST API: Is an atomic rollback after a schema change documented?
0 reputation · 03 Dec 2020, 20:57 UTC
0 reputation · 03 Dec 2020, 20:57 UTC
To revert repository changes made by a workflow that ran after a schema change, using only GitHub Actions and the GitHub REST API.
The REST API can trigger a workflow via workflow_dispatch and cancel a running workflow, but canceling does not undo commits or other side‑effects that have already occurred. Manual rollback requires a custom workflow that checks out a previous commit and pushes it back, yet this approach is not atomic and may leave orphaned artifacts.
GitHub has not yet exposed an API that can atomically roll back all side‑effects of a workflow run after a schema change, and it is unclear whether such a feature will appear in future releases.
GitHub has no documented REST API endpoint that atomically undoes every side‑effect of a completed workflow run, including commits, artifacts, deployments, or external database schema changes. The only API operations that exist are workflow_dispatch, cancel, rerun, and ref manipulation, none of which invert a finished run.
workflow_dispatch or by a comment, this workflow checks out the recorded SHA, restores the repository to that state, and pushes it back to the target branch. Use git push --force-with-lease or the PATCH /repos/{owner}/{repo}/git/refs/{ref} endpoint to update the branch atomically. If branch protection is enabled, prefer creating a “revert” commit instead of a force‑push.actions/checkout@v3 for checkout, actions/github-script for API calls, and actions/checkout@v3 with the fetch-depth option set to 0 to preserve full history. No Action currently performs an “undo” of a workflow run.GitHub treats a workflow run as an execution record separate from Git history. The Git history itself is immutable once pushed; there is no run‑journal that can be replayed in reverse. External state changes (e.g., database migrations) are beyond Git’s scope, so even a perfect Git revert cannot guarantee a clean rollback.
Does the schema change affect only files in the repository, or does it modify an external database or service? Knowing this determines whether a Git‑only rollback suffices or if you must also run a compensating migration.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.