Skip to content

Commit 4aa63cb

Browse files
Cache ./rubies directory on CI
1 parent 4dd97bd commit 4aa63cb

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

.github/workflows/build.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ jobs:
8888
entries: ${{ steps.set-matrix.outputs.entries }}
8989
steps:
9090
- uses: actions/checkout@v3
91+
- run: rake ci:pin_build_manifest
92+
- uses: actions/upload-artifact@v3
93+
with:
94+
name: build-manifest
95+
path: build-manifest.json
9196
- name: Set matrix
9297
id: set-matrix
9398
run: |
@@ -103,6 +108,13 @@ jobs:
103108
runs-on: ubuntu-20.04
104109
steps:
105110
- uses: actions/checkout@v3
111+
- uses: actions/download-artifact@v3
112+
with:
113+
name: build-manifest
114+
- uses: actions/cache@v3
115+
with:
116+
path: ./rubies
117+
key: ${{ matrix.entry.rubies_cache_key }}
106118
- name: Fetch builder image
107119
uses: actions/download-artifact@v3
108120
with:

lib/ruby_wasm/build_system/product/ruby_source.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@ def name
1111
@params[:name]
1212
end
1313

14+
def cache_key
15+
case @params[:type]
16+
when "github"
17+
@params[:rev]
18+
when "local"
19+
File.mtime(@params[:src]).to_i.to_s
20+
else
21+
raise "unknown source type: #{@params[:type]}"
22+
end
23+
end
24+
1425
def src_dir
1526
File.join(@build_dir, "checkouts", @params[:name])
1627
end

lib/ruby_wasm/rake_task.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def initialize(
9292
def hexdigest
9393
require "digest"
9494
digest = Digest::SHA256.new
95-
digest << @source.name
95+
digest << @source.cache_key
9696
digest << @build_dir
9797
digest << @rubies_dir
9898
digest << @target

tasks/ci.rake

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,17 @@ end
1313
namespace :ci do
1414
task :rake_task_matrix do
1515
require "pathname"
16+
ruby_cache_keys = {}
17+
BUILD_TASKS.each do |build|
18+
ruby_cache_keys[build.name] = build.hexdigest
19+
end
1620
entries = BUILD_TASKS.map do |build|
1721
{
1822
task: "build:#{build.name}",
1923
artifact: Pathname.new(build.crossruby.artifact).relative_path_from(LIB_ROOT).to_s,
2024
artifact_name: File.basename(build.crossruby.artifact, ".tar.gz"),
2125
builder: build.target,
26+
rubies_cache_key: ruby_cache_keys[build.name],
2227
}
2328
end
2429
entries += NPM_PACKAGES.map do |pkg|
@@ -29,6 +34,7 @@ namespace :ci do
2934
artifact: "packages/npm-packages/#{pkg[:name]}/#{pkg[:name]}-*.tgz",
3035
artifact_name: "npm-#{pkg[:name]}",
3136
builder: pkg[:target],
37+
rubies_cache_key: ruby_cache_keys[pkg[:build]],
3238
}
3339
end
3440
entries += WAPM_PACKAGES.map do |pkg|
@@ -37,12 +43,13 @@ namespace :ci do
3743
artifact: "packages/wapm-packages/#{pkg[:name]}/dist",
3844
artifact_name: "wapm-#{pkg[:name]}",
3945
builder: "wasm32-unknown-wasi",
46+
rubies_cache_key: ruby_cache_keys[pkg[:build]],
4047
}
4148
end
4249
print JSON.generate(entries)
4350
end
4451

45-
task :build_manifest do
52+
task :pin_build_manifest do
4653
content = JSON.generate({ ruby_revisions: latest_build_sources })
4754
File.write("build_manifest.json", content)
4855
end

0 commit comments

Comments
 (0)