diff --git a/.github/workflows/build_jruby.yml b/.github/workflows/build_jruby.yml index ecfa35e..f573de8 100644 --- a/.github/workflows/build_jruby.yml +++ b/.github/workflows/build_jruby.yml @@ -41,8 +41,17 @@ jobs: run: rustup update - name: Rust Cache uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4 # v2.9.1 + - name: Cargo build + run: cargo build --locked - name: Output CHANGELOG - run: cargo run --locked --bin jruby_changelog -- --version "${{inputs.jruby_version}}" | tee "$GITHUB_STEP_SUMMARY" + run: | + set -euo pipefail + { + # 4 backticks so the inner ```ruby fences in the changelog render literally + echo '````' + cargo run --locked --bin jruby_changelog -- --version "${{inputs.jruby_version}}" + echo '````' + } | tee -a "$GITHUB_STEP_SUMMARY" build-and-upload: runs-on: pub-hk-ubuntu-24.04-xlarge diff --git a/.github/workflows/build_ruby.yml b/.github/workflows/build_ruby.yml index 93d576c..938095d 100644 --- a/.github/workflows/build_ruby.yml +++ b/.github/workflows/build_ruby.yml @@ -41,8 +41,17 @@ jobs: run: rustup update - name: Rust Cache uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4 # v2.9.1 + - name: Cargo build + run: cargo build --locked - name: Output CHANGELOG - run: cargo run --locked --bin ruby_changelog -- --version "${{inputs.ruby_version}}" | tee "$GITHUB_STEP_SUMMARY" + run: | + set -euo pipefail + { + # 4 backticks so the inner ```ruby fences in the changelog render literally + echo '````' + cargo run --locked --bin ruby_changelog -- --version "${{inputs.ruby_version}}" + echo '````' + } | tee -a "$GITHUB_STEP_SUMMARY" build-and-upload: runs-on: ${{ matrix.arch == 'arm64' && 'pub-hk-ubuntu-24.04-arm-xlarge' || 'pub-hk-ubuntu-24.04-xlarge' }} diff --git a/Cargo.lock b/Cargo.lock index e276c7b..cb8d6c9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1088,6 +1088,7 @@ dependencies = [ "java-properties", "lazy_static", "libherokubuildpack", + "pretty_assertions", "regex", "reqwest", "serde", diff --git a/jruby_executable/Cargo.toml b/jruby_executable/Cargo.toml index 98d918c..dfbe9f2 100644 --- a/jruby_executable/Cargo.toml +++ b/jruby_executable/Cargo.toml @@ -38,3 +38,6 @@ tar = { workspace = true } tempfile = { workspace = true } thiserror = { workspace = true } winnow = { workspace = true } + +[dev-dependencies] +pretty_assertions = { workspace = true } diff --git a/jruby_executable/src/bin/jruby_changelog.rs b/jruby_executable/src/bin/jruby_changelog.rs index 6586505..33f104a 100644 --- a/jruby_executable/src/bin/jruby_changelog.rs +++ b/jruby_executable/src/bin/jruby_changelog.rs @@ -1,4 +1,4 @@ -use std::error::Error; +use std::{error::Error, io::Write}; use bullet_stream::global::print; use clap::Parser; @@ -11,14 +11,25 @@ struct Args { version: JRubyVersion, } -fn jruby_changelog(args: &Args) -> Result<(), Box> { +fn jruby_changelog(args: &Args, io: W) -> Result> +where + W: Write, +{ let Args { version } = args; let stdlib_version = jruby_build_properties(version)?.ruby_stdlib_version()?; - println!("Add a changelog item: https://devcenter.heroku.com/admin/changelog_items/new"); - println!(); + render_jruby_changelog(version, &stdlib_version, io) +} +fn render_jruby_changelog( + version: &JRubyVersion, + stdlib_version: &str, + mut io: W, +) -> Result> +where + W: Write, +{ let changelog = formatdoc! {" ## JRuby version {version} is now available @@ -32,14 +43,14 @@ fn jruby_changelog(args: &Args) -> Result<(), Box> { The JRuby release notes can be found on the [JRuby website](https://www.jruby.org/news). "}; - print::plain(changelog); + writeln!(io, "{changelog}")?; - Ok(()) + Ok(io) } fn main() { let args = Args::parse(); - if let Err(error) = jruby_changelog(&args) { + if let Err(error) = jruby_changelog(&args, std::io::stdout()) { print::error(formatdoc! {" ❌ Command failed ❌ @@ -49,3 +60,32 @@ fn main() { std::process::exit(1); } } + +#[cfg(test)] +mod test { + use super::*; + use pretty_assertions::assert_eq; + + #[test] + fn regular_release() { + let mut io = Vec::new(); + + let output = + render_jruby_changelog(&JRubyVersion::parse("9.4.7.0").unwrap(), "3.1.4", &mut io) + .unwrap(); + let actual = String::from_utf8_lossy(output); + let expected = formatdoc! {" + ## JRuby version 9.4.7.0 is now available + + [JRuby v9.4.7.0](/articles/ruby-support-reference#supported-jruby-versions) is now available on Heroku. To run + your app using this version of Ruby, add the following `ruby` directive to your Gemfile: + + ```ruby + ruby \"3.1.4\", engine: \"jruby\", engine_version: \"9.4.7.0\" + ``` + + The JRuby release notes can be found on the [JRuby website](https://www.jruby.org/news). + "}; + assert_eq!(expected.trim(), actual.trim()); + } +} diff --git a/ruby_executable/src/bin/ruby_changelog.rs b/ruby_executable/src/bin/ruby_changelog.rs index ff7c71c..78b8256 100644 --- a/ruby_executable/src/bin/ruby_changelog.rs +++ b/ruby_executable/src/bin/ruby_changelog.rs @@ -17,13 +17,6 @@ where { let Args { version } = args; - writeln!( - io, - "Add a changelog item: https://devcenter.heroku.com/admin/changelog_items/new" - )?; - - writeln!(io)?; - let gemfile_format = version.bundler_format(); let changelog = formatdoc! {" @@ -81,8 +74,6 @@ mod test { let output = ruby_changelog(&args, &mut io).unwrap(); let actual = String::from_utf8_lossy(output); let expected = formatdoc! {" - Add a changelog item: https://devcenter.heroku.com/admin/changelog_items/new - ## Ruby version 3.3.2 is now available [Ruby v3.3.2](/articles/ruby-support#ruby-versions) is now available on Heroku. To run \ @@ -106,8 +97,6 @@ mod test { let output = ruby_changelog(&args, &mut io).unwrap(); let actual = String::from_utf8_lossy(output); let expected = formatdoc! {" - Add a changelog item: https://devcenter.heroku.com/admin/changelog_items/new - ## Ruby version 3.1.0-rc1 is now available [Ruby v3.1.0-rc1](/articles/ruby-support#ruby-versions) is now available on Heroku. To run \