Vagrant boxes (#905)

This commit is contained in:
Roey Darwish Dror 2022-04-23 15:09:54 +03:00 committed by GitHub
parent 020a0619b8
commit 14809322b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 91 additions and 1 deletions

46
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,46 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug executable 'topgrade'",
"console": "integratedTerminal",
"cargo": {
"args": [
"build",
"--bin=topgrade",
"--package=topgrade"
],
"filter": {
"name": "topgrade",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in executable 'topgrade'",
"cargo": {
"args": [
"test",
"--no-run",
"--bin=topgrade",
"--package=topgrade"
],
"filter": {
"name": "topgrade",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
}
]
}

View File

@ -21,5 +21,15 @@
"body": [
"return Err(SkipStep(format!(\"$1\").into()));"
]
},
"Step": {
"scope": "rust",
"prefix": "step",
"body": [
"pub fn $1(ctx: &ExecutionContext) -> Result<()> {",
" $0",
" Ok(())",
"}"
]
}
}
}

View File

@ -392,6 +392,7 @@ fn run() -> Result<()> {
}
}
}
runner.execute(Step::Vagrant, "Vagrant boxes", || vagrant::upgrade_vagrant_boxes(&ctx))?;
if !runner.report().data().is_empty() {
print_separator("Summary");

View File

@ -4,6 +4,7 @@ use std::{fmt::Display, rc::Rc, str::FromStr};
use anyhow::Result;
use log::{debug, error};
use regex::Regex;
use strum::EnumString;
use crate::execution_context::ExecutionContext;
@ -200,3 +201,35 @@ pub fn topgrade_vagrant_box(ctx: &ExecutionContext, vagrant_box: &VagrantBox) ->
.args(&["ssh", "-c", &command])
.check_run()
}
pub fn upgrade_vagrant_boxes(ctx: &ExecutionContext) -> Result<()> {
let vagrant = utils::require("vagrant")?;
print_separator("Vagrant boxes");
let outdated = Command::new(&vagrant)
.args(&["box", "outdated", "--global"])
.check_output()?;
let re = Regex::new(r"\* '(.*?)' for '(.*?)' is outdated").unwrap();
let mut found = false;
for ele in re.captures_iter(&outdated) {
found = true;
let _ = ctx
.run_type()
.execute(&vagrant)
.args(&["box", "update", "--box"])
.arg(&ele.get(1).unwrap().as_str())
.arg("--provider")
.arg(ele.get(2).unwrap().as_str())
.check_run();
}
if !found {
println!("No outdated boxes")
} else {
ctx.run_type().execute(&vagrant).args(&["box", "prune"]).check_run()?;
}
Ok(())
}