Skip to content

Commit 80da449

Browse files
authored
Add support for pre-release versions (#43)
1 parent c82e1d4 commit 80da449

File tree

68 files changed

+1701
-941
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1701
-941
lines changed

.yardopts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
--hide-void-return
33
--markup-provider=redcarpet
44
--markup markdown
5+
- CHANGELOG.md
56
- LICENSE.txt

README.md

Lines changed: 156 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,46 @@
55
[![Maintainability](https://api.codeclimate.com/v1/badges/b8c0af10b15a0ffeb1a1/maintainability)](https://codeclimate.com/github/main-branch/create_github_release/maintainability)
66
[![Test Coverage](https://api.codeclimate.com/v1/badges/b8c0af10b15a0ffeb1a1/test_coverage)](https://codeclimate.com/github/main-branch/create_github_release/test_coverage)
77

8-
A script to manage your gem version and create a GitHub branch, PR, and release
9-
for a new gem version.
10-
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.
14-
15-
Tested on Ruby 2.7+
16-
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)
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)
2334
* [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)
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)
2941

3042
## Installation
3143

3244
Add `create_github_release` as a development dependency in your project's gemspec:
3345

3446
```ruby
35-
spec.add_development_dependency 'create_github_release', '~> 0.1'
47+
spec.add_development_dependency 'create_github_release'
3648
```
3749

3850
and then install using `bundle update`.
@@ -45,16 +57,18 @@ This gem installs the `create-guthub-release` command line tool:
4557
Usage:
4658
create-github-release --help | RELEASE_TYPE [options]
4759
48-
RELEASE_TYPE must be 'major', 'minor', 'patch', or 'first'
60+
RELEASE_TYPE must be 'major', 'minor', 'patch', 'pre', 'release', or 'first'
4961
5062
Options:
5163
--default-branch=BRANCH_NAME Override the default branch
5264
--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.)
5367
--remote=REMOTE_NAME Use this remote name instead of 'origin'
5468
--last-release-version=VERSION
5569
Use this version instead `semverify current`
5670
--next-release-version=VERSION
57-
Use this version instead `semverify RELEASE_TYPE`
71+
Use this version instead `semverify next-RELEASE_TYPE`
5872
--changelog-path=PATH Use this file instead of CHANGELOG.md
5973
-q, --[no-]quiet Do not show output
6074
-v, --[no-]verbose Show extra output
@@ -195,7 +209,85 @@ The `create-github-release` script will do the following:
195209
See [After running create-github-release](#after-running-create-github-release)
196210
for instructions for completing your release.
197211

198-
## After Running create-github-release
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
199291

200292
If you want to make additional updates to the ChangeLog or make changes as
201293
part of the release PR, it is best to do them before running this script. If
@@ -216,15 +308,47 @@ git push
216308
```
217309

218310
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.
220312

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.
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.
224316

225-
Finally, publish your gem to rubygems.org with the `rake release` command.
317+
Finally, publish your gem to rubygems.org with the command:
226318

227-
## How the changelog is updated
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?
228352

229353
A release description is generated by listing the commits between the last release
230354
and the next release.
@@ -266,24 +390,18 @@ The resulting updated changelog file has the following sections:
266390
2. next release description
267391
3. body (including past release descriptions)
268392

269-
## Limitations
270-
271-
* Does not work on Windows
272-
* Has only been tested on MRI Ruby
273-
*
274-
275393
## Development
276394

277395
After checking out the repo, run `bin/setup` to install dependencies. Then, run
278396
`rake spec` to run the tests. You can also run `bin/console` for an interactive
279397
prompt that will allow you to experiment.
280398

281-
To install this gem onto your local machine, run `bundle exec rake install`.
399+
To install this gem onto your current Ruby environment, run `bundle exec rake install`.
282400

283401
## Contributing
284402

285403
Bug reports and pull requests are welcome on
286-
[this project's GitHub issue tracker](https://github.com/main-branch/create_github_release)
404+
[this project's GitHub page](https://github.com/main-branch/create_github_release)
287405

288406
## License
289407

Rakefile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# The default task
44

55
desc 'Run the same tasks that the CI build will run'
6-
task default: %w[spec rubocop yard yard:audit yard:coverage solargraph:typecheck bundle:audit build]
6+
task default: %w[spec rubocop yard yard:audit yard:coverage bundle:audit build]
77

88
# Bundler Audit
99

@@ -75,12 +75,12 @@ Yardstick::Rake::Verify.new(:'yard:coverage') do |verify|
7575
verify.threshold = 100
7676
end
7777

78-
# Solargraph typecheck
78+
# # Solargraph typecheck
7979

80-
desc 'Run the solargraph type checker'
81-
task :'solargraph:typecheck' do
82-
sh 'bundle exec solargraph typecheck --level=typed'
83-
end
80+
# desc 'Run the solargraph type checker'
81+
# task :'solargraph:typecheck' do
82+
# sh 'bundle exec solargraph typecheck --level=typed'
83+
# end
8484

8585
# Additional cleanup
8686

create_github_release.gemspec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ Gem::Specification.new do |spec|
2121

2222
spec.metadata['homepage_uri'] = spec.homepage
2323
spec.metadata['source_code_uri'] = spec.homepage
24-
spec.metadata['changelog_uri'] = spec.homepage
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}"
2526

2627
# Specify which files should be added to the gem when it is released.
2728
# 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|
4243
spec.add_development_dependency 'redcarpet', '~> 3.5'
4344
spec.add_development_dependency 'rspec', '~> 3.10'
4445
spec.add_development_dependency 'rubocop', '~> 1.36'
45-
spec.add_development_dependency 'ruby-debug-ide', '~> 0.7'
4646
spec.add_development_dependency 'simplecov', '~> 0.21'
4747
spec.add_development_dependency 'simplecov-lcov', '~> 0.8'
48-
spec.add_development_dependency 'solargraph', '~> 0.49'
48+
# spec.add_development_dependency 'solargraph', '~> 0.49'
4949
spec.add_development_dependency 'timecop', '~> 0.9'
5050
spec.add_development_dependency 'yard', '~> 0.9'
5151
spec.add_development_dependency 'yardstick', '~> 0.9'

exe/create-github-release

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
require 'create_github_release'
55

6-
options = CreateGithubRelease::CommandLineParser.new.parse(*ARGV)
6+
options = CreateGithubRelease::CommandLine::Parser.new.parse(*ARGV)
77
pp options if options.verbose
88

99
project = CreateGithubRelease::Project.new(options)

lib/create_github_release.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# frozen_string_literal: true
22

33
require 'create_github_release/backtick_debug'
4-
require 'create_github_release/command_line_options'
5-
require 'create_github_release/command_line_parser'
4+
require 'create_github_release/command_line'
65
require 'create_github_release/project'
76

87
require 'create_github_release/change'

lib/create_github_release/assertions/bundle_is_up_to_date.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class BundleIsUpToDate < AssertionBase
1717
# @example
1818
# require 'create_github_release'
1919
#
20-
# options = CreateGithubRelease::CommandLineOptions.new { |o| o.release_type = 'major' }
20+
# options = CreateGithubRelease::CommandLine::Options.new { |o| o.release_type = 'major' }
2121
# project = CreateGithubRelease::Project.new(options)
2222
# assertion = CreateGithubRelease::Assertions::BundleIsUpToDate.new(project)
2323
# begin

lib/create_github_release/assertions/gh_authenticated.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class GhAuthenticated < AssertionBase
1515
# @example
1616
# require 'create_github_release'
1717
#
18-
# options = CreateGithubRelease::CommandLineOptions.new { |o| o.release_type = 'major' }
18+
# options = CreateGithubRelease::CommandLine::Options.new { |o| o.release_type = 'major' }
1919
# project = CreateGithubRelease::Project.new(options)
2020
# assertion = CreateGithubRelease::Assertions::GhAuthenticated.new(project)
2121
# begin

lib/create_github_release/assertions/gh_command_exists.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class GhCommandExists < AssertionBase
1515
# @example
1616
# require 'create_github_release'
1717
#
18-
# options = CreateGithubRelease::CommandLineOptions.new { |o| o.release_type = 'major' }
18+
# options = CreateGithubRelease::CommandLine::Options.new { |o| o.release_type = 'major' }
1919
# project = CreateGithubRelease::Project.new(options)
2020
# assertion = CreateGithubRelease::Assertions::GhCommandExists.new(project)
2121
# begin

lib/create_github_release/assertions/git_command_exists.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class GitCommandExists < AssertionBase
1515
# @example
1616
# require 'create_github_release'
1717
#
18-
# options = CreateGithubRelease::CommandLineOptions.new { |o| o.release_type = 'major' }
18+
# options = CreateGithubRelease::CommandLine::Options.new { |o| o.release_type = 'major' }
1919
# project = CreateGithubRelease::Project.new(options)
2020
# assertion = CreateGithubRelease::Assertions::GitCommandExists.new(project)
2121
# begin

0 commit comments

Comments
 (0)