-
Notifications
You must be signed in to change notification settings - Fork 9
/
Rakefile
242 lines (232 loc) · 7.62 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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# frozen_string_literal: true
require "set"
require "yaml"
CACHE_VERSION = "v1"
CI_WORKFLOW_FILE = ".github/workflows/ci.yml"
namespace :build_matrix do
namespace :github do
task :generate do
yaml = YAML.load_file("build_matrix.yml")
matrix = yaml["matrix"]
github = yaml["github"]
jobs = {}
matrix["nodejs"].each do |nodejs|
nodejs_version = nodejs["nodejs"]
job_name = "Node.js #{nodejs_version}"
build_job_key = "build_#{nodejs_version}"
build_cache_key = "#{CACHE_VERSION}-package-build-#{nodejs_version}-${{github.run_id}}"
jobs[build_job_key] = {
"name" => "#{job_name} - Build",
"runs-on" => "ubuntu-latest",
"needs" => "validation",
"steps" => [
{
"name" => "Checkout project",
"uses" => "actions/checkout@v4"
},
{
"name" => "Checkout Mono",
"uses" => "actions/checkout@v4",
"with" => {
"repository" => "appsignal/mono",
"path" => "tmp/mono"
}
},
{
"name" => "Install Node.js",
"uses" => "actions/setup-node@v4",
"with" => {
"node-version" => nodejs_version,
"cache" => "npm",
"cache-dependency-path" => "package-lock.json"
}
},
{
"name" => "Install dependencies",
"run" => "tmp/mono/bin/mono bootstrap --ci"
},
{
"name" => "Build package",
"run" => "tmp/mono/bin/mono build"
},
{
"name" => "Check install report",
"run" =>
"cat ext/install.report; cat ext/install.report | grep '\"status\": \"success\"'"
},
{
"name" => "Save build cache",
"uses" => "actions/cache/save@v4",
"with" => {
"key" => build_cache_key,
"path" => <<~PATHS
build/
dist/
ext/
PATHS
}
}
]
}
unit_test_job_key = "test_#{nodejs_version}_unit"
jobs[unit_test_job_key] = {
"name" => "#{job_name} - Tests",
"needs" => build_job_key,
"runs-on" => "ubuntu-latest",
"steps" => [
{
"name" => "Checkout project",
"uses" => "actions/checkout@v4"
},
{
"name" => "Checkout Mono",
"uses" => "actions/checkout@v4",
"with" => {
"repository" => "appsignal/mono",
"path" => "tmp/mono"
}
},
{
"name" => "Install Node.js",
"uses" => "actions/setup-node@v4",
"with" => {
"node-version" => nodejs_version,
"cache" => "npm",
"cache-dependency-path" => "package-lock.json"
}
},
{
"name" => "Restore build cache",
"uses" => "actions/cache/restore@v4",
"with" => {
"fail-on-cache-miss" => true,
"key" => build_cache_key,
"path" => <<~PATHS
build/
dist/
ext/
PATHS
}
},
{
"name" => "Install dependencies",
"run" => "tmp/mono/bin/mono bootstrap --ci"
},
{
"name" => "Run tests",
"run" => "tmp/mono/bin/mono test"
},
{
"name" => "Run tests for install failure",
"run" => "npm run test:failure"
}
]
}
# Run extra tests against specific package versions. If configured,
# run the extra tests configured for the package.
test_key = "diagnose"
diagnose_job_key = "test_#{nodejs_version}_extra_#{test_key}"
jobs[diagnose_job_key] = {
"name" => "#{job_name} - Extra test - #{test_key}",
"needs" => build_job_key,
"runs-on" => "ubuntu-latest",
"steps" => [
{
"name" => "Checkout project",
"uses" => "actions/checkout@v4",
"with" => { "submodules" => true }
},
{
"name" => "Checkout Mono",
"uses" => "actions/checkout@v4",
"with" => {
"repository" => "appsignal/mono",
"path" => "tmp/mono"
}
},
{
"name" => "Install Ruby",
"uses" => "ruby/setup-ruby@v1",
"with" => {
"ruby-version" => "3.3",
"bundler-cache" => true
}
},
{
"name" => "Install Node.js",
"uses" => "actions/setup-node@v4",
"with" => {
"node-version" => nodejs_version,
"cache" => "npm",
"cache-dependency-path" => "package-lock.json"
}
},
{
"name" => "Restore build cache",
"uses" => "actions/cache/restore@v4",
"with" => {
"fail-on-cache-miss" => true,
"key" => build_cache_key,
"path" => <<~PATHS
build/
dist/
ext/
PATHS
}
},
{
"name" => "Install dependencies",
"run" => "tmp/mono/bin/mono bootstrap --ci"
},
{
"name" => "Run tests",
"run" => "LANGUAGE=nodejs test/integration/diagnose/bin/test"
}
]
}
jobs["cleanup_#{nodejs_version}"] = {
"name" => "#{job_name} - Clean up",
"needs" => [
unit_test_job_key,
diagnose_job_key
],
# Skip this job for dependabot and forked PRs as they do not
# have write permissions to the repository to delete caches
"if" => "github.actor != 'dependabot[bot]' && " \
"github.event.pull_request.head.repo.fork == false",
"runs-on" => "ubuntu-latest",
"steps" => [
{
"name" => "Checkout project",
"uses" => "actions/checkout@v4"
},
{
"name" => "Delete build cache",
"run" => "gh cache delete #{build_cache_key}",
"env" => {
"GH_TOKEN" => "${{secrets.GITHUB_TOKEN}}"
}
}
]
}
end
github["jobs"].merge!(jobs)
header = "# DO NOT EDIT\n" \
"# This is a generated file by the `rake build_matrix:github:generate` task.\n" \
"# See `build_matrix.yml` for the build matrix.\n" \
"# Generate this file with `rake build_matrix:github:generate`.\n"
generated_yaml = header + YAML.dump(github)
File.write(CI_WORKFLOW_FILE, generated_yaml)
puts "Generated `#{CI_WORKFLOW_FILE}`"
puts "Job count: #{jobs.length}"
end
task :validate => :generate do
`git status | grep #{CI_WORKFLOW_FILE} 2>&1`
if $?.exitstatus.zero? # rubocop:disable Style/SpecialGlobalVars
puts "The `#{CI_WORKFLOW_FILE}` is modified. The changes were not committed."
puts "Please run `rake build_matrix:github:generate` and commit the changes."
exit 1
end
end
end
end