Copy & adapt rake infrastructure from swiftgen projects

This commit is contained in:
David Jennes
2022-07-27 02:10:45 +02:00
parent d18e27d6e4
commit d9a48fbda6
15 changed files with 821 additions and 163 deletions

View File

@@ -1,67 +1,95 @@
# frozen_string_literal: true
# Used constants:
# - BUILD_DIR
require 'json'
namespace :release do
desc 'Create a new release'
task :new => [:check_versions, :check_tag_and_ask_to_release, 'spm:test', :github, :cocoapods]
# rake release:new
desc "Ask for a version number and prepare a release PR for that version"
task :new do
info "Current version is: #{current_pod_version}"
print "What version do you want to release? "
new_version = STDIN.gets.chomp
desc 'Check if all versions from the podspecs and CHANGELOG match'
task :check_versions do
results = []
Rake::Task['release:start'].invoke(new_version)
end
# rake release:start[version]
desc "Start a release by creating a PR with the required changes to bump the version"
task :start, [:version] => ['release:create_branch', 'release:update_files', 'pod:lint', 'release:push_branch', 'github:create_release_pr', 'github:pull_master']
# rake release:finish[version]
desc "Finish a release after the PR has been merged, by tagging master and pushing to trunk"
task :finish => ['github:pull_master', 'github:tag', 'pod:push', 'github:create_release', 'changelog:reset']
### Helper tasks ###
# rake release:create_branch[version]
task :create_branch, [:version] do |_, args|
branch = release_branch(args[:version])
header "Creating release branch"
sh("git", "checkout", "-b", branch)
end
# rake release:update_files[version]
task :update_files, [:version] do |_, args|
version = args[:version]
header "Updating files for version #{version}"
podspec = JSON.parse(File.read(PODSPEC_FILE))
podspec['version'] = version
podspec['source']['tag'] = version
File.write(PODSPEC_FILE, JSON.pretty_generate(podspec) + "\n")
replace(CHANGELOG_FILE, '## Master' => "\#\# #{version}")
replace("docs/conf.py",
/^version = .*/ => %Q(version = '#{version}'),
/^release = .*/ => %Q(release = '#{version}')
)
replace("docs/installation.rst",
/pod 'Stencil', '.*'/ => %Q(pod 'Stencil', '~> #{version}'),
/github "stencilproject\/Stencil" ~> .*/ => %Q(github "stencilproject/Stencil" ~> #{version})
# Check if bundler is installed first, as we'll need it for the cocoapods task (and we prefer to fail early)
`which bundler`
results << Utils.table_result(
$CHILD_STATUS.success?,
'Bundler installed',
'Install bundler using `gem install bundler` and run `bundle install` first.'
)
## Commit Changes
sh("git", "add", PODSPEC_FILE, CHANGELOG_FILE, "docs/*")
sh("git", "commit", "-m", "Version #{version}")
# Extract version from podspec
podspec = Utils::podspec(POD_NAME)
v = podspec['version']
Utils.table_info("#{POD_NAME}.podspec", v)
# Check podspec tag
podspec_tag = podspec['source']['tag']
results << Utils.table_result(podspec_tag == v, 'Podspec version & tag equal', 'Update the `tag` in podspec')
# Check docs config
docs_version = Utils.first_match_in_file('docs/conf.py', /version = '(.+)'/, 1)
docs_release = Utils.first_match_in_file('docs/conf.py', /release = '(.+)'/, 1)
results << Utils.table_result(docs_version == v,'Docs, version updated', 'Update the `version` in docs/conf.py')
results << Utils.table_result(docs_release == v, 'Docs, release updated', 'Update the `release` in docs/conf.py')
# Check docs installation
docs_package = Utils.first_match_in_file('docs/installation.rst', /\.package\(url: .+ from: "(.+)"/, 1)
docs_cocoapods = Utils.first_match_in_file('docs/installation.rst', /pod 'Stencil', '~> (.+)'/, 1)
docs_carthage = Utils.first_match_in_file('docs/installation.rst', /github ".+\/Stencil" ~> (.+)/, 1)
results << Utils.table_result(docs_package == v, 'Docs, package updated', 'Update the package version in docs/installation.rst')
results << Utils.table_result(docs_cocoapods == v, 'Docs, cocoapods updated', 'Update the cocoapods version in docs/installation.rst')
results << Utils.table_result(docs_carthage == v, 'Docs, carthage updated', 'Update the carthage version in docs/installation.rst')
# Check if entry present in CHANGELOG
changelog_entry = Utils.first_match_in_file('CHANGELOG.md', /^## #{Regexp.quote(v)}$/)
results << Utils.table_result(changelog_entry, 'CHANGELOG, Entry added', "Add an entry for #{v} in CHANGELOG.md")
changelog_has_stable = system("grep -qi '^## Master' CHANGELOG.md")
results << Utils.table_result(!changelog_has_stable, 'CHANGELOG, No master', 'Remove section for master branch in CHANGELOG')
exit 1 unless results.all?
end
# rake release:push_branch[version]
task :push_branch, [:version] do |_, args|
branch = release_branch(args[:version])
desc "Check tag and ask to release"
task :check_tag_and_ask_to_release do
results = []
podspec_version = Utils.podspec_version(POD_NAME)
header "Pushing #{branch} to origin"
sh("git", "push", "-u", "origin", branch)
tag_set = !`git ls-remote --tags . refs/tags/#{podspec_version}`.empty?
results << Utils.table_result(
tag_set,
'Tag pushed',
'Please create a tag and push it'
)
exit 1 unless results.all?
print "Release version #{podspec_version} [Y/n]? "
exit 2 unless STDIN.gets.chomp == 'Y'
end
desc "Create a new GitHub release"
task :github do
require 'octokit'
client = Utils.octokit_client
tag = Utils.top_changelog_version
body = Utils.top_changelog_entry
raise 'Must be a valid version' if tag == 'Master'
repo_name = File.basename(`git remote get-url origin`.chomp, '.git').freeze
puts "Pushing release notes for tag #{tag}"
client.create_release("stencilproject/#{repo_name}", tag, name: tag, body: body)
end
desc "pod trunk push #{POD_NAME} to CocoaPods"
task :cocoapods do
Utils.print_header 'Pushing pod to CocoaPods Trunk'
sh "bundle exec pod trunk push #{POD_NAME}.podspec.json"
end
end