Skip to content

Commit

Permalink
Merge pull request #1 from saterus/actions
Browse files Browse the repository at this point in the history
Setup GitHub Actions
  • Loading branch information
saterus authored Apr 13, 2020
2 parents 314f9fd + dd1ab7f commit 38ca32f
Show file tree
Hide file tree
Showing 7 changed files with 233 additions and 17 deletions.
119 changes: 119 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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
91 changes: 91 additions & 0 deletions .github/workflows/rust_build.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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!
Expand Down
20 changes: 10 additions & 10 deletions src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.";
Expand Down Expand Up @@ -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)]
Expand All @@ -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");
}
}
2 changes: 1 addition & 1 deletion src/sk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl<'b, 'a: 'b> From<SimpleOptions<'a>> 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.");
Expand Down
10 changes: 7 additions & 3 deletions src/subcommands/branch_jump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub fn jump(config: &cli::Config) {
let branch_point = pick_branch_point(&current_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);
}
Expand All @@ -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(
Expand Down Expand Up @@ -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()
}
6 changes: 3 additions & 3 deletions src/subcommands/tutorial.rs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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`.
Expand Down

0 comments on commit 38ca32f

Please sign in to comment.