Skip to content

Commit 0af3b61

Browse files
Move release tasks to ci.rake
1 parent 0ae81e4 commit 0af3b61

File tree

3 files changed

+82
-81
lines changed

3 files changed

+82
-81
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ jobs:
152152
node-version: 16
153153
registry-url: https://registry.npmjs.org/
154154
- run: echo "PREREL_NAME=${{ inputs.prerel_name }}" >> $GITHUB_ENV
155-
- run: rake "publish[${PREREL_NAME:-$GITHUB_REF_NAME}]"
155+
- run: rake "ci:publish[${PREREL_NAME:-$GITHUB_REF_NAME}]"
156156
env:
157157
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
158158
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}

tasks/ci.rake

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,46 @@ def latest_build_sources
1212
end
1313
.to_h
1414
end
15+
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+
26+
def release_note
27+
output = <<EOS
28+
| channel | source |
29+
|:-------:|:------:|
30+
EOS
31+
32+
BUILD_SOURCES.each do |name, source|
33+
case source[:type]
34+
when "github"
35+
url =
36+
"https://api.github.com/repos/#{source[:repo]}/commits/#{source[:rev]}"
37+
commit = OpenURI.open_uri(url) { |f| JSON.load(f.read) }
38+
output +=
39+
"| #{name} | [`#{source[:repo]}@#{commit["sha"]}`](https://github.com/ruby/ruby/tree/#{commit["sha"]}) |\n"
40+
else
41+
raise "unknown source type: #{source[:type]}"
42+
end
43+
end
44+
output
45+
end
46+
47+
def sh_or_warn(*cmd)
48+
sh *cmd do |ok, status|
49+
unless ok
50+
warn "Command failed with status (#{status.exitstatus}): #{cmd.join ""}"
51+
end
52+
end
53+
end
54+
1555
namespace :ci do
1656
task :rake_task_matrix do
1757
require "pathname"
@@ -68,4 +108,45 @@ namespace :ci do
68108
content = JSON.generate({ ruby_revisions: latest_build_sources })
69109
File.write("build_manifest.json", content)
70110
end
111+
112+
desc "Fetch artifacts of a run of GitHub Actions"
113+
task :fetch_artifacts, [:run_id] do |t, args|
114+
RubyWasm::Toolchain.check_executable("gh")
115+
116+
artifacts =
117+
JSON.load(
118+
`gh api repos/{owner}/{repo}/actions/runs/#{args[:run_id]}/artifacts`
119+
)
120+
artifacts =
121+
artifacts["artifacts"].filter { RELASE_ARTIFACTS.include?(_1["name"]) }
122+
mkdir_p "release"
123+
Dir.chdir("release") do
124+
artifacts.each do |artifact|
125+
url = artifact["archive_download_url"]
126+
sh "gh api #{url} > #{artifact["name"]}.zip"
127+
mkdir_p artifact["name"]
128+
sh "unzip #{artifact["name"]}.zip -d #{artifact["name"]}"
129+
rm "#{artifact["name"]}.zip"
130+
end
131+
end
132+
end
133+
134+
desc "Publish artifacts as a GitHub Release"
135+
task :publish, [:tag] do |t, args|
136+
RubyWasm::Toolchain.check_executable("gh")
137+
138+
nightly = /^\d{4}-\d{2}-\d{2}-.$/.match?(args[:tag])
139+
files =
140+
RELASE_ARTIFACTS.flat_map { |artifact| Dir.glob("release/#{artifact}/*") }
141+
File.open("release/note.md", "w") { |f| f.print release_note }
142+
NPM_RELEASE_ARTIFACTS.each do |artifact|
143+
tarball = Dir.glob("release/#{artifact}/*")
144+
next if tarball.empty?
145+
tarball = tarball[0]
146+
# tolerate failure as a case that has already been released
147+
npm_tag = nightly ? "next" : "latest"
148+
sh_or_warn %Q(npm publish --tag #{npm_tag} #{tarball})
149+
end
150+
sh %Q(gh release create #{args[:tag]} --title #{args[:tag]} --notes-file release/note.md #{nightly ? "--prerelease" : ""} #{files.join(" ")})
151+
end
71152
end

tasks/packaging.rake

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -91,83 +91,3 @@ namespace :wapm do
9191
end
9292
end
9393
end
94-
95-
NPM_RELEASE_ARTIFACTS = %w[
96-
npm-ruby-head-wasm-emscripten
97-
npm-ruby-head-wasm-wasi
98-
npm-ruby-3_2-wasm-wasi
99-
]
100-
RELASE_ARTIFACTS =
101-
BUILD_TASKS.map do |build|
102-
File.basename(build.crossruby.artifact, ".tar.gz")
103-
end + NPM_RELEASE_ARTIFACTS
104-
105-
def release_note
106-
output = <<EOS
107-
| channel | source |
108-
|:-------:|:------:|
109-
EOS
110-
111-
BUILD_SOURCES.each do |name, source|
112-
case source[:type]
113-
when "github"
114-
url =
115-
"https://api.github.com/repos/#{source[:repo]}/commits/#{source[:rev]}"
116-
commit = OpenURI.open_uri(url) { |f| JSON.load(f.read) }
117-
output +=
118-
"| #{name} | [`#{source[:repo]}@#{commit["sha"]}`](https://github.com/ruby/ruby/tree/#{commit["sha"]}) |\n"
119-
else
120-
raise "unknown source type: #{source[:type]}"
121-
end
122-
end
123-
output
124-
end
125-
126-
desc "Fetch artifacts of a run of GitHub Actions"
127-
task :fetch_artifacts, [:run_id] do |t, args|
128-
RubyWasm::Toolchain.check_executable("gh")
129-
130-
artifacts =
131-
JSON.load(
132-
`gh api repos/{owner}/{repo}/actions/runs/#{args[:run_id]}/artifacts`
133-
)
134-
artifacts =
135-
artifacts["artifacts"].filter { RELASE_ARTIFACTS.include?(_1["name"]) }
136-
mkdir_p "release"
137-
Dir.chdir("release") do
138-
artifacts.each do |artifact|
139-
url = artifact["archive_download_url"]
140-
sh "gh api #{url} > #{artifact["name"]}.zip"
141-
mkdir_p artifact["name"]
142-
sh "unzip #{artifact["name"]}.zip -d #{artifact["name"]}"
143-
rm "#{artifact["name"]}.zip"
144-
end
145-
end
146-
end
147-
148-
desc "Publish artifacts as a GitHub Release"
149-
task :publish, [:tag] do |t, args|
150-
RubyWasm::Toolchain.check_executable("gh")
151-
152-
nightly = /^\d{4}-\d{2}-\d{2}-.$/.match?(args[:tag])
153-
files =
154-
RELASE_ARTIFACTS.flat_map { |artifact| Dir.glob("release/#{artifact}/*") }
155-
File.open("release/note.md", "w") { |f| f.print release_note }
156-
NPM_RELEASE_ARTIFACTS.each do |artifact|
157-
tarball = Dir.glob("release/#{artifact}/*")
158-
next if tarball.empty?
159-
tarball = tarball[0]
160-
# tolerate failure as a case that has already been released
161-
npm_tag = nightly ? "next" : "latest"
162-
sh_or_warn %Q(npm publish --tag #{npm_tag} #{tarball})
163-
end
164-
sh %Q(gh release create #{args[:tag]} --title #{args[:tag]} --notes-file release/note.md #{nightly ? "--prerelease" : ""} #{files.join(" ")})
165-
end
166-
167-
def sh_or_warn(*cmd)
168-
sh *cmd do |ok, status|
169-
unless ok
170-
warn "Command failed with status (#{status.exitstatus}): #{cmd.join ""}"
171-
end
172-
end
173-
end

0 commit comments

Comments
 (0)