forked from puppetlabs/ruby-pwsh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
100 lines (87 loc) · 3.18 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# frozen_string_literal: true
require 'rubocop/rake_task'
require 'fileutils'
require 'github_changelog_generator/task'
require 'open3'
require 'pwsh/version'
require 'rspec/core/rake_task'
require 'yard'
GitHubChangelogGenerator::RakeTask.new :changelog do |config|
config.user = 'puppetlabs'
config.project = 'ruby-pwsh'
config.future_release = Pwsh::VERSION
config.since_tag = '0.1.0'
config.exclude_labels = ['maint']
config.header = "# Change log\n\nAll notable changes to this project will be documented in this file." \
'The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org).'
config.add_pr_wo_labels = true
config.issues = false
config.merge_prefix = '### UNCATEGORIZED PRS; GO LABEL THEM'
config.configure_sections = {
'Changed' => {
'prefix' => '### Changed',
'labels' => %w[backwards-incompatible]
},
'Added' => {
'prefix' => '### Added',
'labels' => %w[feature enhancement]
},
'Fixed' => {
'prefix' => '### Fixed',
'labels' => %w[bugfix]
}
}
end
RuboCop::RakeTask.new(:rubocop) do |task|
task.options = %w[-D -S -E]
end
RSpec::Core::RakeTask.new(:spec)
task default: :spec
YARD::Rake::YardocTask.new do |t|
end
# Executes a command locally.
#
# @param command [String] command to execute.
# @return [Object] the standard out stream.
def run_local_command(command)
stdout, stderr, status = Open3.capture3(command)
error_message = "Attempted to run\ncommand:'#{command}'\nstdout:#{stdout}\nstderr:#{stderr}"
raise error_message unless status.to_i.zero?
stdout
end
# Build the gem
desc 'Build the gem'
task :build do
gemspec_path = File.join(Dir.pwd, 'ruby-pwsh.gemspec')
run_local_command("bundle exec gem build '#{gemspec_path}'")
end
# Tag the repo with a version in preparation for the release
#
# @param :version [String] a semantic version to tag the code with
# @param :sha [String] the sha at which to apply the version tag
desc 'Tag the repo with a version in preparation for release'
task :tag, [:version, :sha] do |_task, args|
raise "Invalid version #{args[:version]} - must be like '1.2.3'" unless args[:version] =~ /^\d+\.\d+\.\d+$/
run_local_command('git fetch upstream')
run_local_command("git tag -a #{args[:version]} -m #{args[:version]} #{args[:sha]}")
run_local_command('git push upstream --tags')
end
# Push the built gem to RubyGems
#
# @param :path [String] optional, the full or relative path to the built gem to be pushed
desc 'Push to RubyGems'
task :push, [:path] do |_task, args|
raise 'No discoverable gem for pushing' if Dir.glob("ruby-pwsh*\.gem").empty? && args[:path].nil?
raise "No file found at specified path: '#{args[:path]}'" unless File.exist?(args[:path])
path = args[:path] || File.join(Dir.pwd, Dir.glob("ruby-pwsh*\.gem")[0])
run_local_command("bundle exec gem push #{path}")
end
desc 'Build for Puppet'
task :build_module do
actual_readme_content = File.read('README.md')
FileUtils.copy_file('pwshlib.md', 'README.md')
# Build
run_local_command('pdk build --force')
# Cleanup
File.open('README.md', 'wb') { |file| file.write(actual_readme_content) }
end