-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathRakefile
More file actions
128 lines (105 loc) · 2.72 KB
/
Rakefile
File metadata and controls
128 lines (105 loc) · 2.72 KB
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
require 'fileutils'
require 'rake/clean'
SUPPORTED = [
['darwin', 'arm64'],
['darwin', 'amd64'],
['linux', 'amd64'],
['linux', 'arm64'],
['linux', 'arm'],
['windows', 'amd64'],
]
SRC_FILES = FileList['*.go', 'internal/**/*.go'].exclude('internal/**/*_test.go')
OUTDIR = 'out'
RELEASE_DIRS = SUPPORTED.map do |os, arch|
"#{OUTDIR}/#{os}_#{arch}"
end
def get_goos
`go env GOHOSTOS`.strip
end
def exec_name(goos)
if goos == 'windows'
'git-who.exe'
else
'git-who'
end
end
def get_version()
`git describe --tags --always --dirty`.strip
end
def get_commit()
`git rev-parse --short HEAD`.strip
end
def build_for_platform(goos, goarch, progname)
version = get_version
rev = get_commit
sh "GOOS=#{goos} GOARCH=#{goarch} go build -a -o #{progname} "\
"-ldflags '-s -w -X main.Commit=#{rev} -X main.Version=#{version}'"
end
$host_progname = exec_name(get_goos())
file $host_progname => SRC_FILES do |t|
gohostos = get_goos()
gohostarch = `go env GOHOSTARCH`.strip
build_for_platform gohostos, gohostarch, t.name
end
CLOBBER.include($host_progname)
desc 'Build executable'
task build: $host_progname
task default: [:build]
namespace 'release' do
directory OUTDIR
RELEASE_DIRS.each do |dir|
directory dir
end
desc 'Build binaries for all supported platforms'
task build: RELEASE_DIRS do
SUPPORTED.each do |os, arch|
output_dir = "#{OUTDIR}/#{os}_#{arch}"
progname = exec_name(os)
build_for_platform(os, arch, "#{output_dir}/#{progname}")
version = get_version
sh "tar czf #{OUTDIR}/gitwho_#{version}_#{os}_#{arch}.tar.gz "\
"-C #{OUTDIR} #{os}_#{arch}"
end
end
desc 'Sign checksum of built artifacts'
task :sign do
FileUtils.cd(OUTDIR) do
version = get_version
sumsfile = "SHA2-256SUMS_#{version}.txt"
sh "shasum -a 256 **/git-who* > #{sumsfile}"
sh "ssh-keygen -Y sign -n file -f ~/.ssh/gitwho_ed25519 #{sumsfile}"
end
end
task all: [:build, :sign]
end
CLOBBER.include(OUTDIR)
desc 'Run go fmt'
task :fmt do
sh 'go fmt ./internal/...'
sh 'go fmt *.go'
end
namespace 'test' do
desc 'Run all tests'
task all: [:unit, :integration, :functional]
desc 'Run unit tests'
task :unit do
sh 'go test -count=1 ./internal/...'
end
desc 'Run integration tests'
task :integration do
sh 'go test -count=1 ./test/integration/...'
end
begin
require 'minitest/test_task'
Minitest::TestTask.create(:functional) do |t|
t.libs << "test/functional"
t.libs << "test/functional/lib"
t.test_globs = ["test/functional/**/*_test.rb"]
end
rescue LoadError
task :functional do
puts "Skipping functional tests; minitest gem not found."
end
end
end
task test: 'test:all'