Skip to content

Commit

Permalink
Automatic version update
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidBakerEffendi committed Oct 7, 2024
1 parent 60573c5 commit 893ba5e
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ jobs:
echo "The next tag version will be: $NEW_TAG"
echo "The current tag is: $CURR_TAG"
- name: Add and commit updated VERSION file
env:
NEW_TAG: ${{ steps.taggerDryRun.outputs.new_tag }}
run: |
./update_version.rb $NEW_TAG
git config --global user.name "GitHub Action"
git config --global user.email "[email protected]"
git add lib/ruby_ast_gen/version.rb
git commit -m "Update VERSION file to $NEW_TAG"
git push
- name: Upload vendored distribution to GitHub Release
uses: softprops/action-gh-release@v2
env:
Expand Down
36 changes: 36 additions & 0 deletions update_version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env ruby

# Script to update the version in `lib/ruby_ast_gen/version.rb`
require 'fileutils'

VERSION_FILE_PATH = 'lib/ruby_ast_gen/version.rb'


if ARGV.empty?
puts "Usage: update_version.rb <new_version>"
exit 1
end

new_version = ARGV[0]
unless new_version.match?(/^v\d+\.\d+\.\d+$/)
puts "Invalid version format. Please provide a version in the format 'vX.X.X' (e.g., v1.0.0)."
exit 1
end
stripped_version = new_version.gsub(/^v/, '')

begin
contents = File.read(VERSION_FILE_PATH)
rescue Errno::ENOENT
puts "Error: Couldn't find the version file at #{VERSION_FILE_PATH}"
exit 1
end

new_contents = contents.gsub(/VERSION\s*=\s*["']\d+\.\d+\.\d+["']/, "VERSION = \"#{stripped_version}\"")

begin
File.write(VERSION_FILE_PATH, new_contents)
puts "Successfully updated version to #{stripped_version} in #{VERSION_FILE_PATH}"
rescue Errno::EACCES
puts "Error: Insufficient permissions to update #{VERSION_FILE_PATH}"
exit 1
end

0 comments on commit 893ba5e

Please sign in to comment.