Skip to content

Commit 2d64f35

Browse files
Changelog support (#32)
## Summary Resolves #15 ## Test Plan Added some cli tests but mostly added tests to new crate to snapshot our changelog output after resolving PRs etc
1 parent a6f560c commit 2d64f35

24 files changed

Lines changed: 2984 additions & 432 deletions

File tree

Cargo.lock

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

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ license = "MIT"
1212

1313
[workspace.dependencies]
1414
seal_bump = { path = "crates/seal_bump" }
15+
seal_changelog = { path = "crates/seal_changelog" }
1516
seal_cli = { path = "crates/seal_cli" }
17+
seal_file_change = { path = "crates/seal_file_change" }
1618
seal_macros = { path = "crates/seal_macros" }
1719
seal_options_metadata = { path = "crates/seal_options_metadata" }
1820
seal_project = { path = "crates/seal_project" }
@@ -29,6 +31,7 @@ glob = { version = "0.3.3" }
2931
insta = { version = "1.41", features = ["filters", "json"] }
3032
itertools = { version = "0.14.0" }
3133
markdown = { version = "1.0.0-alpha.23" }
34+
octocrab = { version = "0.43" }
3235
owo-colors = { version = "4.1.0" }
3336
pretty_assertions = { version = "1.4.1" }
3437
proc-macro2 = { version = "1.0.86" }
@@ -42,6 +45,7 @@ syn = { version = "2.0.77" }
4245
tempfile = { version = "3.14" }
4346
textwrap = { version = "0.16.1" }
4447
thiserror = { version = "2.0" }
48+
tokio = { version = "1", features = ["rt", "macros"] }
4549
toml = { version = "0.9" }
4650
which = { version = "8.0.0" }
4751

crates/seal/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ default-run = "seal"
1111

1212
[dependencies]
1313
seal_bump = { workspace = true }
14+
seal_changelog = { workspace = true }
1415
seal_cli = { workspace = true }
1516
seal_project = { workspace = true }
1617
seal_version = { workspace = true }
@@ -25,6 +26,7 @@ owo-colors = { workspace = true }
2526
regex = { workspace = true }
2627
serde = { workspace = true, features = ["derive"] }
2728
serde_json = { workspace = true }
29+
tokio = { version = "1", features = ["rt", "macros"] }
2830
which = { workspace = true }
2931

3032
[dev-dependencies]

crates/seal/src/commands/bump.rs

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,39 @@ pub fn bump(args: &BumpArgs, printer: Printer) -> Result<ExitStatus> {
7979
change.display_diff(&mut stdout)?;
8080
}
8181

82+
let changelog_changes = if !args.no_changelog {
83+
if let Some(changelog_config) = config.changelog.as_ref() {
84+
match seal_changelog::prepare_changelog_changes(
85+
workspace.root(),
86+
&new_version_string,
87+
changelog_config,
88+
) {
89+
Ok(changes) => {
90+
for change in &changes {
91+
change.display_diff(&mut stdout)?;
92+
}
93+
Some(changes)
94+
}
95+
Err(e) => {
96+
writeln!(stdout, "Warning: Failed to prepare changelog: {e}")?;
97+
None
98+
}
99+
}
100+
} else {
101+
writeln!(
102+
stdout,
103+
"Skipping changelog update because no `[changelog]` section was found in the configuration."
104+
)?;
105+
None
106+
}
107+
} else {
108+
writeln!(
109+
stdout,
110+
"Skipping changelog update because `--no-changelog` was provided."
111+
)?;
112+
None
113+
};
114+
82115
writeln!(stdout)?;
83116

84117
let has_git_operations = branch_name.is_some() || commit_message.is_some();
@@ -87,6 +120,11 @@ pub fn bump(args: &BumpArgs, printer: Printer) -> Result<ExitStatus> {
87120
for change in &changes {
88121
writeln!(stdout, " - Update `{}`", change.path().display())?;
89122
}
123+
if let Some(ref changelog) = changelog_changes {
124+
for change in changelog {
125+
writeln!(stdout, " - Update `{}`", change.path().display())?;
126+
}
127+
}
90128
writeln!(stdout)?;
91129

92130
if has_git_operations {
@@ -140,7 +178,12 @@ pub fn bump(args: &BumpArgs, printer: Printer) -> Result<ExitStatus> {
140178
}
141179

142180
writeln!(stdout, "Updating version files...")?;
143-
changes.apply(workspace.root())?;
181+
changes.apply()?;
182+
183+
if let Some(changelog) = changelog_changes {
184+
writeln!(stdout, "Updating changelog...")?;
185+
changelog.apply()?;
186+
}
144187

145188
if let Some(message) = &commit_message {
146189
writeln!(stdout, "Committing changes...")?;
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
use assert_fs::prelude::*;
2+
3+
use crate::{common::TestContext, seal_snapshot};
4+
5+
#[test]
6+
fn bump_no_changelog_changes_when_no_changelog_option() {
7+
let context = TestContext::new();
8+
context.seal_toml(
9+
r#"
10+
[release]
11+
current-version = "1.0.0"
12+
version-files = ["Cargo.toml"]
13+
commit-message = "Release v{version}"
14+
branch-name = "release/v{version}"
15+
push = false
16+
create-pr = false
17+
confirm = false
18+
19+
[changelog]
20+
ignore-labels = ["internal", "ci"]
21+
"#,
22+
);
23+
context.init_git();
24+
25+
context
26+
.root
27+
.child("Cargo.toml")
28+
.write_str(
29+
r#"[package]
30+
name = "test"
31+
version = "1.0.0"
32+
"#,
33+
)
34+
.unwrap();
35+
36+
seal_snapshot!(context.filters(), context.command().arg("bump").arg("patch").arg("--no-changelog"), @r#"
37+
success: true
38+
exit_code: 0
39+
----- stdout -----
40+
Bumping version from 1.0.0 to 1.0.1
41+
42+
Preview of changes:
43+
-------------------
44+
45+
diff --git a[TEMP]/Cargo.toml b[TEMP]/Cargo.toml
46+
--- a[TEMP]/Cargo.toml
47+
+++ b[TEMP]/Cargo.toml
48+
@@ -1,3 +1,3 @@
49+
[package]
50+
name = "test"
51+
-version = "1.0.0"
52+
+version = "1.0.1"
53+
54+
diff --git a[TEMP]/seal.toml b[TEMP]/seal.toml
55+
--- a[TEMP]/seal.toml
56+
+++ b[TEMP]/seal.toml
57+
@@ -1,5 +1,5 @@
58+
[release]
59+
-current-version = "1.0.0"
60+
+current-version = "1.0.1"
61+
version-files = ["Cargo.toml"]
62+
commit-message = "Release v{version}"
63+
branch-name = "release/v{version}"
64+
Skipping changelog update because `--no-changelog` was provided.
65+
66+
Changes to be made:
67+
- Update `[TEMP]/Cargo.toml`
68+
- Update `[TEMP]/seal.toml`
69+
70+
Commands to be executed:
71+
`git checkout -b release/v1.0.1`
72+
`git add -A`
73+
`git commit -m "Release v1.0.1"`
74+
75+
Creating branch: release/v1.0.1
76+
Updating version files...
77+
Committing changes...
78+
Successfully bumped to 1.0.1
79+
80+
----- stderr -----
81+
"#);
82+
}
83+
84+
#[test]
85+
fn bump_without_changelog_skips_generation() {
86+
let context = TestContext::new();
87+
context.seal_toml(
88+
r#"
89+
[release]
90+
current-version = "1.0.0"
91+
version-files = ["Cargo.toml"]
92+
confirm = false
93+
"#,
94+
);
95+
context.init_git();
96+
97+
context
98+
.root
99+
.child("Cargo.toml")
100+
.write_str(
101+
r#"[package]
102+
name = "test"
103+
version = "1.0.0"
104+
"#,
105+
)
106+
.unwrap();
107+
108+
seal_snapshot!(context.filters(), context.command().arg("bump").arg("patch"), @r#"
109+
success: true
110+
exit_code: 0
111+
----- stdout -----
112+
Bumping version from 1.0.0 to 1.0.1
113+
114+
Preview of changes:
115+
-------------------
116+
117+
diff --git a[TEMP]/Cargo.toml b[TEMP]/Cargo.toml
118+
--- a[TEMP]/Cargo.toml
119+
+++ b[TEMP]/Cargo.toml
120+
@@ -1,3 +1,3 @@
121+
[package]
122+
name = "test"
123+
-version = "1.0.0"
124+
+version = "1.0.1"
125+
126+
diff --git a[TEMP]/seal.toml b[TEMP]/seal.toml
127+
--- a[TEMP]/seal.toml
128+
+++ b[TEMP]/seal.toml
129+
@@ -1,4 +1,4 @@
130+
[release]
131+
-current-version = "1.0.0"
132+
+current-version = "1.0.1"
133+
version-files = ["Cargo.toml"]
134+
confirm = false
135+
Skipping changelog update because no `[changelog]` section was found in the configuration.
136+
137+
Changes to be made:
138+
- Update `[TEMP]/Cargo.toml`
139+
- Update `[TEMP]/seal.toml`
140+
141+
Note: No branch or commit will be created (branch-name and commit-message not configured)
142+
143+
Updating version files...
144+
Successfully bumped to 1.0.1
145+
Note: No git branch or commit was created
146+
147+
----- stderr -----
148+
"#);
149+
}

crates/seal/tests/it/bump/confirmation.rs

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,28 +39,29 @@ version = "1.0.0"
3939
Preview of changes:
4040
-------------------
4141
42-
diff --git a/Cargo.toml b/Cargo.toml
43-
--- a/Cargo.toml
44-
+++ b/Cargo.toml
42+
diff --git a[TEMP]/Cargo.toml b[TEMP]/Cargo.toml
43+
--- a[TEMP]/Cargo.toml
44+
+++ b[TEMP]/Cargo.toml
4545
@@ -1,3 +1,3 @@
4646
[package]
4747
name = "test"
4848
-version = "1.0.0"
4949
+version = "1.0.1"
5050
51-
diff --git a/[TEMP]/seal.toml b/[TEMP]/seal.toml
52-
--- a/[TEMP]/seal.toml
53-
+++ b/[TEMP]/seal.toml
51+
diff --git a[TEMP]/seal.toml b[TEMP]/seal.toml
52+
--- a[TEMP]/seal.toml
53+
+++ b[TEMP]/seal.toml
5454
@@ -1,5 +1,5 @@
5555
[release]
5656
-current-version = "1.0.0"
5757
+current-version = "1.0.1"
5858
version-files = ["Cargo.toml"]
5959
commit-message = "Release v{version}"
6060
branch-name = "release/v{version}"
61+
Skipping changelog update because no `[changelog]` section was found in the configuration.
6162
6263
Changes to be made:
63-
- Update `Cargo.toml`
64+
- Update `[TEMP]/Cargo.toml`
6465
- Update `[TEMP]/seal.toml`
6566
6667
Commands to be executed:
@@ -136,28 +137,29 @@ version = "1.0.0"
136137
Preview of changes:
137138
-------------------
138139
139-
diff --git a/Cargo.toml b/Cargo.toml
140-
--- a/Cargo.toml
141-
+++ b/Cargo.toml
140+
diff --git a[TEMP]/Cargo.toml b[TEMP]/Cargo.toml
141+
--- a[TEMP]/Cargo.toml
142+
+++ b[TEMP]/Cargo.toml
142143
@@ -1,3 +1,3 @@
143144
[package]
144145
name = "test"
145146
-version = "1.0.0"
146147
+version = "1.0.1"
147148
148-
diff --git a/[TEMP]/seal.toml b/[TEMP]/seal.toml
149-
--- a/[TEMP]/seal.toml
150-
+++ b/[TEMP]/seal.toml
149+
diff --git a[TEMP]/seal.toml b[TEMP]/seal.toml
150+
--- a[TEMP]/seal.toml
151+
+++ b[TEMP]/seal.toml
151152
@@ -1,5 +1,5 @@
152153
[release]
153154
-current-version = "1.0.0"
154155
+current-version = "1.0.1"
155156
version-files = ["Cargo.toml"]
156157
commit-message = "Release v{version}"
157158
branch-name = "release/v{version}"
159+
Skipping changelog update because no `[changelog]` section was found in the configuration.
158160
159161
Changes to be made:
160-
- Update `Cargo.toml`
162+
- Update `[TEMP]/Cargo.toml`
161163
- Update `[TEMP]/seal.toml`
162164
163165
Commands to be executed:
@@ -231,28 +233,29 @@ version = "1.0.0"
231233
Preview of changes:
232234
-------------------
233235
234-
diff --git a/Cargo.toml b/Cargo.toml
235-
--- a/Cargo.toml
236-
+++ b/Cargo.toml
236+
diff --git a[TEMP]/Cargo.toml b[TEMP]/Cargo.toml
237+
--- a[TEMP]/Cargo.toml
238+
+++ b[TEMP]/Cargo.toml
237239
@@ -1,3 +1,3 @@
238240
[package]
239241
name = "test"
240242
-version = "1.0.0"
241243
+version = "1.0.1"
242244
243-
diff --git a/[TEMP]/seal.toml b/[TEMP]/seal.toml
244-
--- a/[TEMP]/seal.toml
245-
+++ b/[TEMP]/seal.toml
245+
diff --git a[TEMP]/seal.toml b[TEMP]/seal.toml
246+
--- a[TEMP]/seal.toml
247+
+++ b[TEMP]/seal.toml
246248
@@ -1,5 +1,5 @@
247249
[release]
248250
-current-version = "1.0.0"
249251
+current-version = "1.0.1"
250252
version-files = ["Cargo.toml"]
251253
commit-message = "Release v{version}"
252254
branch-name = "release/v{version}"
255+
Skipping changelog update because no `[changelog]` section was found in the configuration.
253256
254257
Changes to be made:
255-
- Update `Cargo.toml`
258+
- Update `[TEMP]/Cargo.toml`
256259
- Update `[TEMP]/seal.toml`
257260
258261
Commands to be executed:

0 commit comments

Comments
 (0)