-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from nikita-skobov/fix-version-string-pipeline
Fix version string pipeline
- Loading branch information
Showing
3 changed files
with
69 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters