diff --git a/buildpacks/ruby/CHANGELOG.md b/buildpacks/ruby/CHANGELOG.md index 7f7d9d5e..4fe45c9e 100644 --- a/buildpacks/ruby/CHANGELOG.md +++ b/buildpacks/ruby/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- A bug introduced in 4.0.0 would result in incorrectly skipping running `bundle install` when the `Gemfile` or `Gemfile.lock` or environment variables had changed. The bug is now fixed. ([#364](https://github.com/heroku/buildpacks-ruby/pull/364)) + ## [4.0.0] - 2024-11-27 ### Changed diff --git a/buildpacks/ruby/src/layers/shared.rs b/buildpacks/ruby/src/layers/shared.rs index 58854211..f7dcc3dc 100644 --- a/buildpacks/ruby/src/layers/shared.rs +++ b/buildpacks/ruby/src/layers/shared.rs @@ -38,7 +38,7 @@ pub(crate) trait MetadataDiff { /// Standardizes formatting for layer cache clearing behavior /// -/// If the diff is empty, there are no changes and the layer is kept +/// If the diff is empty, there are no changes and the layer is kept and the old data is returned /// If the diff is not empty, the layer is deleted and the changes are listed pub(crate) fn restored_layer_action(old: &M, now: &M) -> (RestoredLayerAction, Meta) where @@ -46,7 +46,7 @@ where { let diff = now.diff(old); if diff.is_empty() { - (RestoredLayerAction::KeepLayer, Meta::Data(now.clone())) + (RestoredLayerAction::KeepLayer, Meta::Data(old.clone())) } else { ( RestoredLayerAction::DeleteLayer, @@ -222,6 +222,35 @@ mod tests { } migrate_toml_chain! {TestMetadata} + #[test] + fn test_restored_layer_action_returns_old_data() { + #[derive(Debug, Clone)] + struct AlwaysNoDiff { + value: String, + } + + impl MetadataDiff for AlwaysNoDiff { + fn diff(&self, _: &Self) -> Vec { + vec![] + } + } + + let old = AlwaysNoDiff { + value: "old".to_string(), + }; + let now = AlwaysNoDiff { + value: "now".to_string(), + }; + + let result = restored_layer_action(&old, &now); + match result { + (RestoredLayerAction::KeepLayer, Meta::Data(data)) => { + assert_eq!(data.value, "old"); + } + _ => panic!("Expected to keep layer"), + } + } + #[test] fn test_cached_layer_write_metadata_restored_layer_action() { let temp = tempfile::tempdir().unwrap();