Skip to content

Commit

Permalink
Delete the release in GitHub and add a comment to the release PR (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcouball committed Jan 8, 2024
1 parent 87fc080 commit 6b0e295
Showing 1 changed file with 14 additions and 5 deletions.
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}"

0 comments on commit 6b0e295

Please sign in to comment.