Skip to content

Commit 9353363

Browse files
Remove RELASE_ARTIFACTS for better maintainability
1 parent 0af3b61 commit 9353363

File tree

1 file changed

+62
-65
lines changed

1 file changed

+62
-65
lines changed

tasks/ci.rake

Lines changed: 62 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,6 @@ def latest_build_sources
1313
.to_h
1414
end
1515

16-
NPM_RELEASE_ARTIFACTS = %w[
17-
npm-ruby-head-wasm-emscripten
18-
npm-ruby-head-wasm-wasi
19-
npm-ruby-3_2-wasm-wasi
20-
]
21-
RELASE_ARTIFACTS =
22-
BUILD_TASKS.map do |build|
23-
File.basename(build.crossruby.artifact, ".tar.gz")
24-
end + NPM_RELEASE_ARTIFACTS
25-
2616
def release_note
2717
output = <<EOS
2818
| channel | source |
@@ -52,56 +42,60 @@ def sh_or_warn(*cmd)
5242
end
5343
end
5444

45+
def rake_task_matrix
46+
require "pathname"
47+
ruby_cache_keys = {}
48+
BUILD_TASKS.each { |build| ruby_cache_keys[build.name] = build.hexdigest }
49+
build_entries =
50+
BUILD_TASKS.map do |build|
51+
{
52+
task: "build:#{build.name}",
53+
artifact:
54+
Pathname
55+
.new(build.crossruby.artifact)
56+
.relative_path_from(LIB_ROOT)
57+
.to_s,
58+
artifact_name: File.basename(build.crossruby.artifact, ".tar.gz"),
59+
builder: build.target,
60+
rubies_cache_key: ruby_cache_keys[build.name]
61+
}
62+
end
63+
npm_entries =
64+
NPM_PACKAGES.map do |pkg|
65+
entry = {
66+
task: "npm:#{pkg[:name]}",
67+
prerelease: "npm:configure_prerelease",
68+
artifact: "packages/npm-packages/#{pkg[:name]}/#{pkg[:name]}-*.tgz",
69+
artifact_name: "npm-#{pkg[:name]}",
70+
builder: pkg[:target],
71+
rubies_cache_key: ruby_cache_keys[pkg[:build]]
72+
}
73+
# Run tests only if the package has 'test' script
74+
package_json =
75+
JSON.parse(
76+
File.read("packages/npm-packages/#{pkg[:name]}/package.json")
77+
)
78+
if package_json["scripts"] && package_json["scripts"]["test"]
79+
entry[:test] = "npm:#{pkg[:name]}-check"
80+
end
81+
entry
82+
end
83+
wapm_entries =
84+
WAPM_PACKAGES.map do |pkg|
85+
{
86+
task: "wapm:#{pkg[:name]}-build",
87+
artifact: "packages/wapm-packages/#{pkg[:name]}/dist",
88+
artifact_name: "wapm-#{pkg[:name]}",
89+
builder: "wasm32-unknown-wasi",
90+
rubies_cache_key: ruby_cache_keys[pkg[:build]]
91+
}
92+
end
93+
{ build: build_entries, npm: npm_entries, wapm: wapm_entries }
94+
end
95+
5596
namespace :ci do
5697
task :rake_task_matrix do
57-
require "pathname"
58-
ruby_cache_keys = {}
59-
BUILD_TASKS.each { |build| ruby_cache_keys[build.name] = build.hexdigest }
60-
entries =
61-
BUILD_TASKS.map do |build|
62-
{
63-
task: "build:#{build.name}",
64-
artifact:
65-
Pathname
66-
.new(build.crossruby.artifact)
67-
.relative_path_from(LIB_ROOT)
68-
.to_s,
69-
artifact_name: File.basename(build.crossruby.artifact, ".tar.gz"),
70-
builder: build.target,
71-
rubies_cache_key: ruby_cache_keys[build.name]
72-
}
73-
end
74-
entries +=
75-
NPM_PACKAGES.map do |pkg|
76-
entry = {
77-
task: "npm:#{pkg[:name]}",
78-
prerelease: "npm:configure_prerelease",
79-
artifact: "packages/npm-packages/#{pkg[:name]}/#{pkg[:name]}-*.tgz",
80-
artifact_name: "npm-#{pkg[:name]}",
81-
builder: pkg[:target],
82-
rubies_cache_key: ruby_cache_keys[pkg[:build]]
83-
}
84-
# Run tests only if the package has 'test' script
85-
package_json =
86-
JSON.parse(
87-
File.read("packages/npm-packages/#{pkg[:name]}/package.json")
88-
)
89-
if package_json["scripts"] && package_json["scripts"]["test"]
90-
entry[:test] = "npm:#{pkg[:name]}-check"
91-
end
92-
entry
93-
end
94-
entries +=
95-
WAPM_PACKAGES.map do |pkg|
96-
{
97-
task: "wapm:#{pkg[:name]}-build",
98-
artifact: "packages/wapm-packages/#{pkg[:name]}/dist",
99-
artifact_name: "wapm-#{pkg[:name]}",
100-
builder: "wasm32-unknown-wasi",
101-
rubies_cache_key: ruby_cache_keys[pkg[:build]]
102-
}
103-
end
104-
print JSON.generate(entries)
98+
print JSON.generate(rake_task_matrix.flat_map { |_, entries| entries })
10599
end
106100

107101
task :pin_build_manifest do
@@ -112,13 +106,15 @@ namespace :ci do
112106
desc "Fetch artifacts of a run of GitHub Actions"
113107
task :fetch_artifacts, [:run_id] do |t, args|
114108
RubyWasm::Toolchain.check_executable("gh")
115-
109+
116110
artifacts =
117111
JSON.load(
118112
`gh api repos/{owner}/{repo}/actions/runs/#{args[:run_id]}/artifacts`
119113
)
114+
matrix = rake_task_matrix.flat_map { |_, entries| entries }
115+
release_artifacts = matrix.map { |entry| entry[:artifact_name] }
120116
artifacts =
121-
artifacts["artifacts"].filter { RELASE_ARTIFACTS.include?(_1["name"]) }
117+
artifacts["artifacts"].filter { release_artifacts.include?(_1["name"]) }
122118
mkdir_p "release"
123119
Dir.chdir("release") do
124120
artifacts.each do |artifact|
@@ -130,16 +126,17 @@ namespace :ci do
130126
end
131127
end
132128
end
133-
129+
134130
desc "Publish artifacts as a GitHub Release"
135131
task :publish, [:tag] do |t, args|
136132
RubyWasm::Toolchain.check_executable("gh")
137-
133+
138134
nightly = /^\d{4}-\d{2}-\d{2}-.$/.match?(args[:tag])
139-
files =
140-
RELASE_ARTIFACTS.flat_map { |artifact| Dir.glob("release/#{artifact}/*") }
135+
matrix = rake_task_matrix
136+
files = matrix.map { |entry| "release/#{entry[:artifact_name]}/*" }
141137
File.open("release/note.md", "w") { |f| f.print release_note }
142-
NPM_RELEASE_ARTIFACTS.each do |artifact|
138+
matrix[:npm].each do |task|
139+
artifact = task[:artifact_name]
143140
tarball = Dir.glob("release/#{artifact}/*")
144141
next if tarball.empty?
145142
tarball = tarball[0]

0 commit comments

Comments
 (0)