Split rake jobs
diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 9169016..a0df092 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml
@@ -56,8 +56,8 @@ cd rust cargo test --verbose - publish-dry-run: - name: cargo:publish-dry-run + publish-dry-run-ruby-rbs-sys: + name: rust:publish:ruby-rbs-sys runs-on: ubuntu-latest continue-on-error: true steps: @@ -93,8 +93,50 @@ key: ${{ runner.os }}-cargo-${{ hashFiles('rust/Cargo.lock') }} restore-keys: | ${{ runner.os }}-cargo- - - name: Test publish crates - run: bundle exec rake rust:publish + - name: Test publish ruby-rbs-sys + run: bundle exec rake rust:publish:ruby-rbs-sys + env: + RBS_RUST_PUBLISH_DRY_RUN: "1" + + publish-dry-run-ruby-rbs: + name: rust:publish:ruby-rbs + runs-on: ubuntu-latest + continue-on-error: true + steps: + - uses: actions/checkout@v6 + - run: git fetch --depth=1 origin +refs/tags/*:refs/tags/* + - name: Set up git identity + run: | + git config user.name "GitHub Actions" + git config user.email "actions@github.com" + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ruby + bundler: none + - name: Update rubygems & bundler + run: gem update --system + - name: Install gems + run: | + bundle config set --local without libs:profilers + bundle install --jobs 4 --retry 3 + - name: Set up vendored RBS source + run: bundle exec rake rust:rbs:sync + - name: Install Rust tools + run: | + rustup update --no-self-update stable + rustup default stable + - uses: actions/cache@v5 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + rust/target + key: ${{ runner.os }}-cargo-${{ hashFiles('rust/Cargo.lock') }} + restore-keys: | + ${{ runner.os }}-cargo- + - name: Test publish ruby-rbs + run: bundle exec rake rust:publish:ruby-rbs env: RBS_RUST_PUBLISH_DRY_RUN: "1"
diff --git a/Rakefile b/Rakefile index 0c5b355..68d1b54 100644 --- a/Rakefile +++ b/Rakefile
@@ -637,36 +637,34 @@ end end - desc "Publish Rust crates to crates.io (set RBS_RUST_PUBLISH_DRY_RUN=1 for dry-run only)" - task :publish do - dry_run = ENV["RBS_RUST_PUBLISH_DRY_RUN"] + namespace :publish do + def self.prepare_publish_branch(crate_name) + dry_run = ENV["RBS_RUST_PUBLISH_DRY_RUN"] - version_file = File.join(RUST_DIR, "rbs_version") + version_file = File.join(RUST_DIR, "rbs_version") - unless File.exist?(version_file) - raise "#{version_file} not found. Run `rake rust:rbs:pin[VERSION]` first." - end + unless File.exist?(version_file) + raise "#{version_file} not found. Run `rake rust:rbs:pin[VERSION]` first." + end - rbs_version = File.read(version_file).strip - raise "#{version_file} is empty" if rbs_version.empty? + rbs_version = File.read(version_file).strip + raise "#{version_file} is empty" if rbs_version.empty? - sys_crate_version = File.read(File.join(RUST_DIR, "ruby-rbs-sys", "Cargo.toml"))[/^version\s*=\s*"(.+)"/, 1] - rbs_crate_version = File.read(File.join(RUST_DIR, "ruby-rbs", "Cargo.toml"))[/^version\s*=\s*"(.+)"/, 1] - release_branch = "rust/release-#{Time.now.strftime('%Y%m%d%H%M%S')}" + crate_version = File.read(File.join(RUST_DIR, crate_name, "Cargo.toml"))[/^version\s*=\s*"(.+)"/, 1] + release_branch = "rust/release-#{crate_name}-#{Time.now.strftime('%Y%m%d%H%M%S')}" - puts "=" * 60 - puts "Rust crate publish#{dry_run ? " (DRY RUN)" : ""}" - puts "=" * 60 - puts " RBS source version: #{rbs_version}" - puts " ruby-rbs-sys: #{sys_crate_version} (tag: ruby-rbs-sys-v#{sys_crate_version})" - puts " ruby-rbs: #{rbs_crate_version} (tag: ruby-rbs-v#{rbs_crate_version})" - puts " Release branch: #{release_branch}" - puts "=" * 60 + puts "=" * 60 + puts "Rust crate publish: #{crate_name}#{dry_run ? " (DRY RUN)" : ""}" + puts "=" * 60 + puts " RBS source version: #{rbs_version}" + puts " #{crate_name}: #{crate_version} (tag: #{crate_name}-v#{crate_version})" + puts " Release branch: #{release_branch}" + puts "=" * 60 - # Check that vendor dirs contain real files, not symlinks - VENDOR_TARGETS.each do |crate, entries| + # Check that vendor dirs contain real files, not symlinks + entries = VENDOR_TARGETS.fetch(crate_name) entries.each do |entry| - path = File.join(RUST_DIR, crate, "vendor", "rbs", entry) + path = File.join(RUST_DIR, crate_name, "vendor", "rbs", entry) if File.symlink?(path) raise "#{path} is a symlink. Run `rake rust:rbs:sync` first." end @@ -674,53 +672,83 @@ raise "#{path} does not exist. Run `rake rust:rbs:sync` first." end end + + # Ensure working tree is clean before publishing + unless `git status --porcelain`.strip.empty? + raise "💢 Working tree is dirty. Please commit or stash your changes before publishing." + end + + # Create a release branch with vendor files committed + original_branch = `git rev-parse --abbrev-ref HEAD`.strip + + sh "git", "checkout", "-b", release_branch, verbose: false + vendor_path = File.join("rust", crate_name, "vendor", "rbs") + sh "git", "add", "-f", vendor_path, verbose: false + sh "git", "commit", "-m", "Publish #{crate_name} (RBS #{rbs_version})", verbose: false + + [dry_run, crate_version, original_branch] end - # Ensure working tree is clean before publishing - unless `git status --porcelain`.strip.empty? - raise "💢 Working tree is dirty. Please commit or stash your changes before publishing." + desc "Publish ruby-rbs-sys crate to crates.io (set RBS_RUST_PUBLISH_DRY_RUN=1 for dry-run only)" + task :"ruby-rbs-sys" do + crate_name = "ruby-rbs-sys" + dry_run, crate_version, original_branch = prepare_publish_branch(crate_name) + + begin + puts "🔰 Dry-run publishing..." + + Dir.chdir(File.join(RUST_DIR, crate_name)) do + sh "cargo", "publish", "--dry-run" + end + + puts "✅ Dry-run succeeded!" + + unless dry_run + puts "💪 Publishing #{crate_name} for real..." + + Dir.chdir(File.join(RUST_DIR, crate_name)) do + sh "cargo", "publish" + end + + sh "git", "tag", "#{crate_name}-v#{crate_version}" + sh "git", "push", "origin", "#{crate_name}-v#{crate_version}" + + puts "🎉 Published #{crate_name} successfully!" + end + ensure + sh "git", "checkout", original_branch, verbose: false + end end - # Create a release branch with vendor files committed - original_branch = `git rev-parse --abbrev-ref HEAD`.strip + desc "Publish ruby-rbs crate to crates.io (set RBS_RUST_PUBLISH_DRY_RUN=1 for dry-run only)" + task :"ruby-rbs" do + crate_name = "ruby-rbs" + dry_run, crate_version, original_branch = prepare_publish_branch(crate_name) - sh "git", "checkout", "-b", release_branch, verbose: false - vendor_paths = VENDOR_TARGETS.keys.map { |crate| File.join("rust", crate, "vendor", "rbs") } - sh "git", "add", "-f", *vendor_paths, verbose: false - sh "git", "commit", "-m", "Publish Rust crates (RBS #{rbs_version})", verbose: false + begin + puts "🔰 Dry-run publishing..." - begin - puts "🔰 Dry-run publishing..." - - Dir.chdir(File.join(RUST_DIR, "ruby-rbs-sys")) do - sh "cargo", "publish", "--dry-run" - end - - Dir.chdir(File.join(RUST_DIR, "ruby-rbs")) do - sh "cargo", "publish", "--dry-run", "--no-verify" - end - - puts "✅ Dry-run succeeded!" - - unless dry_run - puts "💪 Publishing crates for real..." - - Dir.chdir(File.join(RUST_DIR, "ruby-rbs-sys")) do - sh "cargo", "publish" + Dir.chdir(File.join(RUST_DIR, crate_name)) do + sh "cargo", "publish", "--dry-run", "--no-verify" end - Dir.chdir(File.join(RUST_DIR, "ruby-rbs")) do - sh "cargo", "publish" + puts "✅ Dry-run succeeded!" + + unless dry_run + puts "💪 Publishing #{crate_name} for real..." + + Dir.chdir(File.join(RUST_DIR, crate_name)) do + sh "cargo", "publish" + end + + sh "git", "tag", "#{crate_name}-v#{crate_version}" + sh "git", "push", "origin", "#{crate_name}-v#{crate_version}" + + puts "🎉 Published #{crate_name} successfully!" end - - sh "git", "tag", "ruby-rbs-sys-v#{sys_crate_version}" - sh "git", "tag", "ruby-rbs-v#{rbs_crate_version}" - sh "git", "push", "origin", "ruby-rbs-sys-v#{sys_crate_version}", "ruby-rbs-v#{rbs_crate_version}" - - puts "🎉 Published Rust crates successfully!" + ensure + sh "git", "checkout", original_branch, verbose: false end - ensure - sh "git", "checkout", original_branch, verbose: false end end end
diff --git a/docs/rust.md b/docs/rust.md index 7fda6d5..0d4d3f9 100644 --- a/docs/rust.md +++ b/docs/rust.md
@@ -42,16 +42,16 @@ rake rust:rbs:pin[v4.0.3] ``` -### `rake rust:publish` +### `rake rust:publish:ruby-rbs-sys` / `rake rust:publish:ruby-rbs` -Publishes both crates to crates.io. This task: +Publishes each crate to crates.io individually. Each task: 1. Verifies `rust/rbs_version` is set 2. Verifies vendor directories contain real files (not symlinks) 3. Verifies the git working tree is clean 4. Temporarily commits the vendor files (reverted after publish) 5. Runs a dry-run to check packaging -6. Publishes `ruby-rbs-sys` first, then `ruby-rbs` +6. Publishes the crate ### `rake rust:rbs:symlink` @@ -86,8 +86,9 @@ git commit -m "Bump Rust crate versions" ``` -6. Publish: +6. Publish each crate: ```bash - rake rust:publish + rake rust:publish:ruby-rbs-sys + rake rust:publish:ruby-rbs ```