Skip to content

Commit f794329

Browse files
authored
feat: skip breaking changes notification with env var (#659)
* feat: skip breaking changes notification with env var * ci: apply that env in ci
1 parent f9a35c7 commit f794329

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

.github/workflows/test-config-creation.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ jobs:
1717
CONFIG_PATH=~/.config/topgrade.toml;
1818
if [ -f "$CONFIG_PATH" ]; then rm $CONFIG_PATH; fi
1919
cargo build;
20-
./target/debug/topgrade --dry-run --only system;
20+
TOPGRADE_SKIP_BRKC_NOTIFY=true ./target/debug/topgrade --dry-run --only system;
2121
stat $CONFIG_PATH;

src/breaking_changes.rs

+11
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use crate::XDG_DIRS;
1212
use color_eyre::eyre::Result;
1313
use etcetera::base_strategy::BaseStrategy;
1414
use std::{
15+
env::var,
1516
fs::{read_to_string, OpenOptions},
1617
io::Write,
1718
path::PathBuf,
@@ -89,6 +90,16 @@ fn keep_file_path() -> PathBuf {
8990
data_dir().join(keep_file)
9091
}
9192

93+
/// If environment variable `TOPGRADE_SKIP_BRKC_NOTIFY` is set to `true`, then
94+
/// we won't notify the user of the breaking changes.
95+
pub(crate) fn should_skip() -> bool {
96+
if let Ok(var) = var("TOPGRADE_SKIP_BRKC_NOTIFY") {
97+
return var.as_str() == "true";
98+
}
99+
100+
false
101+
}
102+
92103
/// True if this is the first execution of a major release.
93104
pub(crate) fn first_run_of_major_release() -> Result<bool> {
94105
let version = VERSION_STR.parse::<Version>().expect("should be a valid version");

src/main.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::path::PathBuf;
66
use std::process::exit;
77
use std::time::Duration;
88

9-
use crate::breaking_changes::{first_run_of_major_release, print_breaking_changes, write_keep_file};
9+
use crate::breaking_changes::{first_run_of_major_release, print_breaking_changes, should_skip, write_keep_file};
1010
use clap::CommandFactory;
1111
use clap::{crate_version, Parser};
1212
use color_eyre::eyre::Context;
@@ -135,9 +135,13 @@ fn run() -> Result<()> {
135135
let ctx = execution_context::ExecutionContext::new(run_type, sudo, &git, &config);
136136
let mut runner = runner::Runner::new(&ctx);
137137

138-
// If this is the first execution of a major release, inform user of breaking
139-
// changes
140-
if first_run_of_major_release()? {
138+
// If
139+
//
140+
// 1. the breaking changes notification shouldnot be skipped
141+
// 2. this is the first execution of a major release
142+
//
143+
// inform user of breaking changes
144+
if !should_skip() && first_run_of_major_release()? {
141145
print_breaking_changes();
142146

143147
if prompt_yesno("Confirmed?")? {

0 commit comments

Comments
 (0)