|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +# Used constants: |
| 4 | +# - BUILD_DIR |
| 5 | + |
| 6 | +def first_match_in_file(file, regexp) |
| 7 | + File.foreach(file) do |line| |
| 8 | + m = regexp.match(line) |
| 9 | + return m if m |
| 10 | + end |
| 11 | +end |
| 12 | + |
| 13 | +## [ Release a new version ] ################################################## |
| 14 | + |
| 15 | +namespace :release do |
| 16 | + desc 'Create a new release' |
| 17 | + task :new => [:check_versions, :confirm, 'spm:test_command', :github] |
| 18 | + |
| 19 | + desc 'Check if all versions from the podspecs and CHANGELOG match' |
| 20 | + task :check_versions do |
| 21 | + results = [] |
| 22 | + |
| 23 | + # Check if bundler is installed first, as we'll need it for the cocoapods task (and we prefer to fail early) |
| 24 | + `which bundler` |
| 25 | + results << Utils.table_result( |
| 26 | + $CHILD_STATUS.success?, |
| 27 | + 'Bundler installed', |
| 28 | + 'Please install bundler using `gem install bundler` and run `bundle install` first.' |
| 29 | + ) |
| 30 | + changelog_has_stable = system("grep -qi '^## Stable Branch' CHANGELOG.md") |
| 31 | + results << Utils.table_result( |
| 32 | + !changelog_has_stable, |
| 33 | + 'CHANGELOG, No stable', |
| 34 | + 'Please remove section for stable branch in CHANGELOG' |
| 35 | + ) |
| 36 | + |
| 37 | + exit 1 unless results.all? |
| 38 | + end |
| 39 | + |
| 40 | + desc "Ask to release" |
| 41 | + task :confirm do |
| 42 | + print "Release version new version [Y/n]? " |
| 43 | + exit 2 unless STDIN.gets.chomp == 'Y' |
| 44 | + end |
| 45 | + |
| 46 | + desc "Create a new GitHub release" |
| 47 | + task :github do |
| 48 | + require 'octokit' |
| 49 | + |
| 50 | + client = Utils.octokit_client |
| 51 | + tag = Utils.top_changelog_version |
| 52 | + body = Utils.top_changelog_entry |
| 53 | + |
| 54 | + raise 'Must be a valid version' if tag == 'Stable Branch' |
| 55 | + |
| 56 | + repo_name = File.basename(`git remote get-url origin`.chomp, '.git').freeze |
| 57 | + puts "Pushing release notes for tag #{tag}" |
| 58 | + client.create_release("SwiftGen/#{repo_name}", tag, name: tag, body: body) |
| 59 | + end |
| 60 | +end |
0 commit comments