Skip to content

Commit ce34c86

Browse files
author
Uğur Özyılmazel
committed
Add builder tasks
1 parent aee8ecb commit ce34c86

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,6 @@
2222
/vendor/
2323
/Godeps/
2424

25+
build/
26+
2527
# End of https://www.toptal.com/developers/gitignore/api/go

Rakefile

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,46 @@ task :publish, [:revision] do |_, args|
8585
system "git push origin #{current_branch}"
8686
puts "-> all complete!"
8787
end
88+
89+
BUILD_OPTIONS = {
90+
windows: ['386', 'amd64'],
91+
linux: ['386', 'amd64'],
92+
macos: ['amd64'],
93+
}
94+
95+
namespace :build do
96+
task :do, [:goos, :goarch, :target] do |_, args|
97+
rm_rf %w(build)
98+
system %{
99+
cd cmd/scraper-cli &&
100+
GOOS="#{args.goos}" GOARCH="#{args.goarch}" go build -o ../../build/#{args.target}
101+
}
102+
puts "-> build completed: build/#{args.target}"
103+
end
104+
105+
desc "Build for Windows, available architecture(s): #{BUILD_OPTIONS[:windows].join(',')} default: #{BUILD_OPTIONS[:windows][1]}"
106+
task :windows, [:arch] do |_, args|
107+
args.with_defaults(arch: BUILD_OPTIONS[:windows][1])
108+
109+
abort "Please provide valid arch: #{BUILD_OPTIONS[:windows].join(',')}" unless BUILD_OPTIONS[:windows].include?(args.arch)
110+
Rake::Task["build:do"].invoke("windows", args.arch, "scraper-cli-#{args.arch}.exe")
111+
end
112+
113+
desc "Build for Linux, available architecture(s): #{BUILD_OPTIONS[:linux].join(',')} default: #{BUILD_OPTIONS[:linux][1]}"
114+
task :linux, [:arch] do |_, args|
115+
args.with_defaults(arch: BUILD_OPTIONS[:linux][1])
116+
117+
abort "Please provide valid arch: #{BUILD_OPTIONS[:linux].join(',')}" unless BUILD_OPTIONS[:linux].include?(args.arch)
118+
Rake::Task["build:do"].invoke("linux", args.arch, "scraper-cli-linux-#{args.arch}")
119+
end
120+
121+
desc "Build for macOS, available architecture(s): #{BUILD_OPTIONS[:macos].join(',')} default: #{BUILD_OPTIONS[:macos][0]}"
122+
task :macos, [:arch] do |_, args|
123+
args.with_defaults(arch: BUILD_OPTIONS[:macos][0])
124+
125+
abort "Please provide valid arch: #{BUILD_OPTIONS[:macos].join(',')}" unless BUILD_OPTIONS[:macos].include?(args.arch)
126+
Rake::Task["build:do"].invoke("darwin", args.arch, "scraper-cli-macos-#{args.arch}")
127+
end
128+
129+
end
88130
# -----------------------------------------------------------------------------

0 commit comments

Comments
 (0)