create_github_release 0.2.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.markdownlint.yml +1 -1
  3. data/CHANGELOG.md +21 -0
  4. data/LICENSE.txt +1 -1
  5. data/README.md +254 -32
  6. data/create_github_release.gemspec +6 -2
  7. data/exe/create-github-release +12 -8
  8. data/lib/create_github_release/assertion_base.rb +25 -11
  9. data/lib/create_github_release/assertions/bundle_is_up_to_date.rb +4 -3
  10. data/lib/create_github_release/assertions/{docker_is_running.rb → gh_authenticated.rb} +9 -8
  11. data/lib/create_github_release/assertions/gh_command_exists.rb +3 -2
  12. data/lib/create_github_release/assertions/git_command_exists.rb +3 -2
  13. data/lib/create_github_release/assertions/in_git_repo.rb +3 -2
  14. data/lib/create_github_release/assertions/in_repo_root_directory.rb +3 -2
  15. data/lib/create_github_release/assertions/last_release_tag_exists.rb +47 -0
  16. data/lib/create_github_release/assertions/local_and_remote_on_same_commit.rb +4 -3
  17. data/lib/create_github_release/assertions/local_release_branch_does_not_exist.rb +6 -5
  18. data/lib/create_github_release/assertions/local_release_tag_does_not_exist.rb +3 -3
  19. data/lib/create_github_release/assertions/no_staged_changes.rb +3 -2
  20. data/lib/create_github_release/assertions/no_uncommitted_changes.rb +3 -2
  21. data/lib/create_github_release/assertions/on_default_branch.rb +5 -4
  22. data/lib/create_github_release/assertions/remote_release_branch_does_not_exist.rb +6 -5
  23. data/lib/create_github_release/assertions/remote_release_tag_does_not_exist.rb +6 -5
  24. data/lib/create_github_release/assertions.rb +2 -2
  25. data/lib/create_github_release/backtick_debug.rb +69 -0
  26. data/lib/create_github_release/change.rb +73 -0
  27. data/lib/create_github_release/changelog.rb +40 -68
  28. data/lib/create_github_release/command_line_options.rb +367 -0
  29. data/lib/create_github_release/command_line_parser.rb +113 -25
  30. data/lib/create_github_release/project.rb +868 -0
  31. data/lib/create_github_release/release_assertions.rb +3 -3
  32. data/lib/create_github_release/release_tasks.rb +1 -1
  33. data/lib/create_github_release/task_base.rb +25 -11
  34. data/lib/create_github_release/tasks/commit_release.rb +4 -3
  35. data/lib/create_github_release/tasks/create_github_release.rb +16 -35
  36. data/lib/create_github_release/tasks/create_release_branch.rb +6 -5
  37. data/lib/create_github_release/tasks/create_release_pull_request.rb +10 -42
  38. data/lib/create_github_release/tasks/create_release_tag.rb +6 -5
  39. data/lib/create_github_release/tasks/push_release.rb +5 -4
  40. data/lib/create_github_release/tasks/update_changelog.rb +16 -67
  41. data/lib/create_github_release/tasks/update_version.rb +33 -5
  42. data/lib/create_github_release/version.rb +1 -1
  43. data/lib/create_github_release.rb +4 -2
  44. metadata +27 -10
  45. data/.vscode/settings.json +0 -7
  46. data/lib/create_github_release/assertions/changelog_docker_container_exists.rb +0 -73
  47. data/lib/create_github_release/options.rb +0 -397
  48. data/lib/create_github_release/release.rb +0 -82
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f086029c9ddf7585de3b2872c59a6d6b4d5449038327cc26703a5dcf31fc5302
4
- data.tar.gz: 5c3eba003d79b8c676b8040f1fd359eb1b9a0271c873d70d930cd283eda743bd
3
+ metadata.gz: b7feefb0f3ef554c8aea3c693cdbbed30aab587be5dc44631101898caadfa658
4
+ data.tar.gz: d342cd8c38e03ca012d5b70daf832642a7434c647d4466d9cd0969e9f4278926
5
5
  SHA512:
