Skip to content

Commit 0f739d4

Browse files
committed
Add rake release task for creating GitHub releases
1 parent 8ada7e7 commit 0f739d4

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

Rakefile

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,42 @@ task :bump_major do
4545
Rake::Task["changes"].invoke
4646
end
4747

48+
desc "Create a GitHub release for the current version"
49+
task :release do
50+
version = read_version.join('.')
51+
tag = "v#{version}"
52+
53+
# Ensure we're on a clean working tree
54+
unless system("git diff --quiet HEAD")
55+
abort "ERROR: Working tree is dirty. Commit or stash changes before releasing."
56+
end
57+
58+
# Create and push the tag if it doesn't exist
59+
if system("git rev-parse #{tag} >/dev/null 2>&1")
60+
puts "Tag #{tag} already exists."
61+
else
62+
system("git tag -a #{tag} -m 'Release #{tag}'") || abort("Failed to create tag")
63+
system("git push origin #{tag}") || abort("Failed to push tag")
64+
end
65+
66+
# Extract the latest changelog entry for release notes
67+
changelog = File.read("#{PROJECT_ROOT}/CHANGELOG").to_s
68+
# Grab everything from the current version header to the next version header
69+
notes = changelog[/^\*#{Regexp.escape(version)}\*.*?(?=^\*\d+\.\d+\.\d+\*|\z)/m].to_s.strip
70+
71+
# Create the GitHub release
72+
if notes.empty?
73+
system("gh release create #{tag} --title '#{tag}' --generate-notes") || abort("Failed to create release")
74+
else
75+
IO.popen(["gh", "release", "create", tag, "--title", tag, "--notes-file", "-"], "w") do |io|
76+
io.write(notes)
77+
end
78+
abort("Failed to create release") unless $?.success?
79+
end
80+
81+
puts "Released #{tag} on GitHub."
82+
end
83+
4884
desc "Open the github site in your browser"
4985
task :github do
5086
system("open https://github.com/midwire/.env")

0 commit comments

Comments
 (0)