Skip to content

Commit

Permalink
Add a release rake task
Browse files Browse the repository at this point in the history
Bumps the version, updates the changelog, tags, builds and
pushes the gem to rubygems.org
  • Loading branch information
tvdeyen committed Nov 18, 2024
1 parent 112dd63 commit 72279e3
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gem_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bump:
file: lib/alchemy/version.rb
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,5 @@ gem "web-console", "~> 4.2", group: :development
gem "rails_live_reload", "~> 0.3.5"

gem "dartsass-rails", "~> 0.5.0"

gem "gem-release", "~> 2.2"
29 changes: 25 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -339,24 +339,45 @@ $ bin/start

## 📦 Releasing

### Bump version
### 🤖 Automated (recommended)

There is a Rake task that helps you to release a new version of Alchemy.

```bash
$ bundle exec rake alchemy:release
```

> [!NOTE]
> This will release a new patch level
If you want to release a new minor or major version you can do so by setting the `VERSION` environment variable accordingly.

```bash
$ bundle exec rake alchemy:release VERSION=X.Y.Z
```

### 👷🏽‍♀️ Manual

If something goes wrong with the automated release task you can still release a new version manually.

#### 1. Bump version

Bump the version number in `lib/alchemy/version.rb`.

### Update the changelog
#### 2. Update the changelog

```bash
$ export GITHUB_ACCESS_TOKEN=...
$ PREVIOUS_VERSION=4.1.0 bundle exec rake alchemy:changelog:update
```

### Commit version bump
#### 3. Commit version bump

```bash
$ git commit -am "Bump version to vX.Y.Z"
```

### Release a new version
#### 4. Release a new version

This task will publish the ruby gem.
It also tags the latest commit.
Expand Down
20 changes: 20 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,16 @@ namespace :alchemy do
changes = `git rev-list v#{ENV["PREVIOUS_VERSION"]}..HEAD | bundle exec github_fast_changelog AlchemyCMS/alchemy_cms`.split("\n")
changelog = File.read(original_file)
File.open(new_file, "w") do |file|
file.puts "# Changelog"
file.puts ""
file.puts "## Unreleased"
file.puts ""
changes.each do |change|
next if changelog.include?(change)
file.puts change
end
File.foreach(original_file) do |line|
next if line.include?("# Changelog")
file.puts line
end
file.puts ""
Expand All @@ -77,4 +82,19 @@ namespace :alchemy do
File.delete(backup)
end
end

desc "Release a new version of Alchemy to rubygems.org"
task :release do
require_relative "lib/alchemy/version"
ENV["PREVIOUS_VERSION"] = Alchemy::VERSION
system("bundle exec gem bump --version #{ENV.fetch("VERSION", "patch")}")
load "./lib/alchemy/version.rb"
new_version = Alchemy::VERSION
Rake::Task["alchemy:changelog:update"].invoke
changelog = File.read("CHANGELOG.md").gsub(/(##) Unreleased/, "## #{new_version} (#{Time.now.strftime("%Y-%m-%d")})")
File.open("CHANGELOG.md", "w") { |file| file.puts changelog }
system("git add CHANGELOG.md")
system("git commit --amend --no-edit")
Rake::Task["release"].invoke
end
end

0 comments on commit 72279e3

Please sign in to comment.