Skip to content

Commit 7c9a3ae

Browse files
authored
fix: Fix project graph cache invalidation between moon releases. (#664)
* Include version in cache. * Update changelog.
1 parent f6eb988 commit 7c9a3ae

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

crates/core/project-graph/src/graph_hasher.rs

+19-3
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,34 @@
11
use moon_config::{ProjectsAliasesMap, ProjectsSourcesMap};
2-
use moon_hasher::{hash_btree, Hasher, Sha256};
2+
use moon_hasher::{hash_btree, Digest, Hasher, Sha256};
33
use serde::{Deserialize, Serialize};
4-
use std::collections::BTreeMap;
4+
use std::{collections::BTreeMap, env};
55

6-
#[derive(Default, Deserialize, Serialize)]
6+
#[derive(Deserialize, Serialize)]
77
#[serde(rename_all = "camelCase")]
88
pub struct GraphHasher {
99
aliases: BTreeMap<String, String>,
1010

1111
configs: BTreeMap<String, String>,
1212

1313
sources: BTreeMap<String, String>,
14+
15+
// Version of the moon CLI. We need to include this so that the graph
16+
// cache is invalidated between each release, otherwise internal Rust
17+
// changes (in project or task crates) are not reflected until the cache
18+
// is invalidated, which puts the program in a weird state.
19+
version: String,
1420
}
1521

1622
impl GraphHasher {
23+
pub fn new() -> Self {
24+
GraphHasher {
25+
aliases: BTreeMap::default(),
26+
configs: BTreeMap::default(),
27+
sources: BTreeMap::default(),
28+
version: env::var("MOON_VERSION").unwrap_or_default(),
29+
}
30+
}
31+
1732
pub fn hash_aliases(&mut self, aliases: &ProjectsAliasesMap) {
1833
self.aliases.extend(aliases.to_owned());
1934
}
@@ -32,6 +47,7 @@ impl Hasher for GraphHasher {
3247
hash_btree(&self.aliases, sha);
3348
hash_btree(&self.configs, sha);
3449
hash_btree(&self.sources, sha);
50+
sha.update(self.version.as_bytes());
3551
}
3652

3753
fn serialize(&self) -> serde_json::Value {

crates/core/project-graph/src/project_builder.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ impl<'ws> ProjectGraphBuilder<'ws> {
556556
return Ok(String::new());
557557
}
558558

559-
let mut hasher = GraphHasher::default();
559+
let mut hasher = GraphHasher::new();
560560

561561
// Hash aliases and sources as-is as they're very explicit
562562
hasher.hash_aliases(aliases);
@@ -574,6 +574,7 @@ impl<'ws> ProjectGraphBuilder<'ws> {
574574
&self.workspace.root,
575575
)?;
576576

577+
// Hash project-level config (moon.yml)
577578
let config_hashes = self
578579
.workspace
579580
.vcs
@@ -583,6 +584,7 @@ impl<'ws> ProjectGraphBuilder<'ws> {
583584

584585
hasher.hash_configs(&config_hashes);
585586

587+
// Hash workspace-level configs (entire .moon folder)
586588
let config_hashes = self
587589
.workspace
588590
.vcs

packages/cli/CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
- Fixed an issue where hashing would attempt to hash a directory and crash.
88
- Fixed an issue where attempting to hash a large number of files (think 10,000) would hang.
99
- Fixed an issue where offline checks would take longer than expected.
10+
- Fixed an issue where the project graph cache would not invalidate when Rust internals have
11+
changed.
1012

1113
## 0.25.1
1214

0 commit comments

Comments
 (0)