create_github_release 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 046642a7818c8cf626e29d484eede363e25b9ab591ce134f2746fc18a4fa64f5
4
- data.tar.gz: 6e652ca442a87c6160b029c388df237089e5e607de06f10fd388a2f9d84296ad
3
+ metadata.gz: 04e71e4f65e274c0bea5a1629d80b2f88689e547f07fa644b51cbaf480877122
4
+ data.tar.gz: f105cc39f93ff1c3f3cb85f8d675fb18163a4f1054130c3f3fa1871d7c22c66f
5
5
  SHA512:
6
- metadata.gz: 24d892f156b5a01589f39822fb544475d7e14bf71aa864be551edc028422ddac3c12909aff95cca9bdb1ad92147e3d2f1b3dedc80435b6545d069245e3353cc4
7
- data.tar.gz: dd56d32c64689bee2b44b4178f6c2b5ee324c540417b7e254e20b07f6aa856817b2dac65e97ec7aa29b960de786c9aba10eb1f3c3f755ae2a704287f1a0ad9ed
6
+ metadata.gz: 7c1b778ad46a00c912850f1cb09daacf6615f27cf1c8fbddaaa5f02a7c4e7cbc63a617868e431dca80aae6500b070c5d1b7fc2c50c7ccc1b0e363e2a332a122f
7
+ data.tar.gz: 7f2bd65c4ac7cadf6ec45a7c4fbf914a8287b7c99bab509a2618161002978bdcd805d8236161a2e6c47827de9a79577ca62eae5f47986c4ac6491c91df0cb850
data/CHANGELOG.md CHANGED
@@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## v1.3.0 (2024-01-08)
9
+
10
+ [Full Changelog](https://github.com/main-branch/create_github_release/compare/v1.2.0..v1.3.0)
11
+
12
+ Changes since v1.2.0:
13
+
14
+ * fa6ddb2 Add option to create and revert scripts to show version (#48)
15
+ * 954bea7 Add revert-github-release script (#47)
16
+ * 564267a Correctly use semverify to increment pre-release versions (#46)
17
+
8
18
  ## v1.2.0 (2024-01-07)
9
19
 
10
20
  [Full Changelog](https://github.com/main-branch/create_github_release/compare/v1.1.0..v1.2.0)
data/README.md CHANGED
@@ -345,7 +345,7 @@ git push "${REMOTE}" --delete "${RELEASE_TAG}"
345
345
 
346
346
  # Delete the local branch and tag
347
347
  git branch -D "${RELEASE_BRANCH}"
348
- git tag -D "${RELEASE_TAG}"
348
+ git tag -d "${RELEASE_TAG}"
349
349
  ```
350
350
 
351
351
  ### How is the changelog updated?
@@ -0,0 +1,165 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # This script is used to revert a release that was created with the create-github-release gem
5
+ # It will delete the release branch and tag locally and remotely
6
+
7
+ require 'create_github_release'
8
+
9
+ require 'English'
10
+ require 'optparse'
11
+
12
+ # Options for running this script
13
+ class Options
14
+ attr_writer :default_branch, :release_version, :release_tag, :release_branch, :current_branch, :remote
15
+
16
+ def default_branch = @default_branch ||= 'main'
17
+ def release_version = @release_version ||= `semverify current`.chomp
18
+ def release_tag = @release_tag ||= "v#{release_version}"
19
+ def release_branch = @release_branch ||= "release-#{release_tag}"
20
+ def current_branch = @current_branch ||= `git rev-parse --abbrev-ref HEAD`.chomp
21
+ def remote = @remote ||= 'origin'
22
+ end
23
+
24
+ # Parse the command line options for this script
25
+ class Parser
26
+ # Create a new command line parser
27
+ #
28
+ # @example
29
+ # parser = CommandLineParser.new
30
+ #
31
+ def initialize
32
+ @option_parser = OptionParser.new
33
+ define_options
34
+ @options = Options.new
35
+ end
36
+
37
+ attr_reader :option_parser, :options
38
+
39
+ # Parse the command line arguements returning the options
40
+ #
41
+ # @example
42
+ # options = Parser.new.parse(*ARGV)
43
+ #
44
+ # @param args [Array<String>] the command line arguments
45
+ #
46
+ # @return [Options] the options
47
+ #
48
+ def parse(*args)
49
+ begin
50
+ option_parser.parse!(remaining_args = args.dup)
51
+ rescue OptionParser::InvalidOption, OptionParser::MissingArgument => e
52
+ report_errors(e.message)
53
+ end
54
+ parse_remaining_args(remaining_args)
55
+ options
56
+ end
57
+
58
+ private
59
+
60
+ # Output an error message and useage to stderr and exit
61
+ # @return [void]
62
+ # @api private
63
+ def report_errors(*errors)
64
+ warn error_message(errors)
65
+ exit 1
66
+ end
67
+
68
+ # The command line template as a string
69
+ # @return [String]
70
+ # @api private
71
+ def command_template
72
+ <<~COMMAND
73
+ #{File.basename($PROGRAM_NAME)} [--help]
74
+ COMMAND
75
+ end
76
+
77
+ BANNER = <<~BANNER.freeze
78
+ Usage:
79
+ #{File.basename($PROGRAM_NAME)} [--help | --version]
80
+
81
+ This script reverts the effect of running the create-github-release script.
82
+ It must be run in the root directory of the work tree with the release
83
+ branch checked out (which is the state create-github-release leaves you in).
84
+
85
+ This script should be run beefore the release PR is merged.
86
+
87
+ This script removes the release branch and release tag both in the local
88
+ repository and on the remote. Deleting the branch on GitHub will close the
89
+ GitHub PR automatically.
90
+
91
+ Options:
92
+ BANNER
93
+
94
+ # Define the options for OptionParser
95
+ # @return [void]
96
+ # @api private
97
+ def define_options
98
+ option_parser.banner = BANNER
99
+ %i[
100
+ define_help_option define_version_option
101
+ ].each { |m| send(m) }
102
+ end
103
+
104
+ # Define the help option
105
+ # @return [void]
106
+ # @api private
107
+ def define_help_option
108
+ option_parser.on_tail('-h', '--help', 'Show this message') do
109
+ puts option_parser
110
+ exit 0
111
+ end
112
+ end
113
+
114
+ # Define the version option
115
+ # @return [void]
116
+ # @api private
117
+ def define_version_option
118
+ option_parser.on_tail('-v', '--version', 'Output the version of this script') do
119
+ puts CreateGithubRelease::VERSION
120
+ exit 0
121
+ end
122
+ end
123
+
124
+ # Parse non-option arguments
125
+ # @return [void]
126
+ # @api private
127
+ def parse_remaining_args(remaining_args)
128
+ # There should be no remaining args
129
+ report_errors('Too many args') unless remaining_args.empty?
130
+ end
131
+ end
132
+
133
+ def in_work_tree? = `git rev-parse --is-inside-work-tree 2>/dev/null`.chomp == 'true'
134
+ def in_root_directory? = `git rev-parse --show-toplevel 2>/dev/null`.chomp == Dir.pwd
135
+
136
+ def ref_exists?(name)
137
+ `git rev-parse --verify #{name} >/dev/null 2>&1`
138
+ $CHILD_STATUS.success?
139
+ end
140
+
141
+ unless in_work_tree? && in_root_directory?
142
+ warn 'ERROR: Not in the root directory of a Git work tree'
143
+ exit 1
144
+ end
145
+
146
+ # Parse the command line options
147
+ options = Parser.new.parse(*ARGV)
148
+
149
+ unless options.release_branch == options.current_branch
150
+ warn "ERROR: The current branch '#{options.current_branch}' is not the release branch for #{options.release_version}"
151
+ exit 1
152
+ end
153
+
154
+ unless ref_exists?(options.default_branch)
155
+ warn "ERROR: The default branch '#{options.default_branch}' does not exist"
156
+ exit 1
157
+ end
158
+
159
+ `git checkout #{options.default_branch} >/dev/null`
160
+ `git branch -D #{options.release_branch} >/dev/null`
161
+ `git tag -d #{options.release_tag} >/dev/null`
162
+ `git push #{options.remote} --delete #{options.release_branch} >/dev/null`
163
+ `git push #{options.remote} --delete #{options.release_tag} >/dev/null`
164
+
165
+ puts "Reverted release #{options.release_version}"
@@ -118,28 +118,27 @@ module CreateGithubRelease
118
118
  exit 1
119
119
  end
120
120
 
121
- # The command line template as a string
122
- # @return [String]
123
- # @api private
124
- def command_template
125
- <<~COMMAND
126
- #{File.basename($PROGRAM_NAME)} --help | RELEASE_TYPE [options]
127
- COMMAND
128
- end
121
+ # The banner for the option parser
122
+ BANNER = <<~BANNER.freeze
123
+ Usage:
124
+ #{File.basename($PROGRAM_NAME)} --help | RELEASE_TYPE [options]
125
+
126
+ Version #{CreateGithubRelease::VERSION}
127
+
128
+ RELEASE_TYPE must be 'major', 'minor', 'patch', 'pre', 'release', or 'first'
129
+
130
+ Options:
131
+ BANNER
129
132
 
130
133
  # Define the options for OptionParser
131
134
  # @return [void]
132
135
  # @api private
133
136
  def define_options
134
137
  # @sg-ignore
135
- option_parser.banner = "Usage:\n#{command_template}"
136
- option_parser.separator ''
137
- option_parser.separator "RELEASE_TYPE must be 'major', 'minor', 'patch', 'pre', 'release', or 'first'"
138
- option_parser.separator ''
139
- option_parser.separator 'Options:'
138
+ option_parser.banner = BANNER
140
139
  %i[
141
140
  define_help_option define_default_branch_option define_release_branch_option define_pre_option
142
- define_pre_type_option define_remote_option define_last_release_version_option
141
+ define_pre_type_option define_remote_option define_last_release_version_option define_version_option
143
142
  define_next_release_version_option define_changelog_path_option define_quiet_option define_verbose_option
144
143
  ].each { |m| send(m) }
145
144
  end
@@ -176,7 +175,7 @@ module CreateGithubRelease
176
175
  # @return [void]
177
176
  # @api private
178
177
  def define_verbose_option
179
- option_parser.on('-v', '--[no-]verbose', 'Show extra output') do |verbose|
178
+ option_parser.on('-V', '--[no-]verbose', 'Show extra output') do |verbose|
180
179
  options.verbose = verbose
181
180
  end
182
181
  end
@@ -247,6 +246,16 @@ module CreateGithubRelease
247
246
  options.changelog_path = name
248
247
  end
249
248
  end
249
+
250
+ # Define the version option
251
+ # @return [void]
252
+ # @api private
253
+ def define_version_option
254
+ option_parser.on_tail('-v', '--version', 'Output the version of this script') do
255
+ puts CreateGithubRelease::VERSION
256
+ exit 0
257
+ end
258
+ end
250
259
  end
251
260
  # rubocop:enable Metrics/ClassLength
252
261
  end
@@ -43,7 +43,10 @@ module CreateGithubRelease
43
43
  # @return [void]
44
44
  # @api private
45
45
  def increment_version
46
- `semverify next-#{project.release_type}`
46
+ command = "semverify next-#{project.release_type}"
47
+ command += ' --pre' if project.pre
48
+ command += " --pre-type=#{project.pre_type}" if project.pre_type
49
+ `#{command}`
47
50
  error 'Could not increment version' unless $CHILD_STATUS.success?
48
51
  end
49
52
 
@@ -2,5 +2,5 @@
2
2
 
3
3
  module CreateGithubRelease
4
4
  # The version of this gem
5
- VERSION = '1.2.0'
5
+ VERSION = '1.3.0'
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: create_github_release
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-01-07 00:00:00.000000000 Z
11
+ date: 2024-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: semverify
@@ -185,6 +185,7 @@ email:
185
185
  - jcouball@yahoo.com
186
186
  executables:
187
187
  - create-github-release
188
+ - revert-github-release
188
189
  extensions: []
189
190
  extra_rdoc_files: []
190
191
  files:
@@ -201,6 +202,7 @@ files:
201
202
  - Rakefile
202
203
  - create_github_release.gemspec
203
204
  - exe/create-github-release
205
+ - exe/revert-github-release
204
206
  - lib/create_github_release.rb
205
207
  - lib/create_github_release/assertion_base.rb
206
208
  - lib/create_github_release/assertions.rb
@@ -248,8 +250,8 @@ metadata:
248
250
  allowed_push_host: https://rubygems.org
249
251
  homepage_uri: https://github.com/main-branch/create_github_release
250
252
  source_code_uri: https://github.com/main-branch/create_github_release
251
- changelog_uri: https://rubydoc.info/gems/create_github_release/1.2.0/file/CHANGELOG.md
252
- documentation_uri: https://rubydoc.info/gems/create_github_release/1.2.0
253
+ changelog_uri: https://rubydoc.info/gems/create_github_release/1.3.0/file/CHANGELOG.md
254
+ documentation_uri: https://rubydoc.info/gems/create_github_release/1.3.0
253
255
  rubygems_mfa_required: 'true'
254
256
  post_install_message:
255
257
  rdoc_options: []