Skip to content

Commit e771bcb

Browse files
authored
Add Ruby 4.0 support (#152)
- Add Ruby 4.0 to CI test matrix and CD build matrix - Upgrade magnus 0.7.1 → 0.8 for Ruby 4.0 compatibility - Upgrade serde_magnus 0.9.0 → 0.10 - Update Rust code for magnus 0.8 API changes: - Pass `&Ruby` handle to `serialize()` calls - Use `ruby.exception_runtime_error()` instead of `magnus::exception::runtime_error()` Tested locally on Ruby 3.4.7 and Ruby 4.0.0 (90 examples, 0 failures).
1 parent 82bebc5 commit e771bcb

File tree

5 files changed

+28
-34
lines changed

5 files changed

+28
-34
lines changed

.github/workflows/cd.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
# https://github.com/oxidize-rb/actions/blob/main/fetch-ci-data/evaluate.rb#L54
2929
exclude: [arm-linux, x64-mingw32, x64-mingw-ucrt, aarch64-linux-musl]
3030
stable-ruby-versions: |
31-
only: ['3.2', '3.3', '3.4']
31+
only: ['3.2', '3.3', '3.4', '4.0']
3232
3333
build:
3434
name: Build native gems

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
stable-ruby-versions: |
1919
# Explicitly include all Ruby versions we want to support
2020
# to ensure binaries are built for each version
21-
only: ['3.2', '3.3', '3.4']
21+
only: ['3.2', '3.3', '3.4', '4.0']
2222
rspec:
2323
runs-on: ${{ matrix.os }}
2424
needs: ci-data

Cargo.lock

Lines changed: 8 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/code_ownership/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ rb-sys = { version = "0.9.111", features = [
1414
"bindgen-deprecated-types",
1515
"stable-api-compiled-fallback",
1616
] }
17-
magnus = { version = "0.7.1" }
17+
magnus = { version = "0.8" }
1818
serde = { version = "1.0.219", features = ["derive"] }
19-
serde_magnus = "0.9.0"
19+
serde_magnus = "0.10"
2020
codeowners = { git = "https://github.com/rubyatscale/codeowners-rs.git", tag = "v0.3.0" }
2121

2222
[dev-dependencies]

ext/code_ownership/src/lib.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ pub struct Team {
1212
pub reasons: Vec<String>,
1313
}
1414

15-
fn for_team(team_name: String) -> Result<Value, Error> {
15+
fn for_team(ruby: &Ruby, team_name: String) -> Result<Value, Error> {
1616
let run_config = build_run_config();
1717
let team = runner::for_team(&run_config, &team_name);
18-
validate_result(&team)
18+
validate_result(ruby, &team)
1919
}
2020

21-
fn teams_for_files(file_paths: Vec<String>) -> Result<Value, Error> {
21+
fn teams_for_files(ruby: &Ruby, file_paths: Vec<String>) -> Result<Value, Error> {
2222
let run_config = build_run_config();
2323
let path_teams = runner::teams_for_files_from_codeowners(&run_config, &file_paths);
2424
match path_teams {
@@ -35,14 +35,14 @@ fn teams_for_files(file_paths: Vec<String>) -> Result<Value, Error> {
3535
teams_map.insert(path, None);
3636
}
3737
}
38-
let serialized: Value = serialize(&teams_map)?;
38+
let serialized: Value = serialize(ruby, &teams_map)?;
3939
Ok(serialized)
4040
}
41-
Err(e) => Err(Error::new(magnus::exception::runtime_error(), e.to_string())),
41+
Err(e) => Err(Error::new(ruby.exception_runtime_error(), e.to_string())),
4242
}
4343
}
4444

45-
fn for_file(file_path: String) -> Result<Option<Value>, Error> {
45+
fn for_file(ruby: &Ruby, file_path: String) -> Result<Option<Value>, Error> {
4646
let run_config = build_run_config();
4747

4848
match runner::file_owner_for_file(&run_config, &file_path) {
@@ -57,14 +57,14 @@ fn for_file(file_path: String) -> Result<Option<Value>, Error> {
5757
.map(|source| source.to_string())
5858
.collect(),
5959
};
60-
let serialized: Value = serialize(&team)?;
60+
let serialized: Value = serialize(ruby, &team)?;
6161
Ok(Some(serialized))
6262
} else {
6363
Ok(None)
6464
}
6565
}
6666
Err(e) => Err(Error::new(
67-
magnus::exception::runtime_error(),
67+
ruby.exception_runtime_error(),
6868
e.to_string(),
6969
)),
7070
}
@@ -74,33 +74,33 @@ fn version() -> String {
7474
runner::version()
7575
}
7676

77-
fn validate(files: Option<Vec<String>>) -> Result<Value, Error> {
77+
fn validate(ruby: &Ruby, files: Option<Vec<String>>) -> Result<Value, Error> {
7878
let run_config = build_run_config();
7979
let files_vec = files.unwrap_or_default();
8080
let run_result = runner::validate(&run_config, files_vec);
81-
validate_result(&run_result)
81+
validate_result(ruby, &run_result)
8282
}
8383

84-
fn generate_and_validate(files: Option<Vec<String>>, skip_stage: bool) -> Result<Value, Error> {
84+
fn generate_and_validate(ruby: &Ruby, files: Option<Vec<String>>, skip_stage: bool) -> Result<Value, Error> {
8585
let run_config = build_run_config();
8686
let files_vec = files.unwrap_or_default();
8787
let run_result = runner::generate_and_validate(&run_config, files_vec, skip_stage);
88-
validate_result(&run_result)
88+
validate_result(ruby, &run_result)
8989
}
9090

91-
fn validate_result(run_result: &runner::RunResult) -> Result<Value, Error> {
91+
fn validate_result(ruby: &Ruby, run_result: &runner::RunResult) -> Result<Value, Error> {
9292
if !run_result.validation_errors.is_empty() {
9393
Err(Error::new(
94-
magnus::exception::runtime_error(),
94+
ruby.exception_runtime_error(),
9595
run_result.validation_errors.join("\n"),
9696
))
9797
} else if !run_result.io_errors.is_empty() {
9898
Err(Error::new(
99-
magnus::exception::runtime_error(),
99+
ruby.exception_runtime_error(),
100100
run_result.io_errors.join("\n"),
101101
))
102102
} else {
103-
let serialized: Value = serialize(&run_result.info_messages)?;
103+
let serialized: Value = serialize(ruby, &run_result.info_messages)?;
104104
Ok(serialized)
105105
}
106106
}

0 commit comments

Comments
 (0)