Skip to content

Commit

Permalink
Merge pull request #59 from nikita-skobov/fix-version-string-pipeline
Browse files Browse the repository at this point in the history
Fix version string pipeline
  • Loading branch information
nikita-skobov authored Oct 18, 2020
2 parents ed1ac73 + 98a8741 commit 644562c
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 10 deletions.
39 changes: 30 additions & 9 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,34 @@ on:
inputs:
name:
description: 'release tag version'
default: 'vX.Y.Z'
default: 'X.Y.Z'
required: true

jobs:
version_bump:
runs-on: ubuntu-latest
steps:
- name: checkout_code
uses: actions/[email protected]
- name: git_config
run: git config --local user.name "github_CI" && git config --local user.email "github_CI"
- name: version_bump
# when running this pipeline make sure the inputs.name is just the version without the v (eg: 1.1.1)
run: sed -i '5s/.*/version = "${{ github.event.inputs.name }}"/' Cargo.toml
- name: version_check
uses: actions-rs/cargo@ae10961054e4aa8b4aa7dffede299aaf087aa33b
with:
command: check
- name: temp_branch
continue-on-error: true
run: git checkout -b tmp_branch
- name: commit_and_push_new_docs
continue-on-error: true
run: git add Cargo.toml Cargo.lock && git commit -m "version bump ${{ github.event.inputs.name }}" && git push origin HEAD:tmp_branch
build_test:
# The type of runner that the job will run on
runs-on: ${{ matrix.job.os }}
needs: version_bump
strategy:
fail-fast: false
matrix:
Expand All @@ -31,6 +52,8 @@ jobs:
uses: mig4/[email protected]
- name: checkout_code
uses: actions/[email protected]
with:
ref: tmp_branch
- name: install_git_filter_repo
run: bash .github/install-git-filter-repo.sh ${{ matrix.job.os }}
- name: build_executable
Expand Down Expand Up @@ -165,6 +188,8 @@ jobs:
path: ./target/release
- name: lstest
run: ls -l ./target/release/mgt
- name: merge_from_tmp
run: git fetch origin tmp_branch && git checkout tmp_branch && git checkout - && git merge --ff-only tmp_branch
- name: make_mgt_executable
run: chmod +x ./target/release/mgt
- name: helptest
Expand All @@ -173,13 +198,9 @@ jobs:
run: ./doc/gen_docs.sh
- name: git_config
run: git config --local user.name "github_CI" && git config --local user.email "github_CI"
- name: version_bump
# when running this pipeline make sure the inputs.name is just the version without the v (eg: 1.1.1)
run: sed -i '5s/.*/version = "${{ github.event.inputs.name }}"/' Cargo.toml
- name: version_check
uses: actions-rs/cargo@ae10961054e4aa8b4aa7dffede299aaf087aa33b
with:
command: check
- name: commit_and_push_new_docs
continue-on-error: true
run: git add doc/ Cargo.toml Cargo.lock && git commit -m "updates docs for ${{ github.event.inputs.name }}" && git push
run: git add doc/ && git commit -m "updates docs for ${{ github.event.inputs.name }}" && git push
- name: cleanup_tmp_branch
run: git push origin --delete tmp_branch
continue-on-error: true
33 changes: 33 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use std::process::Command;
use std::process::Stdio;

pub fn get_latest_commit() -> String {
let command_and_args = [
"git", "log", "--oneline",
"--pretty=%h", "-n", "1",
];
let mut proc = Command::new(command_and_args[0]);
proc.args(&command_and_args[1..]);

proc.stdin(Stdio::null());
let output = proc.output();


let err_str = "Haha oops! this build failed to get the latest commit hash. ¯\\_(ツ)_/¯";
match output {
Err(_) => return err_str.into(),
Ok(out) => {
let status_code = out.status.code().unwrap_or(1);
if status_code == 0 {
return String::from_utf8_lossy(&out.stdout).into();
} else {
return err_str.into();
}
}
}
}

fn main() {
let latest_commit = get_latest_commit();
println!("cargo:rustc-env=LATEST_COMMIT={}", latest_commit);
}
7 changes: 6 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ mod git_helpers;
mod exec_helpers;

fn get_cli_input<'a>() -> ArgMatches<'a> {
let version_str = format!(
"{} {}",
env!("CARGO_PKG_VERSION"),
env!("LATEST_COMMIT"),
);
let mut base_app = App::new(env!("CARGO_PKG_NAME"))
.version(env!("CARGO_PKG_VERSION"))
.version(version_str.as_str())
.author(env!("CARGO_PKG_AUTHORS"))
.about(env!("CARGO_PKG_DESCRIPTION"));

Expand Down

0 comments on commit 644562c

Please sign in to comment.