create_github_release 1.1.0 → 1.2.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.
- checksums.yaml +4 -4
- data/.yardopts +1 -0
- data/CHANGELOG.md +8 -0
- data/README.md +156 -38
- data/Rakefile +6 -6
- data/create_github_release.gemspec +3 -3
- data/exe/create-github-release +1 -1
- data/lib/create_github_release/assertions/bundle_is_up_to_date.rb +1 -1
- data/lib/create_github_release/assertions/gh_authenticated.rb +1 -1
- data/lib/create_github_release/assertions/gh_command_exists.rb +1 -1
- data/lib/create_github_release/assertions/git_command_exists.rb +1 -1
- data/lib/create_github_release/assertions/in_git_repo.rb +1 -1
- data/lib/create_github_release/assertions/in_repo_root_directory.rb +1 -1
- data/lib/create_github_release/assertions/local_and_remote_on_same_commit.rb +1 -1
- data/lib/create_github_release/assertions/local_release_branch_does_not_exist.rb +1 -1
- data/lib/create_github_release/assertions/no_staged_changes.rb +1 -1
- data/lib/create_github_release/assertions/no_uncommitted_changes.rb +1 -1
- data/lib/create_github_release/assertions/on_default_branch.rb +1 -1
- data/lib/create_github_release/assertions/remote_release_branch_does_not_exist.rb +1 -1
- data/lib/create_github_release/assertions/remote_release_tag_does_not_exist.rb +1 -1
- data/lib/create_github_release/command_line/options.rb +151 -0
- data/lib/create_github_release/command_line/parser.rb +253 -0
- data/lib/create_github_release/command_line/validations.rb +293 -0
- data/lib/create_github_release/command_line/validator.rb +93 -0
- data/lib/create_github_release/command_line.rb +43 -0
- data/lib/create_github_release/project.rb +115 -55
- data/lib/create_github_release/release_assertions.rb +1 -1
- data/lib/create_github_release/release_tasks.rb +1 -1
- data/lib/create_github_release/tasks/commit_release.rb +1 -1
- data/lib/create_github_release/tasks/create_github_release.rb +1 -1
- data/lib/create_github_release/tasks/create_release_branch.rb +1 -1
- data/lib/create_github_release/tasks/create_release_pull_request.rb +1 -1
- data/lib/create_github_release/tasks/create_release_tag.rb +1 -1
- data/lib/create_github_release/tasks/push_release.rb +1 -1
- data/lib/create_github_release/tasks/update_changelog.rb +1 -1
- data/lib/create_github_release/tasks/update_version.rb +1 -1
- data/lib/create_github_release/version.rb +1 -1
- data/lib/create_github_release.rb +1 -2
- metadata +10 -34
- data/lib/create_github_release/command_line_options.rb +0 -378
- data/lib/create_github_release/command_line_parser.rb +0 -229
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 046642a7818c8cf626e29d484eede363e25b9ab591ce134f2746fc18a4fa64f5
|
4
|
+
data.tar.gz: 6e652ca442a87c6160b029c388df237089e5e607de06f10fd388a2f9d84296ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 24d892f156b5a01589f39822fb544475d7e14bf71aa864be551edc028422ddac3c12909aff95cca9bdb1ad92147e3d2f1b3dedc80435b6545d069245e3353cc4
|
7
|
+
data.tar.gz: dd56d32c64689bee2b44b4178f6c2b5ee324c540417b7e254e20b07f6aa856817b2dac65e97ec7aa29b960de786c9aba10eb1f3c3f755ae2a704287f1a0ad9ed
|
data/.yardopts
CHANGED
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,14 @@ 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.2.0 (2024-01-07)
|
9
|
+
|
10
|
+
[Full Changelog](https://github.com/main-branch/create_github_release/compare/v1.1.0..v1.2.0)
|
11
|
+
|
12
|
+
Changes since v1.1.0:
|
13
|
+
|
14
|
+
* 80da449 Add support for pre-release versions (#43)
|
15
|
+
|
8
16
|
## v1.1.0 (2023-10-15)
|
9
17
|
|
10
18
|
[Full Changelog](https://github.com/main-branch/create_github_release/compare/v1.0.0..v1.1.0)
|
data/README.md
CHANGED
@@ -5,34 +5,46 @@
|
|
5
5
|
[](https://codeclimate.com/github/main-branch/create_github_release/maintainability)
|
6
6
|
[](https://codeclimate.com/github/main-branch/create_github_release/test_coverage)
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
8
|
+
When run in your gem's git worktree, the `create-github-release` script does the
|
9
|
+
following:
|
10
|
+
|
11
|
+
* bumps the gem's version following SemVer,
|
12
|
+
* updates the gems's changelog,
|
13
|
+
* creates a new release branch and release tag,
|
14
|
+
* commits the version and changelog changes to the release branch,
|
15
|
+
* pushes these changes to GitHub and creates a PR to merge the release branch to the
|
16
|
+
default branch
|
17
|
+
|
18
|
+
Since this script builds a changelog by listing the commits since the last release, it
|
19
|
+
works best if you are disciplined about squashing PR commits to the minimum number of
|
20
|
+
commits necessary (usually one) in order to avoid a noisy changelog.
|
21
|
+
|
22
|
+
Tested on Ruby 3.0+
|
23
|
+
|
24
|
+
* [Installation](#installation)
|
25
|
+
* [Usage](#usage)
|
26
|
+
* [First release using this script when there were NO prior releases](#first-release-using-this-script-when-there-were-no-prior-releases)
|
27
|
+
* [First release using this script when there were prior releases](#first-release-using-this-script-when-there-were-prior-releases)
|
28
|
+
* [Subsequent releases using this script](#subsequent-releases-using-this-script)
|
29
|
+
* [Pre-release versions](#pre-release-versions)
|
30
|
+
* [Creating the first pre-release version for a release](#creating-the-first-pre-release-version-for-a-release)
|
31
|
+
* [Creating subsequent pre-releases](#creating-subsequent-pre-releases)
|
32
|
+
* [Changing the pre-release type](#changing-the-pre-release-type)
|
33
|
+
* [Creating the release after pre-releases](#creating-the-release-after-pre-releases)
|
23
34
|
* [After Running create-github-release](#after-running-create-github-release)
|
24
|
-
|
25
|
-
* [
|
26
|
-
* [
|
27
|
-
|
28
|
-
|
35
|
+
* [FAQ](#faq)
|
36
|
+
* [What if I want to reverse the changes made by this script?](#what-if-i-want-to-reverse-the-changes-made-by-this-script)
|
37
|
+
* [How is the changelog updated?](#how-is-the-changelog-updated)
|
38
|
+
* [Development](#development)
|
39
|
+
* [Contributing](#contributing)
|
40
|
+
* [License](#license)
|
29
41
|
|
30
42
|
## Installation
|
31
43
|
|
32
44
|
Add `create_github_release` as a development dependency in your project's gemspec:
|
33
45
|
|
34
46
|
```ruby
|
35
|
-
spec.add_development_dependency 'create_github_release'
|
47
|
+
spec.add_development_dependency 'create_github_release'
|
36
48
|
```
|
37
49
|
|
38
50
|
and then install using `bundle update`.
|
@@ -45,16 +57,18 @@ This gem installs the `create-guthub-release` command line tool:
|
|
45
57
|
Usage:
|
46
58
|
create-github-release --help | RELEASE_TYPE [options]
|
47
59
|
|
48
|
-
RELEASE_TYPE must be 'major', 'minor', 'patch', or 'first'
|
60
|
+
RELEASE_TYPE must be 'major', 'minor', 'patch', 'pre', 'release', or 'first'
|
49
61
|
|
50
62
|
Options:
|
51
63
|
--default-branch=BRANCH_NAME Override the default branch
|
52
64
|
--release-branch=BRANCH_NAME Override the release branch to create
|
65
|
+
-p, --pre Create a pre-release
|
66
|
+
-t, --pre-type=TYPE Type of pre-release to create (e.g. alpha, beta, etc.)
|
53
67
|
--remote=REMOTE_NAME Use this remote name instead of 'origin'
|
54
68
|
--last-release-version=VERSION
|
55
69
|
Use this version instead `semverify current`
|
56
70
|
--next-release-version=VERSION
|
57
|
-
Use this version instead `semverify RELEASE_TYPE`
|
71
|
+
Use this version instead `semverify next-RELEASE_TYPE`
|
58
72
|
--changelog-path=PATH Use this file instead of CHANGELOG.md
|
59
73
|
-q, --[no-]quiet Do not show output
|
60
74
|
-v, --[no-]verbose Show extra output
|
@@ -195,7 +209,85 @@ The `create-github-release` script will do the following:
|
|
195
209
|
See [After running create-github-release](#after-running-create-github-release)
|
196
210
|
for instructions for completing your release.
|
197
211
|
|
198
|
-
|
212
|
+
### Pre-release versions
|
213
|
+
|
214
|
+
This gem allows creation of a release with a pre-release version as [defined in the
|
215
|
+
Semver 2.0.0 spec](https://semver.org/#spec-item-9). An example of a pre-release
|
216
|
+
version is `1.0.0-beta.1`.
|
217
|
+
|
218
|
+
Pre-release versions have a lower precedence than their associated normal version.
|
219
|
+
This means the pre-release version sorts before the associated release version. For
|
220
|
+
example, `1.0.0-beta.1` comes before `1.0.0`. A pre-release version indicates that
|
221
|
+
the version is unstable and might not yet satisfy the intended compatibility
|
222
|
+
requirements as denoted by its associated normal version
|
223
|
+
|
224
|
+
This gem limits pre-release versions to the form `MAJOR.MINOR.PATCH-PRERELEASE` where
|
225
|
+
`PRERELEASE` can ONLY have the following form: `TYPE.DIGITS`. `TYPE` is any text
|
226
|
+
string allowed in the Semver 2.0.0 spec and is typically 'alpha', 'beta', 'pre',
|
227
|
+
'rc', etc. `DIGITS` is a numeric identifier that does not include leading zeroes.
|
228
|
+
|
229
|
+
#### Creating the first pre-release version for a release
|
230
|
+
|
231
|
+
Let's say that:
|
232
|
+
* The current release version is `1.3.4`
|
233
|
+
* You want to create the first pre-release for the next MINOR release
|
234
|
+
* You want the pre-release TYPE to be 'alpha'
|
235
|
+
|
236
|
+
You would use the following command:
|
237
|
+
|
238
|
+
```shell
|
239
|
+
create-github-release minor --pre --pre-type=alpha
|
240
|
+
```
|
241
|
+
|
242
|
+
This would create a release whose version is `1.4.0-alpha.1`.
|
243
|
+
|
244
|
+
#### Creating subsequent pre-releases
|
245
|
+
|
246
|
+
Let's say you would like to create another alpha pre-release for the `1.4.0` release.
|
247
|
+
|
248
|
+
You would use the following command:
|
249
|
+
|
250
|
+
```shell
|
251
|
+
create-github-release pre
|
252
|
+
```
|
253
|
+
|
254
|
+
This woould increment the pre-release numeric identifier giving the version is `1.4.0-alpha.2`.
|
255
|
+
|
256
|
+
It is only valid to use the `pre` command when the current release is a pre-release
|
257
|
+
version. For example, it would not be valid to run `create-github-release pre` if the
|
258
|
+
current version is `1.0.0`.
|
259
|
+
|
260
|
+
#### Changing the pre-release type
|
261
|
+
|
262
|
+
Continuing with the previous example where the current release version is
|
263
|
+
`1.4.0-alpha.2`, if you now you want to create a beta pre-release, you would use the
|
264
|
+
following command:
|
265
|
+
|
266
|
+
```shell
|
267
|
+
create-github-release pre --pre-type=beta
|
268
|
+
```
|
269
|
+
|
270
|
+
This would change the release type and reset the pre-release numeric identifier to
|
271
|
+
'1' resulting in the verion `1.4.0-beta.1`
|
272
|
+
|
273
|
+
Note that the current release type MUST be lexically less than the new release type
|
274
|
+
specified on the command line. This means that if the current version is
|
275
|
+
`1.4.0-beta.1`, it would not be valid to change the release type to `alpha` since
|
276
|
+
'alpha' <= 'beta'.
|
277
|
+
|
278
|
+
#### Creating the release after pre-releases
|
279
|
+
|
280
|
+
Now let's say that the current version is `1.4.0-beta.1`. To create release whose version
|
281
|
+
is `1.4.0`, use the command:
|
282
|
+
|
283
|
+
```shell
|
284
|
+
create-github-release release
|
285
|
+
```
|
286
|
+
|
287
|
+
It is only valid to use the `release` command when the current release version is a
|
288
|
+
pre-release version.
|
289
|
+
|
290
|
+
### After Running create-github-release
|
199
291
|
|
200
292
|
If you want to make additional updates to the ChangeLog or make changes as
|
201
293
|
part of the release PR, it is best to do them before running this script. If
|
@@ -216,15 +308,47 @@ git push
|
|
216
308
|
```
|
217
309
|
|
218
310
|
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
|
311
|
+
are output by `create-github-release` so you do not have to memorize them.
|
220
312
|
|
221
|
-
It is important to use a fast foward
|
222
|
-
|
223
|
-
merging a PR.
|
313
|
+
It is important to use a fast foward merge to ensure that the release tag points to
|
314
|
+
the right commit after the merge. The GitHub UI does not allow fast forward merges
|
315
|
+
when merging a PR.
|
224
316
|
|
225
|
-
Finally, publish your gem to rubygems.org with the
|
317
|
+
Finally, publish your gem to rubygems.org with the command:
|
226
318
|
|
227
|
-
|
319
|
+
```shell
|
320
|
+
rake release:rubygem_push
|
321
|
+
```
|
322
|
+
|
323
|
+
## FAQ
|
324
|
+
|
325
|
+
### What if I want to reverse the changes made by this script?
|
326
|
+
|
327
|
+
You will need to delete the Git tag and branch created by this script both remotely and locally.
|
328
|
+
|
329
|
+
In your worktree run the following commands:
|
330
|
+
|
331
|
+
```shell
|
332
|
+
DEFAULT_BRANCH=main
|
333
|
+
RELEASE_VERSION=1.0.1
|
334
|
+
RELEASE_TAG="v${RELEASE_VERSION}"
|
335
|
+
RELEASE_BRANCH="release_${RELEASE_TAG}"
|
336
|
+
REMOTE=origin
|
337
|
+
|
338
|
+
# Make sure the release branch is not checked out
|
339
|
+
git checkout "${DEFAULT_BRANCH}"
|
340
|
+
|
341
|
+
# Delete remote branch and tag
|
342
|
+
# Deleting the remote branch will automatically close the release PR
|
343
|
+
git push "${REMOTE}" --delete "${RELEASE_BRANCH}"
|
344
|
+
git push "${REMOTE}" --delete "${RELEASE_TAG}"
|
345
|
+
|
346
|
+
# Delete the local branch and tag
|
347
|
+
git branch -D "${RELEASE_BRANCH}"
|
348
|
+
git tag -D "${RELEASE_TAG}"
|
349
|
+
```
|
350
|
+
|
351
|
+
### How is the changelog updated?
|
228
352
|
|
229
353
|
A release description is generated by listing the commits between the last release
|
230
354
|
and the next release.
|
@@ -266,24 +390,18 @@ The resulting updated changelog file has the following sections:
|
|
266
390
|
2. next release description
|
267
391
|
3. body (including past release descriptions)
|
268
392
|
|
269
|
-
## Limitations
|
270
|
-
|
271
|
-
* Does not work on Windows
|
272
|
-
* Has only been tested on MRI Ruby
|
273
|
-
*
|
274
|
-
|
275
393
|
## Development
|
276
394
|
|
277
395
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
278
396
|
`rake spec` to run the tests. You can also run `bin/console` for an interactive
|
279
397
|
prompt that will allow you to experiment.
|
280
398
|
|
281
|
-
To install this gem onto your
|
399
|
+
To install this gem onto your current Ruby environment, run `bundle exec rake install`.
|
282
400
|
|
283
401
|
## Contributing
|
284
402
|
|
285
403
|
Bug reports and pull requests are welcome on
|
286
|
-
[this project's GitHub
|
404
|
+
[this project's GitHub page](https://github.com/main-branch/create_github_release)
|
287
405
|
|
288
406
|
## License
|
289
407
|
|
data/Rakefile
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
# The default task
|
4
4
|
|
5
5
|
desc 'Run the same tasks that the CI build will run'
|
6
|
-
task default: %w[spec rubocop yard yard:audit yard:coverage
|
6
|
+
task default: %w[spec rubocop yard yard:audit yard:coverage bundle:audit build]
|
7
7
|
|
8
8
|
# Bundler Audit
|
9
9
|
|
@@ -75,12 +75,12 @@ Yardstick::Rake::Verify.new(:'yard:coverage') do |verify|
|
|
75
75
|
verify.threshold = 100
|
76
76
|
end
|
77
77
|
|
78
|
-
# Solargraph typecheck
|
78
|
+
# # Solargraph typecheck
|
79
79
|
|
80
|
-
desc 'Run the solargraph type checker'
|
81
|
-
task :'solargraph:typecheck' do
|
82
|
-
|
83
|
-
end
|
80
|
+
# desc 'Run the solargraph type checker'
|
81
|
+
# task :'solargraph:typecheck' do
|
82
|
+
# sh 'bundle exec solargraph typecheck --level=typed'
|
83
|
+
# end
|
84
84
|
|
85
85
|
# Additional cleanup
|
86
86
|
|
@@ -21,7 +21,8 @@ Gem::Specification.new do |spec|
|
|
21
21
|
|
22
22
|
spec.metadata['homepage_uri'] = spec.homepage
|
23
23
|
spec.metadata['source_code_uri'] = spec.homepage
|
24
|
-
spec.metadata['changelog_uri'] = spec.
|
24
|
+
spec.metadata['changelog_uri'] = "https://rubydoc.info/gems/#{spec.name}/#{spec.version}/file/CHANGELOG.md"
|
25
|
+
spec.metadata['documentation_uri'] = "https://rubydoc.info/gems/#{spec.name}/#{spec.version}"
|
25
26
|
|
26
27
|
# Specify which files should be added to the gem when it is released.
|
27
28
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
@@ -42,10 +43,9 @@ Gem::Specification.new do |spec|
|
|
42
43
|
spec.add_development_dependency 'redcarpet', '~> 3.5'
|
43
44
|
spec.add_development_dependency 'rspec', '~> 3.10'
|
44
45
|
spec.add_development_dependency 'rubocop', '~> 1.36'
|
45
|
-
spec.add_development_dependency 'ruby-debug-ide', '~> 0.7'
|
46
46
|
spec.add_development_dependency 'simplecov', '~> 0.21'
|
47
47
|
spec.add_development_dependency 'simplecov-lcov', '~> 0.8'
|
48
|
-
spec.add_development_dependency 'solargraph', '~> 0.49'
|
48
|
+
# spec.add_development_dependency 'solargraph', '~> 0.49'
|
49
49
|
spec.add_development_dependency 'timecop', '~> 0.9'
|
50
50
|
spec.add_development_dependency 'yard', '~> 0.9'
|
51
51
|
spec.add_development_dependency 'yardstick', '~> 0.9'
|
data/exe/create-github-release
CHANGED
@@ -17,7 +17,7 @@ module CreateGithubRelease
|
|
17
17
|
# @example
|
18
18
|
# require 'create_github_release'
|
19
19
|
#
|
20
|
-
# options = CreateGithubRelease::
|
20
|
+
# options = CreateGithubRelease::CommandLine::Options.new { |o| o.release_type = 'major' }
|
21
21
|
# project = CreateGithubRelease::Project.new(options)
|
22
22
|
# assertion = CreateGithubRelease::Assertions::BundleIsUpToDate.new(project)
|
23
23
|
# begin
|
@@ -15,7 +15,7 @@ module CreateGithubRelease
|
|
15
15
|
# @example
|
16
16
|
# require 'create_github_release'
|
17
17
|
#
|
18
|
-
# options = CreateGithubRelease::
|
18
|
+
# options = CreateGithubRelease::CommandLine::Options.new { |o| o.release_type = 'major' }
|
19
19
|
# project = CreateGithubRelease::Project.new(options)
|
20
20
|
# assertion = CreateGithubRelease::Assertions::GhAuthenticated.new(project)
|
21
21
|
# begin
|
@@ -15,7 +15,7 @@ module CreateGithubRelease
|
|
15
15
|
# @example
|
16
16
|
# require 'create_github_release'
|
17
17
|
#
|
18
|
-
# options = CreateGithubRelease::
|
18
|
+
# options = CreateGithubRelease::CommandLine::Options.new { |o| o.release_type = 'major' }
|
19
19
|
# project = CreateGithubRelease::Project.new(options)
|
20
20
|
# assertion = CreateGithubRelease::Assertions::GhCommandExists.new(project)
|
21
21
|
# begin
|
@@ -15,7 +15,7 @@ module CreateGithubRelease
|
|
15
15
|
# @example
|
16
16
|
# require 'create_github_release'
|
17
17
|
#
|
18
|
-
# options = CreateGithubRelease::
|
18
|
+
# options = CreateGithubRelease::CommandLine::Options.new { |o| o.release_type = 'major' }
|
19
19
|
# project = CreateGithubRelease::Project.new(options)
|
20
20
|
# assertion = CreateGithubRelease::Assertions::GitCommandExists.new(project)
|
21
21
|
# begin
|
@@ -17,7 +17,7 @@ module CreateGithubRelease
|
|
17
17
|
# @example
|
18
18
|
# require 'create_github_release'
|
19
19
|
#
|
20
|
-
# options = CreateGithubRelease::
|
20
|
+
# options = CreateGithubRelease::CommandLine::Options.new { |o| o.release_type = 'major' }
|
21
21
|
# project = CreateGithubRelease::Project.new(options)
|
22
22
|
# assertion = CreateGithubRelease::Assertions::InGitRepo.new(project)
|
23
23
|
# begin
|
@@ -18,7 +18,7 @@ module CreateGithubRelease
|
|
18
18
|
# @example
|
19
19
|
# require 'create_github_release'
|
20
20
|
#
|
21
|
-
# options = CreateGithubRelease::
|
21
|
+
# options = CreateGithubRelease::CommandLine::Options.new { |o| o.release_type = 'major' }
|
22
22
|
# project = CreateGithubRelease::Project.new(options)
|
23
23
|
# assertion = CreateGithubRelease::Assertions::InRepoRootDirectory.new(project)
|
24
24
|
# begin
|
@@ -17,7 +17,7 @@ module CreateGithubRelease
|
|
17
17
|
# @example
|
18
18
|
# require 'create_github_release'
|
19
19
|
#
|
20
|
-
# options = CreateGithubRelease::
|
20
|
+
# options = CreateGithubRelease::CommandLine::Options.new { |o| o.release_type = 'major' }
|
21
21
|
# project = CreateGithubRelease::Project.new(options)
|
22
22
|
# assertion = CreateGithubRelease::Assertions::LocalAndRemoteOnSameCommit.new(project)
|
23
23
|
# begin
|
@@ -15,7 +15,7 @@ module CreateGithubRelease
|
|
15
15
|
# @example
|
16
16
|
# require 'create_github_release'
|
17
17
|
#
|
18
|
-
# options = CreateGithubRelease::
|
18
|
+
# options = CreateGithubRelease::CommandLine::Options.new { |o| o.release_type = 'major' }
|
19
19
|
# project = CreateGithubRelease::Project.new(options)
|
20
20
|
# assertion = CreateGithubRelease::Assertions::LocalReleaseBranchDoesNotExist.new(project)
|
21
21
|
# begin
|
@@ -17,7 +17,7 @@ module CreateGithubRelease
|
|
17
17
|
# @example
|
18
18
|
# require 'create_github_release'
|
19
19
|
#
|
20
|
-
# options = CreateGithubRelease::
|
20
|
+
# options = CreateGithubRelease::CommandLine::Options.new { |o| o.release_type = 'major' }
|
21
21
|
# project = CreateGithubRelease::Project.new(options)
|
22
22
|
# assertion = CreateGithubRelease::Assertions::NoStagedChanges.new(project)
|
23
23
|
# begin
|
@@ -17,7 +17,7 @@ module CreateGithubRelease
|
|
17
17
|
# @example
|
18
18
|
# require 'create_github_release'
|
19
19
|
#
|
20
|
-
# options = CreateGithubRelease::
|
20
|
+
# options = CreateGithubRelease::CommandLine::Options.new { |o| o.release_type = 'major' }
|
21
21
|
# project = CreateGithubRelease::Project.new(options)
|
22
22
|
# assertion = CreateGithubRelease::Assertions::NoUncommittedChanges.new(project)
|
23
23
|
# begin
|
@@ -17,7 +17,7 @@ module CreateGithubRelease
|
|
17
17
|
# @example
|
18
18
|
# require 'create_github_release'
|
19
19
|
#
|
20
|
-
# options = CreateGithubRelease::
|
20
|
+
# options = CreateGithubRelease::CommandLine::Options.new { |o| o.release_type = 'major' }
|
21
21
|
# project = CreateGithubRelease::Project.new(options)
|
22
22
|
# assertion = CreateGithubRelease::Assertions::OnDefaultBranch.new(project)
|
23
23
|
# begin
|
@@ -15,7 +15,7 @@ module CreateGithubRelease
|
|
15
15
|
# @example
|
16
16
|
# require 'create_github_release'
|
17
17
|
#
|
18
|
-
# options = CreateGithubRelease::
|
18
|
+
# options = CreateGithubRelease::CommandLine::Options.new { |o| o.release_type = 'major' }
|
19
19
|
# project = CreateGithubRelease::Project.new(options)
|
20
20
|
# assertion = CreateGithubRelease::Assertions::RemoteReleaseBranchDoesNotExist.new(project)
|
21
21
|
# begin
|
@@ -15,7 +15,7 @@ module CreateGithubRelease
|
|
15
15
|
# @example
|
16
16
|
# require 'create_github_release'
|
17
17
|
#
|
18
|
-
# options = CreateGithubRelease::
|
18
|
+
# options = CreateGithubRelease::CommandLine::Options.new { |o| o.release_type = 'major' }
|
19
19
|
# project = CreateGithubRelease::Project.new(options)
|
20
20
|
# assertion = CreateGithubRelease::Assertions::RemoteReleaseTagDoesNotExist.new(project)
|
21
21
|
# begin
|
@@ -0,0 +1,151 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'uri'
|
4
|
+
require 'forwardable'
|
5
|
+
|
6
|
+
module CreateGithubRelease
|
7
|
+
module CommandLine
|
8
|
+
# Stores and validates the command line options
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
# options = CreateGithubRelease::CommandLine::Options.new
|
12
|
+
# options.release_type = 'major'
|
13
|
+
# options.valid? #=> true
|
14
|
+
# options.errors #=> []
|
15
|
+
#
|
16
|
+
# @api public
|
17
|
+
#
|
18
|
+
class Options
|
19
|
+
CreateGithubRelease::CommandLine::ALLOWED_OPTIONS.each { |option| attr_accessor option }
|
20
|
+
|
21
|
+
# @attribute release_type [rw] the type of release to create
|
22
|
+
#
|
23
|
+
# Must be one of the VALID_RELEASE_TYPES
|
24
|
+
#
|
25
|
+
# @example
|
26
|
+
# options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major')
|
27
|
+
# options.release_type #=> 'major'
|
28
|
+
# @return [String]
|
29
|
+
# @api public
|
30
|
+
|
31
|
+
# @attribute default_branch [rw] the default branch of the repository
|
32
|
+
# @example
|
33
|
+
# options = CreateGithubRelease::CommandLine::Options.new(default_branch: 'main')
|
34
|
+
# options.default_branch #=> 'main'
|
35
|
+
# @return [String]
|
36
|
+
# @api public
|
37
|
+
|
38
|
+
# @attribute release_branch [rw] the branch use to create the release
|
39
|
+
# @example
|
40
|
+
# options = CreateGithubRelease::CommandLine::Options.new(release_branch: 'release-v1.0.0')
|
41
|
+
# options.release_branch #=> 'release-v1.0.0'
|
42
|
+
# @return [String]
|
43
|
+
# @api public
|
44
|
+
|
45
|
+
# @attribute remote [rw] the name of the remote to use to access Github
|
46
|
+
# @example
|
47
|
+
# options = CreateGithubRelease::CommandLine::Options.new(remote: 'origin')
|
48
|
+
# options.remote #=> 'origin'
|
49
|
+
# @return [String]
|
50
|
+
# @api public
|
51
|
+
|
52
|
+
# @attribute last_release_version [rw] the version of the last release
|
53
|
+
# @example
|
54
|
+
# options = CreateGithubRelease::CommandLine::Options.new(last_release_version: '0.1.1')
|
55
|
+
# options.last_release_version #=> '0.1.1'
|
56
|
+
# @return [String]
|
57
|
+
# @api public
|
58
|
+
|
59
|
+
# @attribute next_release_version [rw] the version of the next release
|
60
|
+
# @example
|
61
|
+
# options = CreateGithubRelease::CommandLine::Options.new(next_release_version: '1.0.0')
|
62
|
+
# options.next_release_version #=> '1.0.0'
|
63
|
+
# @return [String]
|
64
|
+
# @api public
|
65
|
+
|
66
|
+
# @attribute changelog_path [rw] the path to the changelog file
|
67
|
+
# @example
|
68
|
+
# options = CreateGithubRelease::CommandLine::Options.new(changelog_path: 'CHANGELOG.md')
|
69
|
+
# options.changelog_path #=> 'CHANGELOG.md'
|
70
|
+
# @return [String]
|
71
|
+
# @api public
|
72
|
+
|
73
|
+
# @attribute quiet [rw] if `true`, suppresses all output
|
74
|
+
# @example
|
75
|
+
# options = CreateGithubRelease::CommandLine::Options.new(quiet: true)
|
76
|
+
# options.quiet #=> true
|
77
|
+
# @return [Boolean]
|
78
|
+
# @api public
|
79
|
+
|
80
|
+
# @attribute verbose [rw] if `true`, enables verbose output
|
81
|
+
# @example
|
82
|
+
# options = CreateGithubRelease::CommandLine::Options.new(verbose: true)
|
83
|
+
# options.verbose #=> true
|
84
|
+
# @return [Boolean]
|
85
|
+
# @api public
|
86
|
+
|
87
|
+
# Create a new instance of this class
|
88
|
+
#
|
89
|
+
# @example No arguments or block given
|
90
|
+
# options = CreateGithubRelease::CommandLine::Options.new
|
91
|
+
# options.release_type #=> nil
|
92
|
+
# options.valid? #=> false
|
93
|
+
# options.errors #=> ["--release-type must be given and be one of 'major', 'minor', 'patch'"]
|
94
|
+
#
|
95
|
+
# @example With keyword arguments
|
96
|
+
# config = { release_type: 'major', default_branch: 'main', quiet: true }
|
97
|
+
# options = CreateGithubRelease::CommandLine::Options.new(**config)
|
98
|
+
# options.release_type #=> 'major'
|
99
|
+
# options.default_branch #=> 'main'
|
100
|
+
# options.quiet #=> true
|
101
|
+
# options.valid? #=> true
|
102
|
+
#
|
103
|
+
# @example with a configuration block
|
104
|
+
# options = CreateGithubRelease::CommandLine::Options.new do |o|
|
105
|
+
# o.release_type = 'major'
|
106
|
+
# o.default_branch = 'main'
|
107
|
+
# o.quiet = true
|
108
|
+
# end
|
109
|
+
# options.release_type #=> 'major'
|
110
|
+
# options.default_branch #=> 'main'
|
111
|
+
# options.quiet #=> true
|
112
|
+
# options.valid? #=> true
|
113
|
+
#
|
114
|
+
# @yield [self] an initialization block
|
115
|
+
# @yieldparam self [CreateGithubRelease::CommandLine::Options] the instance being initialized
|
116
|
+
# @yieldreturn [void] the return value is ignored
|
117
|
+
#
|
118
|
+
def initialize(**options)
|
119
|
+
assert_no_unknown_options(options)
|
120
|
+
options.each { |k, v| instance_variable_set("@#{k}", v) }
|
121
|
+
|
122
|
+
self.quiet ||= false
|
123
|
+
self.verbose ||= false
|
124
|
+
self.pre ||= false
|
125
|
+
@errors = []
|
126
|
+
|
127
|
+
yield(self) if block_given?
|
128
|
+
|
129
|
+
@validator = CommandLine::Validator.new(self)
|
130
|
+
|
131
|
+
valid?
|
132
|
+
end
|
133
|
+
|
134
|
+
extend Forwardable
|
135
|
+
def_delegators :@validator, :valid?, :errors
|
136
|
+
|
137
|
+
private
|
138
|
+
|
139
|
+
# Raise ArgumentError if options has a key not in ALLOWED_OPTIONS
|
140
|
+
# @return [void]
|
141
|
+
# @api private
|
142
|
+
def assert_no_unknown_options(options)
|
143
|
+
unknown_options = options.keys - ALLOWED_OPTIONS
|
144
|
+
return if unknown_options.empty?
|
145
|
+
|
146
|
+
message = "Unknown keywords: #{unknown_options.join(', ')}"
|
147
|
+
raise ArgumentError, message
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|