6
- metadata.gz: 101af2b61d0a4a78b9ad776bf265981152a11134170c67133910e7f7ab3081f169bc5361b490dda4c5a218c2b46e2a22812a30613582d879ffc7080d058225f5
7
- data.tar.gz: 6cb1bbdcaa1bc974ef0a684648fb82df1be00ff67de2d50503130ce642bd3f0022935d77a2fdd2af7c4bbd992bde05167e48142d9a3b048ff5b779cd63f57a70
6
+ metadata.gz: 122c8e2198ceb28fa9e429f851e7c6d821cadc71fb5a3ade6749c520d1ae7d427159f7059e1455a3a2b15294d8e1125e75451d4d1996fceef63f07e7b88b4ffb
7
+ data.tar.gz: e6d1a7abe65328fc51161458934709b9ae3e747573398f4ef71bcdfad4023f865b76ebd6836fe7622183a90909da9498ca6ec30b29deac89d9608b0a225e8d7d
data/.markdownlint.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  default: true
2
2
 
3
3
  # Unordered list indentation
4
- MD007: { indent: 4 }
4
+ MD007: { indent: 2 }
5
5
 
6
6
  # Line length
7
7
  MD013: { line_length: 90, tables: false, code_blocks: false }
data/CHANGELOG.md CHANGED
@@ -5,6 +5,27 @@ 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.0.0 (2023-02-05)
9
+
10
+ [Full Changelog](https://github.com/main-branch/create_github_release/compare/v0.3.0..v1.0.0)
11
+
12
+ Changes since v0.3.0:
13
+
14
+ * bfd40e6 Handle the first release of a gem (#32)
15
+ * 7a76148 Release v0.3.0 (#31)
16
+
17
+ ## v0.3.0 (2023-01-29)
18
+
19
+ [Full Changelog](https://github.com/main-branch/create_github_release/compare/v0.2.1..v0.3.0)
20
+
21
+ Changes since v0.2.1:
22
+
23
+ * 92ce55a Report "no changes" in the release description (#30)
24
+ * 1b3505b Assert that gh has been authenticated (#29)
25
+ * c7bd12d Complete redesign of this gem (#28)
26
+ * d75e1e9 Create release tag after committing release changes (#27)
27
+ * 24bdd02 Release v0.2.1
28
+
8
29
  ## v0.2.1 (2022-11-16)
9
30
 
10
31
  [Full Changelog](https://github.com/main-branch/create_github_release/compare/v0.2.0...v0.2.1)
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2022 James Couball
3
+ Copyright (c) 2023 James Couball
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -5,36 +5,27 @@
5
5
  [![Maintainability](https://api.codeclimate.com/v1/badges/b8c0af10b15a0ffeb1a1/maintainability)](https://codeclimate.com/github/main-branch/create_github_release/maintainability)
6
6
  [![Test Coverage](https://api.codeclimate.com/v1/badges/b8c0af10b15a0ffeb1a1/test_coverage)](https://codeclimate.com/github/main-branch/create_github_release/test_coverage)
7
7
 
8
- Create a GitHub release for a new gem version.
8
+ A script to manage your gem version and create a GitHub branch, PR, and release
9
+ for a new gem version.
9
10
 
10
- To create a new GitHub release for a gem, run the following from the top level
11
- project directory with the default branch selected:
11
+ Since this script builds a changelog by listing the commits on the default branch,
12
+ it works best if you are disciplined about squashing PR commits to the
13
+ minimum number of commits necessary (usually one) in order to avoid a noisy changelog.
12
14
 
13
- ```shell
14
- create-github-release [major|minor|patch]
15
- ```
15
+ Tested on Ruby 2.7+
16
16
 
17
- The following conditions must be met in order to create a release:
18
-
19
- * The bundle must be up to date (via bundle update)
20
- * You current directory must be in the top level of the git repository
21
- * The default branch must be checked out
22
- * There are no uncommitted changes
23
- * The local and remote must be on the same commit
24
- * The new release tag must not already exist either locally or remotely
25
- * The new release branch must not already exist either locally or remotely
26
- * Docker must be running
27
- * The changelog docker container must already exist or be able to be built
28
- * The gh command must be installed
29
-
30
- The result of running this command is:
31
- * A new release branch is created
32
- * CHANGELOG.md is updated with a list of PRs since the last release
33
- * The Gem version is updated via Bump
34
- * The CHANGELOG.md and version changes are committed and tagged on the new release branch
35
- * The new release branch is pushed to the remote
36
- * A release is created on GitHub
37
- * A release PR is created on GitHub
17
+ * [The create\_github\_release Gem](#the-create_github_release-gem)
18
+ * [Installation](#installation)
19
+ * [Usage](#usage)
20
+ * [First release using this script when there were NO prior releases](#first-release-using-this-script-when-there-were-no-prior-releases)
21
+ * [First release using this script when there were prior releases](#first-release-using-this-script-when-there-were-prior-releases)
22
+ * [Subsequent releases using this script](#subsequent-releases-using-this-script)
23
+ * [After Running create-github-release](#after-running-create-github-release)
24
+ * [How the changelog is updated](#how-the-changelog-is-updated)
25
+ * [Limitations](#limitations)
26
+ * [Development](#development)
27
+ * [Contributing](#contributing)
28
+ * [License](#license)
38
29
 
39
30
  ## Installation
40
31
 
@@ -46,17 +37,248 @@ spec.add_development_dependency 'create_github_release', '~> 0.1'
46
37
 
47
38
  and then install using `bundle update`.
48
39
 
40
+ ## Usage
41
+
42
+ This gem installs the `create-guthub-release` command line tool:
43
+
44
+ ```text
45
+ Usage:
46
+ create-github-release --help | RELEASE_TYPE [options]
47
+
48
+ RELEASE_TYPE must be 'major', 'minor', 'patch', or 'first'
49
+
50
+ Options:
51
+ --default-branch=BRANCH_NAME Override the default branch
52
+ --release-branch=BRANCH_NAME Override the release branch to create
53
+ --remote=REMOTE_NAME Use this remote name instead of 'origin'
54
+ --last-release-version=VERSION
55
+ Use this version instead `bump current`
56
+ --next-release-version=VERSION
57
+ Use this version instead `bump RELEASE_TYPE`
58
+ --changelog-path=PATH Use this file instead of CHANGELOG.md
59
+ -q, --[no-]quiet Do not show output
60
+ -v, --[no-]verbose Show extra output
61
+ -h, --help Show this message
62
+ ```
63
+
64
+ The RELEASE_TYPE should follow [Semantic Versioning](https://semver.org) rules:
65
+
66
+ * A **major** release includes incompatible API changes
67
+ * A **minor** release includes added functionality in a backwards compatible manner
68
+ * A **patch** release includes backwards compatible bug fixes or other inconsequential changes
69
+
70
+ This script will be used for three different use cases:
71
+
72
+ ### First release using this script when there were NO prior releases
73
+
74
+ If this is to be the first release of this gem follow these instructions.
75
+
76
+ For this use case, let's assume the following:
77
+
78
+ * the default branch is `main` (this is the HEAD branch returned by `git remote show origin`)
79
+ * the current version of the gem is `0.1.0` (as returned by `bump current`)
80
+
81
+ If a different first version number is desired, update the version number in the
82
+ source code making sure that `bump current` returns the desired version number.
83
+ Then commit the change to the default branch on the remote before running this
84
+ script.
85
+
86
+ You should start with a CHANGELOG.md that just has frontmatter. An empty file or
87
+ no file is also acceptable. It is not recommended to go with the CHANGELOG.md generated
88
+ by `bundle gem`. Here are suggested CHANGELOG.md contents prior to the first release:
89
+
90
+ ```markdown
91
+ # Change Log
92
+
93
+ Changes for each release are listed in this file.
94
+
95
+ This project adheres to [Semantic Versioning](https://semver.org/) for its releases.
96
+ ```
97
+
98
+ See [How the changelog is updated](#how-the-changelog-is-updated) for more information.
99
+
100
+ The following prerequisites are checked by this script:
101
+
102
+ * The current directory must be in the top level of the git repository
103
+ * The HEAD commit of the default branch (`main`) must be checked out
104
+ * The HEAD commit of the default branch of the local repository must match the
105
+ HEAD commit of the default branch of the remote repository
106
+ * There are no uncommitted or unstaged changes
107
+ * The bundle must be up to date (the script will attempt to update the bundle if needed)
108
+ * The next-release tag (`v0.1.0`) must NOT already exist
109
+ * The next-release branch (`release-v0.1.0`) must NOT already exist
110
+ * The gh command must be installed and authenticated via `gh auth`
111
+
112
+ You should run:
113
+
114
+ ```shell
115
+ create-github-release first
116
+ ```
117
+
118
+ The `create-github-release` script will do the following:
119
+
120
+ * Determine the next-release version (`v0.1.0`) using `bump current`
121
+ * Update the project's changelog file `CHANGELOG.md`
122
+ * Create a release branch `release-v0.1.0`
123
+ * Commit the changes to the changelog and create a release tag (`v0.1.0`) pointing
124
+ to that commit
125
+ * Push the release branch to GitHub
126
+ * Create a GitHub release and pull request for the release
127
+
128
+ See [After running create-github-release](#after-running-create-github-release)
129
+ for instructions for completing your release.
130
+
131
+ ### First release using this script when there were prior releases
132
+
133
+ In order to start using `create-github-release` after you have used some other
134
+ method for managing the gem version and creating releases, you need to ensure the
135
+ following prerequisites are met:
136
+
137
+ 1. that `bump current` is the version of the last release (let's use `1.3.1` as an
138
+ example).
139
+ 2. that there is a corresponding release tag that points to the last commit on the
140
+ default branch of the previous release. If the last version was `1.3.1`, then
141
+ the last-release tag should be `v1.3.1`.
142
+
143
+ Changes to the changelog file to ensure the next-release description is added correctly
144
+ may need to be done. See [How the changelog is updated](#how-the-changelog-is-updated)
145
+ for details.
146
+
147
+ Any changes needed to make sure these prerequisites are met should merged or pushed
148
+ to the default branch on the remote.
149
+
150
+ Once these prerequisites are met and any adjustments have been done, follow the
151
+ directions in [Subserquent releases using this script](#subsequent-releases-using-this-script).
152
+
153
+ See [After running create-github-release](#after-running-create-github-release)
154
+ for instructions for completing your release.
155
+
156
+ ### Subsequent releases using this script
157
+
158
+ For this use case, let's assume the following:
159
+
160
+ * you want to create a `major` release
161
+ * the default branch is `main` (this is the HEAD branch returned by `git remote show origin`)
162
+ * the current version of the gem is `0.1.0` (as returned by `bump current`)
163
+
164
+ The following prerequisites must be met:
165
+
166
+ * The current directory must be in the top level of the git repository
167
+ * The HEAD commit of the default branch (`main`) must be checked out
168
+ * The HEAD commit of the default branch of the local repository must match the
169
+ HEAD commit of the default branch of the remote repository
170
+ * There are no uncommitted or unstaged changes
171
+ * The bundle must be up to date (the script will attempt to update the bundle if needed)
172
+ * The last-release tag (`v0.1.0`) must already exist
173
+ * The next-release tag (`v1.0.0`) must NOT already exist
174
+ * The next-release branch (`release-v1.0.0`) must NOT already exist
175
+ * The gh command must be installed and authenticated via `gh auth`
176
+
177
+ You should run:
178
+
179
+ ```shell
180
+ create-github-release major
181
+ ```
182
+
183
+ The `create-github-release` script will do the following:
184
+
185
+ * Determine the last-release version using `bump current`
186
+ * Determine the next-release version using `bump show-next RELEASE_TYPE`
187
+ * Bump the project's version using `bump RELEASE_TYPE`
188
+ * Update the project's changelog file `CHANGELOG.md`
189
+ * Create a release branch `release-v1.0.0`
190
+ * Commit the changes to the version and changelog AND create a release tag (`v1.0.0`) pointing
191
+ to that commit
192
+ * Push the release branch to GitHub
193
+ * Create a GitHub release and pull request for the release
194
+
195
+ See [After running create-github-release](#after-running-create-github-release)
196
+ for instructions for completing your release.
197
+
198
+ ## After Running create-github-release
199
+
200
+ If you want to make additional updates to the ChangeLog or make changes as
201
+ part of the release PR, it is best to do them before running this script. If
202
+ you must make changes after running this script, you should do so in additional
203
+ commits on the release branch. Before merging to the default branch, you should
204
+ squash all commits down to ONE commit on the release branch and make sure that
205
+ the new release tag (`v1.0.0` in this example) points to this commit.
206
+
207
+ If you are happy with the PR, you should approve it in GitHub.
208
+
209
+ Next, merge the release branch into the default branch **MANUALLY AT THE COMMAND
210
+ LINE** using a fast forward merge with the following commands:
211
+
212
+ ```shell
213
+ git checkout main
214
+ git merge --ff-only release-v1.0.0
215
+ git push
216
+ ```
217
+
218
+ GitHub will automatically close the PR after the `git push` command. These commands
219
+ are output by `create-github-release` so you do not have to memorize them ;)
220
+
221
+ It is important to use a fast foward marge to ensure that the release tag points
222
+ to the right commit after the merge. GitHub does not allow fast forward merges when
223
+ merging a PR.
224
+
225
+ Finally, publish your gem to rubygems.org with the `rake release` command.
226
+
227
+ ## How the changelog is updated
228
+
229
+ A release description is generated by listing the commits between the last release
230
+ and the next release.
231
+
232
+ As an example, let's assume the following:
233
+
234
+ * the last release version was `0.1.0`
235
+ * the next release version will be `1.0.0`
236
+ * there were two changes in the next release:
237
+ * The first commit has sha `1111111` and a commit message starting with the
238
+ line 'Add feature 1'
239
+ * The second commit has sha `2222222` and a commit message starting with the
240
+ line 'Add feature 2'
241
+
242
+ The release description will look like this:
243
+
244
+ ```text
245
+ ## Release v1.0.0
246
+
247
+ Full Changelog
248
+
249
+ Changes since v0.1.0:
250
+
251
+ * 2222222 Add feature 2
252
+ * 1111111 Add feature 1
253
+ ```
254
+
255
+ The existing changelog file is read and split into two parts: front matter and
256
+ body.
257
+
258
+ The front matter is everything before the first markdown H2 header. If there is
259
+ no H2 header, the entire file is considered front matter.
260
+
261
+ The body is everything else in the file (if the file contains an H2 header)
262
+
263
+ The resulting updated changelog file has the following sections:
264
+
265
+ 1. front matter
266
+ 2. next release description
267
+ 3. body (including past release descriptions)
268
+
269
+ ## Limitations
270
+
271
+ * Does not work on Windows
272
+ * Has only been tested on MRI Ruby
273
+ *
274
+
49
275
  ## Development
50
276
 
51
277
  After checking out the repo, run `bin/setup` to install dependencies. Then, run
52
278
  `rake spec` to run the tests. You can also run `bin/console` for an interactive
53
279
  prompt that will allow you to experiment.
54
280
 
55
- To install this gem onto your local machine, run `bundle exec rake install`. To
56
- release a new version, update the version number in `version.rb`, and then run
57
- `bundle exec rake release`, which will create a git tag for the version, push git
58
- commits and the created tag, and push the `.gem` file to
59
- [rubygems.org](https://rubygems.org).
281
+ To install this gem onto your local machine, run `bundle exec rake install`.
60
282
 
61
283
  ## Contributing
62
284
 
@@ -8,8 +8,11 @@ Gem::Specification.new do |spec|
8
8
  spec.authors = ['James']
9
9
  spec.email = ['jcouball@yahoo.com']
10
10
 
11
- spec.summary = 'Create a GitHub release PR for a Ruby Gem'
12
- spec.description = spec.summary
11
+ spec.summary = 'A script to create a GitHub release for a Ruby Gem'
12
+ spec.description = <<~DESCRIPTION
13
+ A script that manages your gem version and creates a GitHub branch, PR, and
14
+ release for a new gem version.
15
+ DESCRIPTION
13
16
  spec.homepage = 'https://github.com/main-branch/create_github_release'
14
17
  spec.license = 'MIT'
15
18
  spec.required_ruby_version = '>= 2.7.0'
@@ -40,6 +43,7 @@ Gem::Specification.new do |spec|
40
43
  spec.add_development_dependency 'simplecov', '~> 0.21'
41
44
  spec.add_development_dependency 'simplecov-lcov', '~> 0.8'
42
45
  spec.add_development_dependency 'solargraph', '~> 0.47'
46
+ spec.add_development_dependency 'timecop', '~> 0.9'
43
47
  spec.add_development_dependency 'yard', '~> 0.9'
44
48
  spec.add_development_dependency 'yardstick', '~> 0.9'
45
49
 
@@ -3,20 +3,24 @@
3
3
 
4
4
  require 'create_github_release'
5
5
 
6
- options = CreateGithubRelease::CommandLineParser.new.parse(ARGV)
7
- CreateGithubRelease::ReleaseAssertions.new(options).make_assertions
6
+ options = CreateGithubRelease::CommandLineParser.new.parse(*ARGV)
7
+ pp options if options.verbose
8
+
9
+ project = CreateGithubRelease::Project.new(options)
10
+
11
+ CreateGithubRelease::ReleaseAssertions.new(project).make_assertions
8
12
  puts unless options.quiet
9
- CreateGithubRelease::ReleaseTasks.new(options).run
13
+ CreateGithubRelease::ReleaseTasks.new(project).run
10
14
 
11
- puts <<~MESSAGE unless options.quiet
12
- Release '#{options.tag}' created successfully
13
- See the release notes at #{options.release_url}
15
+ puts <<~MESSAGE unless project.quiet
16
+ Release '#{project.next_release_tag}' created successfully
17
+ See the release notes at #{project.release_url}
14
18
 
15
19
  Next steps:
16
20
  * Get someone to review and approve the release pull request
17
21
  * Merge the pull request manually from the command line with the following commands:
18
22
 
19
- git checkout #{options.default_branch}
20
- git merge --ff-only #{options.branch}
23
+ git checkout #{project.default_branch}
24
+ git merge --ff-only #{project.release_branch}
21
25
  git push
22
26
  MESSAGE
@@ -9,11 +9,14 @@ module CreateGithubRelease
9
9
  # @api private
10
10
  #
11
11
  class AssertionBase
12
- # Create a new assertion object and save the given `options`
13
- # @param options [CreateGithubRelease::Options] the options
12
+ # Create a new assertion object and save the given `project`
13
+ # @param project [CreateGithubRelease::Project] the project to create a release for
14
14
  # @api private
15
- def initialize(options)
16
- @options = options
15
+ def initialize(project)
16
+ raise ArgumentError, 'project must be a CreateGithubRelease::Project' unless
17
+ project.is_a?(CreateGithubRelease::Project)
18
+
19
+ @project = project
17
20
  end
18
21
 
19
22
  # This method must be overriden by a subclass
@@ -29,25 +32,25 @@ module CreateGithubRelease
29
32
 
30
33
  # @!attribute [r] options
31
34
  #
32
- # The options passed to the assertion object
33
- # @return [CreateGithubRelease::Options] the options
35
+ # The project passed to the assertion object
36
+ # @return [CreateGithubRelease::Project] the project to create a release for
34
37
  # @api private
35
- attr_reader :options
38
+ attr_reader :project
36
39
 
37
- # Calls `Kernel.print` if the `quiet` flag is not set in the `options`
40
+ # Calls `Kernel.print` if the `quiet` flag is not set in the `project`
38
41
  # @param args [Array] the arguments to pass to `Kernel.print`
39
42
  # @return [void]
40
43
  # @api private
41
44
  def print(*args)
42
- super unless options.quiet
45
+ super unless project.quiet?
43
46
  end
44
47
 
45
- # Calls `Kernel.puts` if the `quiet` flag is not set in the `options`
48
+ # Calls `Kernel.puts` if the `quiet` flag is not set in the `project`
46
49
  # @param args [Array] the arguments to pass to `Kernel.puts`
47
50
  # @return [void]
48
51
  # @api private
49
52
  def puts(*args)
50
- super unless options.quiet
53
+ super unless project.quiet?
51
54
  end
52
55
 
53
56
  # Writes a message to stderr and exits with exitcode 1
@@ -58,5 +61,16 @@ module CreateGithubRelease
58
61
  warn "ERROR: #{message}"
59
62
  exit 1
60
63
  end
64
+
65
+ # `true` if the `project.verbose?` flag is `true`
66
+ # @return [Boolean]
67
+ # @api private
68
+ def backtick_debug?
69
+ project.verbose?
70
+ end
71
+
72
+ # This overrides the backtick operator for this class to output debug
73
+ # information if `verbose?` is true
74
+ include CreateGithubRelease::BacktickDebug
61
75
  end
62
76
  end
@@ -5,7 +5,7 @@ require 'create_github_release/assertion_base'
5
5
 
6
6
  module CreateGithubRelease
7
7
  module Assertions
8
- # Assert that options.branch does not exist
8
+ # Assert that project.release+branch does not exist
9
9
  #
10
10
  # Checks both the local repository and the remote repository.
11
11
  #
@@ -17,8 +17,9 @@ module CreateGithubRelease
17
17
  # @example
18
18
  # require 'create_github_release'
19
19
  #
20
- # options = CreateGithubRelease::Options.new { |o| o.release_type = 'major' }
21
- # assertion = CreateGithubRelease::Assertions::BundleIsUpToDate.new(options)
20
+ # options = CreateGithubRelease::CommandLineOptions.new { |o| o.release_type = 'major' }
21
+ # project = CreateGithubRelease::Project.new(options)
22
+ # assertion = CreateGithubRelease::Assertions::BundleIsUpToDate.new(project)
22
23
  # begin
23
24
  # assertion.assert
24
25
  # puts 'Assertion passed'
@@ -5,18 +5,19 @@ require 'create_github_release/assertion_base'
5
5
 
6
6
  module CreateGithubRelease
7
7
  module Assertions
8
- # Assert that docker is running
8
+ # Assert that the 'gh' command is in the path
9
9
  #
10
10
  # @api public
11
11
  #
12
- class DockerIsRunning < AssertionBase
13
- # Make sure that docker is running
12
+ class GhAuthenticated < AssertionBase
13
+ # Make sure that the 'gh' command is authenticated
14
14
  #
15
15
  # @example
16
16
  # require 'create_github_release'
17
17
  #
18
- # options = CreateGithubRelease::Options.new { |o| o.release_type = 'major' }
19
- # assertion = CreateGithubRelease::Assertions::DockerIsRunning.new(options)
18
+ # options = CreateGithubRelease::CommandLineOptions.new { |o| o.release_type = 'major' }
19
+ # project = CreateGithubRelease::Project.new(options)
20
+ # assertion = CreateGithubRelease::Assertions::GhAuthenticated.new(project)
20
21
  # begin
21
22
  # assertion.assert
22
23
  # puts 'Assertion passed'
@@ -29,12 +30,12 @@ module CreateGithubRelease
29
30
  # @raise [SystemExit] if the assertion fails
30
31
  #
31
32
  def assert
32
- print 'Checking that docker is installed and running...'
33
- `docker info > /dev/null 2>&1`
33
+ print 'Checking that the gh command is authenticated...'
34
+ output = `gh auth status 2>&1`
34
35
  if $CHILD_STATUS.success?
35
36
  puts 'OK'
36
37
  else
37
- error 'Docker is not installed or not running'
38
+ error "gh not authenticated:\n#{output}"
38
39
  end
39
40
  end
40
41
  end
@@ -15,8 +15,9 @@ module CreateGithubRelease
15
15
  # @example
16
16
  # require 'create_github_release'
17
17
  #
18
- # options = CreateGithubRelease::Options.new { |o| o.release_type = 'major' }
19
- # assertion = CreateGithubRelease::Assertions::GhCommandExists.new(options)
18
+ # options = CreateGithubRelease::CommandLineOptions.new { |o| o.release_type = 'major' }
19
+ # project = CreateGithubRelease::Project.new(options)
20
+ # assertion = CreateGithubRelease::Assertions::GhCommandExists.new(project)
20
21
  # begin
21
22
  # assertion.assert
22
23
  # puts 'Assertion passed'
@@ -15,8 +15,9 @@ module CreateGithubRelease
15
15
  # @example
16
16
  # require 'create_github_release'
17
17
  #
18
- # options = CreateGithubRelease::Options.new { |o| o.release_type = 'major' }
19
- # assertion = CreateGithubRelease::Assertions::GitCommandExists.new(options)
18
+ # options = CreateGithubRelease::CommandLineOptions.new { |o| o.release_type = 'major' }
19
+ # project = CreateGithubRelease::Project.new(options)
20
+ # assertion = CreateGithubRelease::Assertions::GitCommandExists.new(project)
20
21
  # begin
21
22
  # assertion.assert
22
23
  # puts 'Assertion passed'
@@ -17,8 +17,9 @@ module CreateGithubRelease
17
17
  # @example
18
18
  # require 'create_github_release'
19
19
  #
20
- # options = CreateGithubRelease::Options.new { |o| o.release_type = 'major' }
21
- # assertion = CreateGithubRelease::Assertions::InGitRepo.new(options)
20
+ # options = CreateGithubRelease::CommandLineOptions.new { |o| o.release_type = 'major' }
21
+ # project = CreateGithubRelease::Project.new(options)
22
+ # assertion = CreateGithubRelease::Assertions::InGitRepo.new(project)
22
23
  # begin
23
24
  # assertion.assert
24
25
  # puts 'Assertion passed'
@@ -18,8 +18,9 @@ module CreateGithubRelease
18
18
  # @example
19
19
  # require 'create_github_release'
20
20
  #
21
- # options = CreateGithubRelease::Options.new { |o| o.release_type = 'major' }
22
- # assertion = CreateGithubRelease::Assertions::InRepoRootDirectory.new(options)
21
+ # options = CreateGithubRelease::CommandLineOptions.new { |o| o.release_type = 'major' }
22
+ # project = CreateGithubRelease::Project.new(options)
23
+ # assertion = CreateGithubRelease::Assertions::InRepoRootDirectory.new(project)
23
24
  # begin
24
25
  # assertion.assert
25
26
  # puts 'Assertion passed'
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'English'
4
+ require 'create_github_release/assertion_base'
5
+
6
+ module CreateGithubRelease
7
+ module Assertions
8
+ # Assert that the release tag does not exist in the local repository
9
+ #
10
+ # @api public
11
+ #
12
+ class LastReleaseTagExists < AssertionBase
13
+ # Assert that the last release tag exists in the local repository
14
+ #
15
+ # @example
16
+ # require 'create_github_release'
17
+ #
18
+ # options = CreateGithubRelease::Options.new { |o| o.release_type = 'major' }
19
+ # assertion = CreateGithubRelease::Assertions::LastReleaseTagExists.new(options)
20
+ # begin
21
+ # assertion.assert
22
+ # puts 'Assertion passed'
23
+ # rescue SystemExit
24
+ # puts 'Assertion failed'
25
+ # end
26
+ #
27
+ # @return [void]
28
+ #
29
+ # @raise [SystemExit] if the assertion fails
30
+ #
31
+ def assert
32
+ return if project.first_release?
33
+
34
+ print "Checking that last release tag '#{project.last_release_tag}' exists..."
35
+
36
+ tags = `git tag --list "#{project.last_release_tag}"`.chomp
37
+ error 'Could not list tags' unless $CHILD_STATUS.success?
38
+
39
+ if tags == ''
40
+ error "Last release tag '#{project.last_release_tag}' does not exist"
41
+ else
42
+ puts 'OK'
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end