From 98cb397ea9d9ad612939d85edb5fb569526d3dc0 Mon Sep 17 00:00:00 2001 From: kjuulh Date: Sun, 18 Dec 2022 20:05:49 +0100 Subject: [PATCH] add releaser --- .github/workflows/release.yml | 108 +++++++++++++++++++++++++++++++ LICENSE | 0 README.md | 1 + crates/github/src/fuzzy_clone.rs | 32 +++++++-- man/.gitkeep | 0 src/init/fish.rs | 13 ++++ src/init/mod.rs | 20 ++++++ src/main.rs | 4 ++ 8 files changed, 174 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 LICENSE create mode 100644 README.md create mode 100644 man/.gitkeep create mode 100644 src/init/fish.rs create mode 100644 src/init/mod.rs diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..613c9a9 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,108 @@ +name: release +on: + push: + branches: + - main + - next + pull_request: + workflow_dispatch: + +env: + CARGO_INCREMENTAL: 0 + +jobs: + release: + name: ${{ matrix.target }} + permissions: + contents: write + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + include: + - os: ubuntu-latest + target: x86_64-unknown-linux-musl + deb: true + - os: ubuntu-latest + target: arm-unknown-linux-musleabihf + - os: ubuntu-latest + target: armv7-unknown-linux-musleabihf + - os: ubuntu-latest + target: aarch64-unknown-linux-musl + deb: true + + - os: macos-11 + target: x86_64-apple-darwin + - os: macos-11 + target: aarch64-apple-darwin + steps: + - name: Checkout repository + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Get version + id: get_version + run: sed -En 's/^version = "(.*)"/value=\1/p' Cargo.toml >> $GITHUB_OUTPUT + + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + override: true + target: ${{ matrix.target }} + + - name: Setup cache + uses: Swatinem/rust-cache@v1 + with: + key: ${{ matrix.target }} + + - name: Build binary + uses: actions-rs/cargo@v1 + with: + command: build + args: --release --locked --target=${{ matrix.target }} --color=always --verbose + use-cross: ${{ runner.os == 'Linux' }} + + - name: Install cargo-deb + if: ${{ matrix.deb == true }} + uses: actions-rs/install@v0.1 + with: + crate: cargo-deb + + - name: Build deb + if: ${{ matrix.deb == true }} + uses: actions-rs/cargo@v1 + with: + command: deb + args: --no-build --no-strip --output=. --target=${{ matrix.target }} + + - name: Package (*nix) + if: runner.os != 'Windows' + run: > + tar -cv + LICENSE README.md + man/ + -C target/${{ matrix.target }}/release/ toolkit + | gzip --best + > 'toolkit-${{ steps.get_version.outputs.value }}-${{ matrix.target }}.tar.gz' + - name: Upload artifact + uses: actions/upload-artifact@v2 + with: + name: ${{ matrix.target }} + path: | + *.deb + *.tar.gz + *.zip + - name: Create release + if: ${{ github.ref == 'refs/heads/main' && startsWith(github.event.head_commit.message, 'chore(release)') }} + uses: softprops/action-gh-release@v1 + with: + draft: true + files: | + *.deb + *.tar.gz + *.zip + name: ${{ steps.get_version.outputs.value }} + tag_name: "" diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..e69de29 diff --git a/README.md b/README.md new file mode 100644 index 0000000..56132a8 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# Toolkit diff --git a/crates/github/src/fuzzy_clone.rs b/crates/github/src/fuzzy_clone.rs index e3b768e..97caa84 100644 --- a/crates/github/src/fuzzy_clone.rs +++ b/crates/github/src/fuzzy_clone.rs @@ -1,5 +1,6 @@ use std::io::Write; +use clap::value_parser; use eyre::Context; pub struct FuzzyClone; @@ -201,13 +202,18 @@ impl FuzzyClone { }), )?; } else { - util::shell::run(&["git", "pull"], None)?; + util::shell::run( + &["git", "pull"], + Some(util::shell::RunOptions { + path: git_repo_path.clone(), + }), + )?; } Ok(git_repo_path) } - fn run() -> eyre::Result<()> { + fn run(print_dest: &bool) -> eyre::Result<()> { let settings = Self::get_settings()?; if settings.auto_update { println!("running auto update"); @@ -234,10 +240,17 @@ impl FuzzyClone { let chosen = util::shell::run_with_input_and_output(&["fzf"], entries_str)?; let chosen = std::str::from_utf8(&chosen.stdout)?; - Self::clone(GitHubEntry::from(chosen.to_string()).ok_or(eyre::anyhow!( + let path = Self::clone(GitHubEntry::from(chosen.to_string()).ok_or(eyre::anyhow!( "could not parse choice as github entry /" ))?)?; + if *print_dest { + print!( + "{}", + path.to_str().ok_or(eyre::anyhow!("path was not found"))? + ); + } + Ok(()) } @@ -255,13 +268,24 @@ impl util::Cmd for FuzzyClone { Ok(clap::Command::new("fuzzy-clone") .alias("fc") .alias("c") + .arg( + clap::Arg::new("print-dest") + .long("print-dest") + .value_name("print-dest") + .value_parser(value_parser!(bool)) + .num_args(0..=1) + .require_equals(true) + .default_missing_value("true"), + ) .subcommand(clap::Command::new("update"))) } fn exec(args: &clap::ArgMatches) -> eyre::Result<()> { + let print_dest = args.get_one::("print-dest").unwrap_or(&false); + match args.subcommand() { Some(("update", _)) => Self::update()?, - _ => Self::run()?, + _ => Self::run(print_dest)?, } Ok(()) diff --git a/man/.gitkeep b/man/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/init/fish.rs b/src/init/fish.rs new file mode 100644 index 0000000..fda48e7 --- /dev/null +++ b/src/init/fish.rs @@ -0,0 +1,13 @@ +pub struct Fish; + +impl util::Cmd for Fish { + fn cmd() -> eyre::Result { + let cmd = clap::Command::new("fish").subcommands(&[]); + + Ok(cmd) + } + + fn exec(args: &clap::ArgMatches) -> eyre::Result<()> { + Ok(()) + } +} diff --git a/src/init/mod.rs b/src/init/mod.rs new file mode 100644 index 0000000..658386a --- /dev/null +++ b/src/init/mod.rs @@ -0,0 +1,20 @@ +mod fish; + +pub struct Init; + +impl util::Cmd for Init { + fn cmd() -> eyre::Result { + let cmd = clap::Command::new("init") + .subcommands(&[fish::Fish::cmd()?]) + .subcommand_required(true); + + Ok(cmd) + } + + fn exec(args: &clap::ArgMatches) -> eyre::Result<()> { + match args.subcommand() { + Some(("fish", args)) => fish::Fish::exec(args), + _ => Err(eyre::anyhow!("missing command!")), + } + } +} diff --git a/src/main.rs b/src/main.rs index d761d58..4429d2a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ use util::Cmd; +mod init; mod prereqs; fn main() -> eyre::Result<()> { @@ -10,7 +11,9 @@ fn main() -> eyre::Result<()> { sourcegraph::Sourcegraph::cmd()?, github::GitHub::cmd()?, stats::Stats::cmd()?, + init::Init::cmd()?, ]) + .subcommand_required(true) .get_matches(); match matches.subcommand() { @@ -19,6 +22,7 @@ fn main() -> eyre::Result<()> { Some(("sourcegraph", subcmd)) => sourcegraph::Sourcegraph::exec(subcmd), Some(("github", subcmd)) => github::GitHub::exec(subcmd), Some(("stats", subcmd)) => stats::Stats::exec(subcmd), + Some(("init", subcmd)) => init::Init::exec(subcmd), _ => Err(eyre::anyhow!("no command selected!")), } }