@@ -12,6 +12,46 @@ def latest_build_sources
1212 end
1313 . to_h
1414end
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+
1555namespace :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
71152end
0 commit comments