diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..1526bb6 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,119 @@ +name: GitHub Release + +on: + # Publish `v1.2.3` tags as releases. + push: + tags: + - v* + +jobs: + # Create the GitHub Release before building the project. + create_release: + runs-on: ubuntu-latest + + steps: + - name: Create artifacts directory + run: mkdir artifacts + + - name: Create GitHub Release + id: release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: ${{ github.ref }} + draft: "true" + + - name: Save release upload URL to artifact + run: echo "${{ steps.release.outputs.upload_url }}" > artifacts/release-upload-url + + - name: Upload artifacts + uses: actions/upload-artifact@v1 + with: + name: artifacts + path: artifacts + + # This runs for each target, so it can't be the same job that creates the Release. + build_release: + needs: [create_release] + + runs-on: ${{ matrix.os }} + strategy: + matrix: + build: [linux, macos] + include: + - build: linux + os: ubuntu-latest + rust: stable + target: x86_64-unknown-linux-gnu + # target: x86_64-unknown-linux-musl + - build: macos + os: macos-latest + rust: stable + target: x86_64-apple-darwin + + steps: + - name: Checkout rebase-wizard + uses: actions/checkout@v2 + with: + fetch-depth: 1 + + - name: Latest Stable Rust Toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ matrix.rust }} + profile: minimal + override: "true" + target: ${{ matrix.target }} + + - name: Export TARGET_DIR + run: | + TARGET_DIR="./target/${{ matrix.target }}" + echo "::set-env name=TARGET_DIR::$TARGET_DIR" + + - name: Export OUTPUT_BINARY_PATH + run: | + OUTPUT_BINARY_PATH="${{ env.TARGET_DIR }}/release/rebase-wizard" + echo "::set-env name=OUTPUT_BINARY_PATH::$OUTPUT_BINARY_PATH" + + - name: Release build + uses: actions-rs/cargo@v1 + with: + # use-cross: "true" + command: build + args: --release --target ${{ matrix.target }} + + - name: Strip Binary + run: strip ${{ env.OUTPUT_BINARY_PATH }} + + - name: Get release download URL + uses: actions/download-artifact@v1 + with: + name: artifacts + path: artifacts + + - name: Set release upload URL + shell: bash + run: | + release_upload_url="$(cat artifacts/release-upload-url)" + echo "::set-env name=RELEASE_UPLOAD_URL::$release_upload_url" + echo "release upload url: $RELEASE_UPLOAD_URL" + + - name: Set release asset + shell: bash + run: | + asset_name="rebase-wizard-${{ matrix.target }}" + mv ${{ env.OUTPUT_BINARY_PATH }} $asset_name + echo "::set-env name=RELEASE_ASSET::$asset_name" + echo "release asset: $RELEASE_ASSET" + + - name: Upload release archive + uses: actions/upload-release-asset@v1.0.1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ env.RELEASE_UPLOAD_URL }} + asset_path: ${{ env.RELEASE_ASSET }} + asset_name: ${{ env.RELEASE_ASSET }} + asset_content_type: application/octet-stream diff --git a/.github/workflows/rust_build.yml b/.github/workflows/rust_build.yml new file mode 100644 index 0000000..903c304 --- /dev/null +++ b/.github/workflows/rust_build.yml @@ -0,0 +1,91 @@ +name: Rust Build + +on: + pull_request: + push: + branches: + - master + +jobs: + check: + runs-on: ubuntu-latest + + steps: + - name: Checkout rebase-wizard + uses: actions/checkout@v2 + with: + fetch-depth: 1 + + - name: Latest Stable Rust Toolchain with clippy + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + components: clippy + + - name: Annotate commit with clippy warnings + uses: actions-rs/clippy-check@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + args: --all-features + + audit: + runs-on: ubuntu-latest + + steps: + - name: Checkout rebase-wizard + uses: actions/checkout@v2 + with: + fetch-depth: 1 + + - name: Latest Stable Rust Toolchain with clippy + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + + - name: Security audit + uses: actions-rs/audit-check@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + + build: + runs-on: ${{ matrix.os }} + strategy: + matrix: + build: [linux, macos] + include: + - build: linux + os: ubuntu-latest + rust: stable + target: x86_64-unknown-linux-musl + - build: macos + os: macos-latest + rust: stable + target: x86_64-apple-darwin + + steps: + - name: Checkout rebase-wizard + uses: actions/checkout@v2 + with: + fetch-depth: 1 + + - name: Latest Stable Rust Toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ matrix.rust }} + profile: minimal + override: "true" + target: ${{ matrix.target }} + + - name: Test build + uses: actions-rs/cargo@v1 + with: + command: build + args: --tests + + - name: Test run + uses: actions-rs/cargo@v1 + with: + command: test + args: --verbose diff --git a/README.md b/README.md index 697bbc1..1bc0cf9 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +![Rust Build](https://github.com/saterus/rebase-wizard/workflows/Rust%20Build/badge.svg) + # Rebase Wizard The Wizard can help with all your rebase problems! diff --git a/src/git.rs b/src/git.rs index 0ca951d..8047638 100644 --- a/src/git.rs +++ b/src/git.rs @@ -17,7 +17,7 @@ impl BranchLocation { } } -static LOCAL_CHANGES_WARNING: &'static str = "\ +static LOCAL_CHANGES_WARNING: &str = "\ The Wizard advises against rebasing while there are changes to the local git repo. Please commit, stash, or discard your changes before proceeding."; @@ -88,14 +88,14 @@ pub fn current_branch_name() -> String { .to_string() } -pub fn extract_ref(branch_line: &str) -> &str { +pub fn extract_ref(branch_line: &str) -> Option<&str> { let re = Regex::new(r"\s*(\w\S*)\s").unwrap(); - for caps in re.captures_iter(branch_line) { - return caps.get(1).unwrap().as_str(); + if let Some(capture) = re.captures_iter(branch_line).next() { + Some(capture.get(1).unwrap().as_str()) + } else { + None } - - return ""; } #[cfg(test)] @@ -109,9 +109,9 @@ mod tests { let sample3 = " origin/foo/bar-baz 770b0814b WIP!"; let sample4 = " fa1afe1 WIP!"; - assert_eq!(extract_ref(sample), "foo/bar-baz"); - assert_eq!(extract_ref(sample2), "foo/bark-bazz"); - assert_eq!(extract_ref(sample3), "origin/foo/bar-baz"); - assert_eq!(extract_ref(sample4), "fa1afe1"); + assert_eq!(extract_ref(sample).unwrap(), "foo/bar-baz"); + assert_eq!(extract_ref(sample2).unwrap(), "foo/bark-bazz"); + assert_eq!(extract_ref(sample3).unwrap(), "origin/foo/bar-baz"); + assert_eq!(extract_ref(sample4).unwrap(), "fa1afe1"); } } diff --git a/src/sk.rs b/src/sk.rs index c2040da..21a6045 100644 --- a/src/sk.rs +++ b/src/sk.rs @@ -23,7 +23,7 @@ impl<'b, 'a: 'b> From> for SkimOptions<'b> { pub fn one(source: SkimItemReceiver, options: SimpleOptions) -> String { let skim_output = Skim::run_with(&options.into(), Some(source)) .map(|out| out.selected_items) - .unwrap_or_else(|| Vec::new()); + .unwrap_or_else(Vec::new); let selected_item = skim_output.first().unwrap_or_else(|| { eprintln!("Nothing selected. Aborting."); diff --git a/src/subcommands/branch_jump.rs b/src/subcommands/branch_jump.rs index cea33c2..9ad4afd 100644 --- a/src/subcommands/branch_jump.rs +++ b/src/subcommands/branch_jump.rs @@ -10,7 +10,7 @@ pub fn jump(config: &cli::Config) { let branch_point = pick_branch_point(¤t_branch_name, &target_branch, &config); println!("The Rebase Wizard has seen your future:"); - println!(""); + println!(); println!("Run the following command when you are ready:"); println!(" git rebase --onto {} {}", target_branch, branch_point); } @@ -37,7 +37,9 @@ pub fn pick_target_branch(current_branch_name: &str, config: &cli::Config) -> St let branches = git::all_branches(); let selection = sk::one(sk::to_source(branches), options); - git::extract_ref(&selection).to_string() + git::extract_ref(&selection) + .expect("branch name not found") + .to_string() } pub fn pick_branch_point( @@ -69,5 +71,7 @@ pub fn pick_branch_point( let commits = git::recent_commits(); let selection = sk::one(sk::to_source(commits), options); - git::extract_ref(&selection).to_string() + git::extract_ref(&selection) + .expect("commit sha not found") + .to_string() } diff --git a/src/subcommands/tutorial.rs b/src/subcommands/tutorial.rs index ea434db..b502446 100644 --- a/src/subcommands/tutorial.rs +++ b/src/subcommands/tutorial.rs @@ -1,4 +1,4 @@ -pub static SECRETS_TEXT: &'static str = r" +pub static SECRETS_TEXT: &str = r" Wizard Secrets: 🧙‍♂️ git rebase --onto TARGET_BRANCH BRANCH_POINT @@ -12,9 +12,9 @@ Wizard Secrets: 🧙‍♂️ First commit you didn't author on this branch "; -pub static MORE_HELP_TEASER: &'static str = "For more secrets 🔮, try running the --tutorial flag."; +pub static MORE_HELP_TEASER: &str = "For more secrets 🔮, try running the --tutorial flag."; -pub static TUTORIAL_TEXT: &'static str = r" +pub static TUTORIAL_TEXT: &str = r" *Branch Jumping*: It isn't uncommon to need to move your feature branch from being based on one branch to another. This requires picking the exact right arguments for `git rebase --onto`.