Skip to content

Commit c7bd12d

Browse files
authored
Complete redesign of this gem (#28)
1 parent d75e1e9 commit c7bd12d

File tree

78 files changed

+3254
-1593
lines changed

Some content is hidden

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

78 files changed

+3254
-1593
lines changed

.vscode/settings.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2022 James Couball
3+
Copyright (c) 2023 James Couball
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,40 @@
77

88
Create a GitHub release for a new gem version.
99

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:
12-
13-
```shell
14-
create-github-release [major|minor|patch]
10+
The `create-github-release` script does the following:
11+
12+
* Bumps the project's version
13+
* Updates the project's changelog
14+
* Creates a release branch
15+
* Commits the version change and changelog update
16+
* Creates a version tag
17+
* Pushes the release branch to GitHub
18+
* Creates a GitHub release and GitHub pull request for the release
19+
20+
You should merge the pull request once it is reviewed and approved.
21+
22+
Pull the changes from the default branch and publish your gem with the `rake release` command.
23+
24+
Here is the command line --help output:
25+
26+
```text
27+
Usage:
28+
create-github-release --help | RELEASE_TYPE [options]
29+
30+
RELEASE_TYPE must be 'major', 'minor', or 'patch'
31+
32+
Options:
33+
--default-branch=BRANCH_NAME Override the default branch
34+
--release-branch=BRANCH_NAME Override the release branch to create
35+
--remote=REMOTE_NAME Use this remote name instead of 'origin'
36+
--last-release-version=VERSION
37+
Use this version instead `bump current`
38+
--next-release-version=VERSION
39+
Use this version instead `bump RELEASE_TYPE`
40+
--changelog-path=PATH Use this file instead of CHANGELOG.md
41+
-q, --[no-]quiet Do not show output
42+
-v, --[no-]verbose Show extra output
43+
-h, --help Show this message
1544
```
1645

1746
The following conditions must be met in order to create a release:
@@ -21,21 +50,11 @@ The following conditions must be met in order to create a release:
2150
* The default branch must be checked out
2251
* There are no uncommitted changes
2352
* The local and remote must be on the same commit
53+
* The last release tag must exist
2454
* The new release tag must not already exist either locally or remotely
2555
* 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
2856
* The gh command must be installed
2957

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
38-
3958
## Installation
4059

4160
Add `create_github_release` as a development dependency in your project's gemspec:
@@ -52,11 +71,7 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
5271
`rake spec` to run the tests. You can also run `bin/console` for an interactive
5372
prompt that will allow you to experiment.
5473

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).
74+
To install this gem onto your local machine, run `bundle exec rake install`.
6075

6176
## Contributing
6277

create_github_release.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Gem::Specification.new do |spec|
4040
spec.add_development_dependency 'simplecov', '~> 0.21'
4141
spec.add_development_dependency 'simplecov-lcov', '~> 0.8'
4242
spec.add_development_dependency 'solargraph', '~> 0.47'
43+
spec.add_development_dependency 'timecop', '~> 0.9'
4344
spec.add_development_dependency 'yard', '~> 0.9'
4445
spec.add_development_dependency 'yardstick', '~> 0.9'
4546

exe/create-github-release

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,24 @@
33

44
require 'create_github_release'
55

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
812
puts unless options.quiet
9-
CreateGithubRelease::ReleaseTasks.new(options).run
13+
CreateGithubRelease::ReleaseTasks.new(project).run
1014

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}
1418
1519
Next steps:
1620
* Get someone to review and approve the release pull request
1721
* Merge the pull request manually from the command line with the following commands:
1822
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}
2125
git push
2226
MESSAGE

lib/create_github_release.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# frozen_string_literal: true
22

3+
require 'create_github_release/backtick_debug'
4+
require 'create_github_release/command_line_options'
35
require 'create_github_release/command_line_parser'
6+
require 'create_github_release/project'
47

8+
require 'create_github_release/change'
59
require 'create_github_release/changelog'
6-
require 'create_github_release/options'
7-
require 'create_github_release/release'
810

911
require 'create_github_release/assertion_base'
1012
require 'create_github_release/assertions'

lib/create_github_release/assertion_base.rb

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@ module CreateGithubRelease
99
# @api private
1010
#
1111
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
1414
# @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
1720
end
1821

1922
# This method must be overriden by a subclass
@@ -29,25 +32,25 @@ def assert
2932

3033
# @!attribute [r] options
3134
#
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
3437
# @api private
35-
attr_reader :options
38+
attr_reader :project
3639

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`
3841
# @param args [Array] the arguments to pass to `Kernel.print`
3942
# @return [void]
4043
# @api private
4144
def print(*args)
42-
super unless options.quiet
45+
super unless project.quiet?
4346
end
4447

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`
4649
# @param args [Array] the arguments to pass to `Kernel.puts`
4750
# @return [void]
4851
# @api private
4952
def puts(*args)
50-
super unless options.quiet
53+
super unless project.quiet?
5154
end
5255

5356
# Writes a message to stderr and exits with exitcode 1
@@ -58,5 +61,16 @@ def error(message)
5861
warn "ERROR: #{message}"
5962
exit 1
6063
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
6175
end
6276
end

lib/create_github_release/assertions.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ module Assertions; end
99
end
1010

1111
require_relative 'assertions/bundle_is_up_to_date'
12-
require_relative 'assertions/changelog_docker_container_exists'
13-
require_relative 'assertions/docker_is_running'
1412
require_relative 'assertions/gh_command_exists'
1513
require_relative 'assertions/git_command_exists'
1614
require_relative 'assertions/in_git_repo'
1715
require_relative 'assertions/in_repo_root_directory'
16+
require_relative 'assertions/last_release_tag_exists'
1817
require_relative 'assertions/local_and_remote_on_same_commit'
1918
require_relative 'assertions/local_release_branch_does_not_exist'
2019
require_relative 'assertions/local_release_tag_does_not_exist'

lib/create_github_release/assertions/bundle_is_up_to_date.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
module CreateGithubRelease
77
module Assertions
8-
# Assert that options.branch does not exist
8+
# Assert that project.release+branch does not exist
99
#
1010
# Checks both the local repository and the remote repository.
1111
#
@@ -17,8 +17,9 @@ class BundleIsUpToDate < AssertionBase
1717
# @example
1818
# require 'create_github_release'
1919
#
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)
2223
# begin
2324
# assertion.assert
2425
# puts 'Assertion passed'

lib/create_github_release/assertions/changelog_docker_container_exists.rb

Lines changed: 0 additions & 73 deletions
This file was deleted.

0 commit comments

Comments
 (0)