-
Notifications
You must be signed in to change notification settings - Fork 35
/
Rakefile
180 lines (167 loc) · 5.4 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# frozen_string_literal: true
require 'rubygems'
require 'bundler'
begin
Bundler.setup(:default, :development)
rescue Bundler::BundlerError => e
warn e.message
warn 'Run `bundle install` to install missing gems'
exit e.status_code
end
require 'algoliasearch'
require 'rake'
require 'rspec/core'
require 'rspec/core/rake_task'
require 'rubocop/rake_task'
# LINT
desc 'Check files for linting issues'
RuboCop::RakeTask.new(:lint) do |task|
task.patterns = [
'lib/**/*.rb',
'spec/**/*.rb'
]
task.options = [
'--display-cop-names',
'--force-exclusion' # Some files are excluded in .rubocop.yml
]
end
# TEST
desc 'Run unit tests'
RSpec::Core::RakeTask.new(:test) do |task|
task.rspec_opts = '--color --format progress'
task.pattern = [
'spec/*.rb',
'spec/jekyll/**/*.rb'
]
end
namespace 'test' do
desc 'Run tests in all Ruby versions'
task :all_ruby_versions do
puts 'Please, run ./scripts/test_all_ruby_versions manually'
end
# Generate locally browsable coverage files
task :coverage do
ENV['COVERAGE'] = 'true'
Rake::Task['test'].execute
end
desc 'Live-reload unit tests'
task :watch do
# We specifically watch for ./lib and ./spec and not the whole dir because:
# 1. It's the only directories we are interested in
# 2. Listening to the whole parent dir might throw Guard errors if we have
# symlink
sh 'bundle exec guard --clear --watchdir lib spec'
end
# Integration tests need to run `bundle exec jekyll build/algolia`. Using
# bundle from inside a Rakefile does not seem to work, so the scripts have to
# be run manually. Each script run the needed commands to prepare the test
# site, then actually run the _run and _watch_run tasks below.
desc 'Run integration tests'
task :integration do
puts 'Please, run ./scripts/test_integration manually'
end
namespace 'integration' do
desc 'Live-reload integration tests'
task :watch do
puts 'Please, run ./scripts/test_integration_watch manually'
end
# Delete the test indices
task :_delete_indices do
Algolia.init(
application_id: ENV['ALGOLIA_APPLICATION_ID'],
api_key: ENV['ALGOLIA_API_KEY']
)
Algolia::Index.new(ENV['ALGOLIA_INDEX_NAME']).delete_index!
Algolia::Index
.new("#{ENV['ALGOLIA_INDEX_NAME']}_object_ids").delete_index!
end
# Run only the integration tests
desc ''
RSpec::Core::RakeTask.new(:_run) do |task|
task.rspec_opts = '--color --format progress'
task.pattern = [
# Check that the default build has the expected results
'spec/integration/main_spec.rb',
# Check various config and its impact on the settings
'spec/integration/settings_spec.rb',
# Check that object ids are stored in dedicated index
'spec/integration/object_ids_spec.rb'
]
end
# Live-reloading integration tests
# It will reload the tests whenever they are changed. It will not
# live-rebuild everything, you still have to run rake
# ./scripts/test_integration_prepare for that
task :_watch_run do
sh 'bundle exec guard '\
'--clear '\
'--watchdir lib spec/integration '\
'--guardfile Guardfile_integration'
end
end
end
task watch: 'test:watch'
# GEM RELEASE
desc 'Release a new version of the gem'
task release: %i[lint test] do
Rake::Task['release:update_develop_from_master'].invoke
Rake::Task['release:update_version'].invoke
Rake::Task['release:build'].invoke
Rake::Task['release:push'].invoke
Rake::Task['release:update_master_from_develop'].invoke
end
namespace 'release' do
# Getting up to date from master
task :update_develop_from_master do
sh 'git checkout master --quiet'
sh 'git pull --rebase origin master --quiet'
sh 'git checkout develop --quiet'
sh 'git rebase master --quiet'
end
# Update current version
task :update_version do
version_file_path = 'lib/jekyll/algolia/version.rb'
require_relative version_file_path
# Ask for new version
old_version = Jekyll::Algolia::VERSION.to_s
puts "Current version is #{old_version}"
puts 'Enter new version:'
new_version = STDIN.gets.strip
# Write it to file
version_file_content = File.open(version_file_path, 'rb').read
version_file_content.gsub!(old_version, new_version)
File.write(version_file_path, version_file_content)
# Commit it in git
sh "git commit -a -m 'release #{new_version}'"
# Create the git tag
last_tag = `git describe --tags --abbrev=0`.strip
changelog = `git log #{last_tag}..HEAD --format=%B`.gsub("\n\n", "\n")
tag_name = new_version
sh 'git tag '\
"-a #{tag_name} "\
"-m \"#{changelog}\""\
' 2>/dev/null'
sh "git tag #{tag_name} #{tag_name} -f -a"
end
# Build the gem
task :build do
sh 'bundle install'
sh 'gem build jekyll-algolia.gemspec'
end
# Push the gem to rubygems
task :push do
# This will throw a warning because we're redefining a constant. That's ok.
load 'lib/jekyll/algolia/version.rb'
current_version = Jekyll::Algolia::VERSION.to_s
sh "gem push jekyll-algolia-#{current_version}.gem"
sh "rm jekyll-algolia-#{current_version}.gem"
sh "git push origin #{current_version}"
end
# Update master
task :update_master_from_develop do
sh 'git checkout master --quiet'
sh 'git rebase develop --quiet'
sh 'git checkout develop --quiet'
end
end
task default: :test