Skip to content
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

chore(vdev): Rewrite scripts in vdev #16661

Merged
merged 15 commits into from
Mar 9, 2023
Merged
Show file tree
Hide file tree
Changes from 7 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
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ jobs:
- uses: actions/checkout@v3
- run: sudo -E bash scripts/environment/bootstrap-ubuntu-20.04.sh
- run: bash scripts/environment/prepare.sh
- run: make test-vrl
- run: cargo vdev test-vrl

test-vrl-wasm:
name: VRL WASM - Linux
Expand Down
22 changes: 0 additions & 22 deletions scripts/check-component-docs.sh

This file was deleted.

12 changes: 0 additions & 12 deletions scripts/install-git-hooks.sh

This file was deleted.

16 changes: 0 additions & 16 deletions scripts/release-github.sh

This file was deleted.

3 changes: 2 additions & 1 deletion scripts/signoff-git-hook.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/bin/bash
jonathanpv marked this conversation as resolved.
Show resolved Hide resolved
set -euo pipefail

# Automatically signs off your commits.
# Used by vdev/src/commands/install_git_hooks.rs to
# automatically sign off your commits.
jonathanpv marked this conversation as resolved.
Show resolved Hide resolved
#
# Installation:
#
Expand Down
14 changes: 0 additions & 14 deletions scripts/test-vrl.sh

This file was deleted.

34 changes: 34 additions & 0 deletions vdev/src/commands/check/component_docs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use anyhow::{Result, Ok};
use std::process::Command;
use crate::app::CommandExt as _;


/// Check that component documentation is up-to-date
#[derive(clap::Args, Debug)]
#[command()]
pub struct Cli {}

