diff --git a/.github/workflows/test-config-creation.yml b/.github/workflows/test-config-creation.yml index 58c7b8dd..cbada83b 100644 --- a/.github/workflows/test-config-creation.yml +++ b/.github/workflows/test-config-creation.yml @@ -17,5 +17,5 @@ jobs: CONFIG_PATH=~/.config/topgrade.toml; if [ -f "$CONFIG_PATH" ]; then rm $CONFIG_PATH; fi cargo build; - ./target/debug/topgrade --dry-run --only system; + TOPGRADE_SKIP_BRKC_NOTIFY=true ./target/debug/topgrade --dry-run --only system; stat $CONFIG_PATH; diff --git a/src/breaking_changes.rs b/src/breaking_changes.rs index 965c2e69..520db396 100644 --- a/src/breaking_changes.rs +++ b/src/breaking_changes.rs @@ -12,6 +12,7 @@ use crate::XDG_DIRS; use color_eyre::eyre::Result; use etcetera::base_strategy::BaseStrategy; use std::{ + env::var, fs::{read_to_string, OpenOptions}, io::Write, path::PathBuf, @@ -89,6 +90,16 @@ fn keep_file_path() -> PathBuf { data_dir().join(keep_file) } +/// If environment variable `TOPGRADE_SKIP_BRKC_NOTIFY` is set to `true`, then +/// we won't notify the user of the breaking changes. +pub(crate) fn should_skip() -> bool { + if let Ok(var) = var("TOPGRADE_SKIP_BRKC_NOTIFY") { + return var.as_str() == "true"; + } + + false +} + /// True if this is the first execution of a major release. pub(crate) fn first_run_of_major_release() -> Result { let version = VERSION_STR.parse::().expect("should be a valid version"); diff --git a/src/main.rs b/src/main.rs index 8153a32e..de478ad1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,7 @@ use std::path::PathBuf; use std::process::exit; use std::time::Duration; -use crate::breaking_changes::{first_run_of_major_release, print_breaking_changes, write_keep_file}; +use crate::breaking_changes::{first_run_of_major_release, print_breaking_changes, should_skip, write_keep_file}; use clap::CommandFactory; use clap::{crate_version, Parser}; use color_eyre::eyre::Context; @@ -135,9 +135,13 @@ fn run() -> Result<()> { let ctx = execution_context::ExecutionContext::new(run_type, sudo, &git, &config); let mut runner = runner::Runner::new(&ctx); - // If this is the first execution of a major release, inform user of breaking - // changes - if first_run_of_major_release()? { + // If + // + // 1. the breaking changes notification shouldnot be skipped + // 2. this is the first execution of a major release + // + // inform user of breaking changes + if !should_skip() && first_run_of_major_release()? { print_breaking_changes(); if prompt_yesno("Confirmed?")? {