Skip to content

Commit

Permalink
Create bin/release script (#16)
Browse files Browse the repository at this point in the history
* Created bin/release script

* Update lib/edusign/version.rb through bin/release task

* Commit change to version on master
  • Loading branch information
grmnlrt authored Jan 30, 2024
1 parent ec2a9b0 commit ebfd6f4
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions bin/release
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env ruby
require 'json'

SEMVER_PATTERN = /^(?<major>0|[1-9]\d*)\.(?<minor>0|[1-9]\d*)\.(?<patch>0|[1-9]\d*)(?:-(?<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/m
version = ""

unless `git branch --show-current`.strip == 'master'
puts "⚠️ You must be on master to run bin/release script"
return
end

unless `git status`.match?(/nothing to commit, working tree clean/)
puts "⚠️ Your git status must be clean to run bin/release script"
return
end

system "git pull origin master"
puts "You're about to deploy a new version of Edusign gem"
puts "Before proceeding, check out `master`'s last commit"
system "gh browse $(git rev-parse HEAD)"
puts "Is the CI green? (y/n)"
print "> "
continue = gets.chomp
return unless continue == "y"

until version.match?(SEMVER_PATTERN)
puts "Not a correct version number. Version number must follow the semver pattern. See https://semver.org/." unless version.empty?
puts ""
puts "Previous version released:"
system "gh release list --limit 1 --repo lewagon/edusign | awk '{print $1}'"
puts ""
puts "Which version number do you want to release?"
print "> "
version = gets.chomp
end

puts "Release version v#{version}"
gem_version_path = File.join(File.dirname(__FILE__), "../lib/edusign/version.rb")
file_lines = File.open(gem_version_path, "r").readlines
file_lines[3] = " VERSION = \"#{version}\"\n"
File.open(gem_version_path, "wb") {|file| file.write(file_lines.join) }
puts "Commit changes on GitHub"
system "git add ../lib/edusign/version.rb"
system "git commit -m 'Commit v#{version}'"
puts "Push to master"
system "git push origin master"
puts "Create tag and release on GitHub"
system "git tag v#{version}"
system "git push origin v#{version}"
system "gh release create v#{version} --generate-notes"

puts "Version v#{version} released! 🎉"

0 comments on commit ebfd6f4

Please sign in to comment.