impl Cli {
#[allow(clippy::dbg_macro)]
jonathanpv marked this conversation as resolved.
Show resolved Hide resolved
pub fn exec(self) -> Result<()> {
let args = vec!["ls-files", "--full-name", "--modified", "--others", "--exclude-standard"];
let mut command = Command::new("git");
command.in_repo();
let files: Vec<String> = command.args(args).capture_output()?.lines().map(str::to_owned).collect();
jonathanpv marked this conversation as resolved.
Show resolved Hide resolved
let dirty_component_files: Vec<String> = files
.iter()
.filter(|file| file.contains("website/cue/reference/components"))
jonathanpv marked this conversation as resolved.
Show resolved Hide resolved
.map(|file| format!(" - {file}"))
jonathanpv marked this conversation as resolved.
Show resolved Hide resolved
.collect();

// If it is not empty, there are out-of-sync component Cue files in the current branch.
if !dirty_component_files.is_empty() {
println!("Found out-of-sync component Cue files in this branch:");
println!("{}", dirty_component_files.join("\n"));
jonathanpv marked this conversation as resolved.
Show resolved Hide resolved
println!("Run `make generate-component-docs` locally to update your branch and commit/push the changes.");
std::process::exit(1);
}

Ok(())
}
}
7 changes: 1 addition & 6 deletions vdev/src/commands/check/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
crate::cli_subcommands! {
"Check parts of the Vector code base..."
component_docs,
mod component_docs,
mod component_features,
mod deny,
docs,
Expand All @@ -15,11 +15,6 @@ crate::cli_subcommands! {

// These should eventually be migrated to Rust code

crate::script_wrapper! {
component_docs = "Check that component documentation is up-to-date"
=> "check-component-docs.sh"
}

crate::script_wrapper! {
docs = "Check that all /docs files are valid"
=> "check-docs.sh"
Expand Down
40 changes: 40 additions & 0 deletions vdev/src/commands/install_git_hooks.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use anyhow::{Result, Ok};
jonathanpv marked this conversation as resolved.
Show resolved Hide resolved
use std::process::Command;
use crate::git;
use crate::app::CommandExt as _;
// use std::{env, path::PathBuf};
jonathanpv marked this conversation as resolved.
Show resolved Hide resolved

/// Install a Git commit message hook that verifies
/// that all commits have been signed off.
#[derive(clap::Args, Debug)]
#[command()]
pub struct Cli {
/// The mode argument. Can be used to control which hook(s) are installed,
/// with the default being to install all available hooks.
mode: Option<String>
jonathanpv marked this conversation as resolved.
Show resolved Hide resolved
}

impl Cli {
pub fn exec(self) -> Result<()> {
let mode = self.mode.unwrap_or_else(|| "all".to_string());
let git_dir = git::get_git_dir()?;

// Create a new directory named hooks in the .git directory if it
// doesn't already exist.
let mut command = Command::new("mkdir");
command.in_repo();
command.args(["-p", &format!("{git_dir}/hooks")]);

command.check_run()?;

// Copy the script scripts/signoff-git-hook.sh to the
// .git/hooks/commit-msg file
if mode == "all" || mode == "signoff" {
jonathanpv marked this conversation as resolved.
Show resolved Hide resolved
command = Command::new("cp");
command.args(["scripts/signoff-git-hook.sh", &format!("{git_dir}/hooks/commit-msg")]);
command.check_run()?;
jonathanpv marked this conversation as resolved.
Show resolved Hide resolved
println!("Copied scripts/signoff-git-hook.sh to {git_dir}/hooks/commit-msg");
}
Ok(())
}
}
2 changes: 2 additions & 0 deletions vdev/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,14 @@ cli_commands! {
mod generate,
mod info,
mod integration,
mod install_git_hooks,
mod meta,
mod package,
mod release,
mod run,
mod status,
mod test,
mod test_vrl,
mod version,
}

Expand Down
31 changes: 31 additions & 0 deletions vdev/src/commands/release/github.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use anyhow::{Result, Ok};
use std::process::Command;
use std::env;
use crate::app::CommandExt as _;
use crate::util;

/// Uploads target/artifacts to GitHub releases
#[derive(clap::Args, Debug)]
#[command()]
pub struct Cli {
}

impl Cli {
pub fn exec(self) -> Result<()> {
let version = env::var("VECTOR_VERSION").or_else(|_| util::read_version())?;
let mut command = Command::new("gh");
command.in_repo();
command.args(["release",
"--repo",
"vectordotdev/vector",
"create",
&format!("v{version}"),
"--title",
&format!("v{version}"),
"--notes",
&format!("[View release notes](https://vector.dev/releases/{version})"),
"target/artifacts/*"]);
command.check_run()?;
Ok(())
}
}
6 changes: 1 addition & 5 deletions vdev/src/commands/release/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ crate::cli_subcommands! {
mod channel,
commit,
docker,
github,
mod github,
homebrew,
mod prepare,
push,
Expand All @@ -23,10 +23,6 @@ crate::script_wrapper! {
docker = "Build the Vector docker images and optionally push it to the registry"
=> "build-docker.sh"
}
crate::script_wrapper! {
github = "Determine the appropriate release channel (nightly or latest) based on Git HEAD"
=> "release-github.sh"
}
crate::script_wrapper! {
homebrew = "Releases latest version to the vectordotdev homebrew tap"
=> "release-homebrew.sh"
Expand Down
23 changes: 23 additions & 0 deletions vdev/src/commands/test_vrl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use anyhow::{Context as _, Result};

use crate::{app};
use std::{env, path::PathBuf};

/// Run the Vector Remap Language test suite
#[derive(clap::Args, Debug)]
#[command()]
pub struct Cli {}

impl Cli {
pub fn exec(self) -> Result<()> {
let path: PathBuf = [app::path(), "lib", "vrl", "tests"].into_iter().collect();
env::set_current_dir(path).context("Could not change directory")?;

#[allow(clippy::case_sensitive_file_extension_comparisons)]
jonathanpv marked this conversation as resolved.
Show resolved Hide resolved
app::exec(
"cargo",
["run", "--", "--runtime=ast"].into_iter(),
jonathanpv marked this conversation as resolved.
Show resolved Hide resolved
false,
)
}
}
6 changes: 6 additions & 0 deletions vdev/src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ pub fn list_files() -> Result<Vec<String>> {
.collect())
}

// Gets path of the current Git repository's .git directory by the git rev-parse --git-dir command.
pub fn get_git_dir() -> Result<String> {
let output = capture_output(&["rev-parse", "--git-dir"])?;
Ok(output.trim_end().to_string())
}
jonathanpv marked this conversation as resolved.
Show resolved Hide resolved

fn capture_output(args: &[&str]) -> Result<String> {
Command::new("git").in_repo().args(args).capture_output()
}
Expand Down