Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix shared layer logic #364

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions buildpacks/ruby/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 31 additions & 2 deletions buildpacks/ruby/src/layers/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ 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<M>(old: &M, now: &M) -> (RestoredLayerAction, Meta<M>)
where
M: MetadataDiff + Clone,
{
let diff = now.diff(old);
if diff.is_empty() {
(RestoredLayerAction::KeepLayer, Meta::Data(now.clone()))
(RestoredLayerAction::KeepLayer, Meta::Data(old.clone()))
} else {
(
RestoredLayerAction::DeleteLayer,
Expand Down Expand Up @@ -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<String> {
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();
Expand Down
Loading