Skip to content

chore: dont update ide settings in CI #306

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

Merged
merged 1 commit into from
Feb 22, 2025
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: 2 additions & 2 deletions crates/xtask/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ WORKDIR /usr/src/app

COPY . .

RUN cargo build --profile ephemeral-build
RUN cargo xtask init
RUN cargo xtask init --update-ide false
RUN cargo xtask build
78 changes: 45 additions & 33 deletions crates/xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,12 @@ impl App {
Xtasks::Macros { macro_name } => {
cmd.arg("macros").arg(macro_name.as_ref());
}
Xtasks::Init => {
cmd.arg("init");
Xtasks::Init { dont_update_ide } => {
let arg = cmd.arg("init");

if dont_update_ide {
arg.arg("--dont-update-ide");
}
}
Xtasks::Build => {
cmd.arg("build");
Expand Down Expand Up @@ -486,7 +490,11 @@ enum Xtasks {
macro_name: Macro,
},
/// Performs first time local-development environment setup
Init,
Init {
/// Prevents updating the IDE settings, defaults to false
#[clap(long, default_value = "false")]
dont_update_ide: bool,
},
/// Build the main workspace only
Build,
/// Build the main workspace, apply all prefferred lints
Expand Down Expand Up @@ -583,7 +591,7 @@ impl Xtasks {
Xtasks::Docs { open, no_rust_docs } => Self::docs(app_settings, open, no_rust_docs),
Xtasks::Test { name, package } => Self::test(app_settings, package, name),
Xtasks::CiCheck => Self::cicd(app_settings),
Xtasks::Init => Self::init(app_settings),
Xtasks::Init { dont_update_ide } => Self::init(app_settings, dont_update_ide),
Xtasks::Macros { macro_name } => match macro_name {
Macro::ScriptTests => {
let mut settings = app_settings.clone();
Expand Down Expand Up @@ -1290,7 +1298,7 @@ impl Xtasks {
Ok(())
}

fn init(app_settings: GlobalArgs) -> Result<()> {
fn init(app_settings: GlobalArgs, dont_update_ide: bool) -> Result<()> {
// install cargo mdbook
Self::run_system_command(
&app_settings,
Expand Down Expand Up @@ -1350,34 +1358,38 @@ impl Xtasks {

// create .vscode settings
// read from templates at compile time
let vscode_settings = include_str!("../templates/settings.json.tera");
let mut tera = tera::Tera::default();
let mut context = tera::Context::new();
let workspace_dir = Self::workspace_dir(&app_settings)?;
let json_workspace_dir = serde_json::to_string(&workspace_dir)?; // make sure this works as a json string
context.insert("dir", &json_workspace_dir.trim_matches('\"'));

let templated_settings = tera.render_str(vscode_settings, &context)?;
let templated_settings_json = Self::read_json_with_comments(templated_settings.as_bytes())
.with_context(|| "reading templated vscode settings")?;
let vscode_dir = Self::relative_workspace_dir(&app_settings, ".vscode")?;
std::fs::create_dir_all(&vscode_dir)?;
let vscode_settings_path = vscode_dir.join("settings.json");

// if the file already exists, merge the settings otherwise create it
info!(
"Merging vscode settings at {:?}. With overrides generated by template.",
vscode_settings_path
);
if vscode_settings_path.exists() {
let existing_settings = std::fs::read_to_string(&vscode_settings_path)?;
let mut existing_settings = Self::read_json_with_comments(existing_settings.as_bytes())
.with_context(|| "reading existing vscode settings file")?;
Self::merge_json(templated_settings_json, &mut existing_settings);
let merged_settings = serde_json::to_string_pretty(&existing_settings)?;
std::fs::write(&vscode_settings_path, merged_settings)?;
} else {
std::fs::write(&vscode_settings_path, templated_settings)?;
if !dont_update_ide {
let vscode_settings = include_str!("../templates/settings.json.tera");
let mut tera = tera::Tera::default();
let mut context = tera::Context::new();
let workspace_dir = Self::workspace_dir(&app_settings)?;
let json_workspace_dir = serde_json::to_string(&workspace_dir)?; // make sure this works as a json string
context.insert("dir", &json_workspace_dir.trim_matches('\"'));

let templated_settings = tera.render_str(vscode_settings, &context)?;
let templated_settings_json =
Self::read_json_with_comments(templated_settings.as_bytes())
.with_context(|| "reading templated vscode settings")?;
let vscode_dir = Self::relative_workspace_dir(&app_settings, ".vscode")?;
std::fs::create_dir_all(&vscode_dir)?;
let vscode_settings_path = vscode_dir.join("settings.json");

// if the file already exists, merge the settings otherwise create it
info!(
"Merging vscode settings at {:?}. With overrides generated by template.",
vscode_settings_path
);
if vscode_settings_path.exists() {
let existing_settings = std::fs::read_to_string(&vscode_settings_path)?;
let mut existing_settings =
Self::read_json_with_comments(existing_settings.as_bytes())
.with_context(|| "reading existing vscode settings file")?;
Self::merge_json(templated_settings_json, &mut existing_settings);
let merged_settings = serde_json::to_string_pretty(&existing_settings)?;
std::fs::write(&vscode_settings_path, merged_settings)?;
} else {
std::fs::write(&vscode_settings_path, templated_settings)?;
}
}

Ok(())
Expand Down
Loading