Skip to content

Delete the release in GitHub and add a comment to the release PR #52

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

Merged
merged 1 commit into from
Jan 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions exe/revert-github-release
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Options
def release_tag = @release_tag ||= "v#{release_version}"
def release_branch = @release_branch ||= "release-#{release_tag}"
def current_branch = @current_branch ||= `git rev-parse --abbrev-ref HEAD`.chomp
def release_pr = @release_pr ||= `gh pr list --search "head:#{release_branch}" --json number --jq ".[].number"`.chomp
def remote = @remote ||= 'origin'
end

Expand Down Expand Up @@ -79,6 +80,8 @@ class Parser
Usage:
#{File.basename($PROGRAM_NAME)} [--help | --version]

Version #{CreateGithubRelease::VERSION}

This script reverts the effect of running the create-github-release script.
It must be run in the root directory of the work tree with the release
branch checked out (which is the state create-github-release leaves you in).
Expand Down Expand Up @@ -139,6 +142,16 @@ def ref_exists?(name)
$CHILD_STATUS.success?
end

def revert_release!(options)
`gh pr comment #{options.release_pr} --body="Reverting this release using revert-github-release"`
`git checkout #{options.default_branch} >/dev/null`
`git branch -D #{options.release_branch} >/dev/null`
`git tag -d #{options.release_tag} >/dev/null`
`git push #{options.remote} --delete #{options.release_branch} >/dev/null`
`git push #{options.remote} --delete #{options.release_tag} >/dev/null`
`gh release delete #{options.release_tag} --yes >/dev/null`
end

unless in_work_tree? && in_root_directory?
warn 'ERROR: Not in the root directory of a Git work tree'
exit 1
Expand All @@ -157,10 +170,6 @@ unless ref_exists?(options.default_branch)
exit 1
end

`git checkout #{options.default_branch} >/dev/null`
`git branch -D #{options.release_branch} >/dev/null`
`git tag -d #{options.release_tag} >/dev/null`
`git push #{options.remote} --delete #{options.release_branch} >/dev/null`
`git push #{options.remote} --delete #{options.release_tag} >/dev/null`
revert_release!(options)

puts "Reverted release #{options.release_version}"