Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[r2r] refactor version handling #1686

Merged
merged 4 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions azure-pipelines-android-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
echo "##vso[task.setvariable variable=COMMIT_HASH]${TAG}"
displayName: Setup ENV
- bash: |
VERSION=2.1.$(Build.BuildId)_$(Build.SourceBranchName)_$(COMMIT_HASH)_android_armv7_CI
VERSION=$(Build.BuildId)_$(Build.SourceBranchName)_$(COMMIT_HASH)_android_armv7_CI
if ! grep -q $VERSION MM_VERSION; then
echo $VERSION > MM_VERSION
fi
Expand All @@ -34,7 +34,7 @@ jobs:
env:
MANUAL_MM_VERSION: true
- bash: |
VERSION=2.1.$(Build.BuildId)_$(Build.SourceBranchName)_$(COMMIT_HASH)_android_aarch64_CI
VERSION=$(Build.BuildId)_$(Build.SourceBranchName)_$(COMMIT_HASH)_android_aarch64_CI
if ! grep -q $VERSION MM_VERSION; then
echo $VERSION > MM_VERSION
fi
Expand Down
2 changes: 1 addition & 1 deletion azure-pipelines-build-stage-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- bash: |
rm -rf upload
mkdir upload
VERSION=2.1.$(Build.BuildId)_$(Build.SourceBranchName)_$(COMMIT_HASH)_$(Agent.OS)_CI
VERSION=$(Build.BuildId)_$(Build.SourceBranchName)_$(COMMIT_HASH)_$(Agent.OS)_CI
if ! grep -q $VERSION MM_VERSION; then
echo $VERSION > MM_VERSION
fi
Expand Down
2 changes: 1 addition & 1 deletion azure-pipelines-ios-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
echo "##vso[task.setvariable variable=COMMIT_HASH]${TAG}"
displayName: Setup ENV
- bash: |
VERSION=2.1.$(Build.BuildId)_$(Build.SourceBranchName)_$(COMMIT_HASH)_ios_aarch64_CI
VERSION=$(Build.BuildId)_$(Build.SourceBranchName)_$(COMMIT_HASH)_ios_aarch64_CI
if ! grep -q $VERSION MM_VERSION; then
echo $VERSION > MM_VERSION
fi
Expand Down
4 changes: 2 additions & 2 deletions azure-pipelines-release-stage-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
mkdir upload
displayName: 'Recreate upload dir'
- bash: |
VERSION=2.1.$(Build.BuildId)_$(Build.SourceBranchName)_$(COMMIT_HASH)_$(Agent.OS)_Debug
VERSION=$(Build.BuildId)_$(Build.SourceBranchName)_$(COMMIT_HASH)_$(Agent.OS)_Debug
if ! grep -q $VERSION MM_VERSION; then
echo $VERSION > MM_VERSION
fi
Expand Down Expand Up @@ -83,7 +83,7 @@ jobs:
condition: and( eq( variables['Agent.OS'], 'Windows_NT' ), eq( variables['DEBUG_UPLOADED'], '' ) )
- bash: |
rm -f MM_VERSION
VERSION=2.1.$(Build.BuildId)_$(Build.SourceBranchName)_$(COMMIT_HASH)_$(Agent.OS)_Release
VERSION=$(Build.BuildId)_$(Build.SourceBranchName)_$(COMMIT_HASH)_$(Agent.OS)_Release
if ! grep -q $VERSION MM_VERSION; then
echo $VERSION > MM_VERSION
fi
Expand Down
2 changes: 1 addition & 1 deletion azure-pipelines-wasm-stage-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- bash: |
rm -rf upload
mkdir upload
VERSION=2.1.$(Build.BuildId)_$(Build.SourceBranchName)_$(COMMIT_HASH)_$(Agent.OS)_Release
VERSION=$(Build.BuildId)_$(Build.SourceBranchName)_$(COMMIT_HASH)_$(Agent.OS)_Release
if ! grep -q $VERSION MM_VERSION; then
echo $VERSION > MM_VERSION
fi
Expand Down
3 changes: 2 additions & 1 deletion mm2src/mm2_bin_lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

[package]
name = "mm2_bin_lib"
version = "0.1.0"
version = "1.0.0-beta"
authors = ["James Lee", "Artem Pikulin", "Artem Grinblat", "Omar S.", "Onur Ozkan", "Alina Sharon", "Caglar Kaya", "Cipi", "Sergey Boiko", "Samuel Onoja", "Roman Sztergbaum", "Kadan Stadelmann <ca333@komodoplatform.com>"]
edition = "2018"
default-run = "mm2"

Expand Down
37 changes: 16 additions & 21 deletions mm2src/mm2_bin_lib/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,31 +51,26 @@ fn mm_version() -> String {
// and a release tag when building from some kind of a stable branch,
// though we should keep the ability for the tooling to provide the “MM_VERSION”
// externally, because moving the entire ".git" around is not always practical.
onur-ozkan marked this conversation as resolved.
Show resolved Hide resolved
let mut version = "UNKNOWN".to_string();
let mut command = Command::new("git");
command.arg("log").arg("--pretty=format:%h").arg("-n1");
if let Ok(go) = command.output() {
if go.status.success() {
version = from_utf8(&go.stdout).unwrap().trim().to_string();
if !Regex::new(r"^\w+$").unwrap().is_match(&version) {
panic!("{}", version)
}
}
}
let mut version = env!("CARGO_PKG_VERSION").to_owned();

let mm_version_p = root().join("../../MM_VERSION");
let v_file = String::from_utf8(slurp(&mm_version_p)).unwrap();
let v_file = v_file.trim().to_string();
// if there is no MM_VERSION file there is no need to create it

// if there is MM_VERSION file, that means CI wants to put a tag to version
if !v_file.is_empty() {
if !v_file.contains(&version) {
// If the file doesn't contain the latest commit hash then this is a local build
// and the env version variable should be "v_file"_"version" as "v_file" is the version from the local file
// and "version" is the latest commit hash
version = format!("{}_{}", v_file, version);
} else {
// If the file contains the latest commit hash then this is a CI build and the version generated by CI should be written to env
version = v_file;
version = format!("{}_{}", version, v_file.trim());
} else {
let mut command = Command::new("git");
command.arg("log").arg("--pretty=format:%h").arg("-n1");
if let Ok(go) = command.output() {
if go.status.success() {
let commit_hash = from_utf8(&go.stdout).unwrap().trim().to_string();
if !Regex::new(r"^\w+$").unwrap().is_match(&commit_hash) {
panic!("{}", commit_hash)
}

version = format!("{version}_{commit_hash}");
}
}
}

Expand Down
9 changes: 8 additions & 1 deletion mm2src/mm2_main/src/mm2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,6 @@ pub fn mm2_main(version: String, datetime: String) {
use libc::c_char;

init_crash_reports();
log!("AtomicDEX MarketMaker {} DT {}", version, datetime);

// Temporarily simulate `argv[]` for the C version of the main method.
let args: Vec<String> = env::args()
Expand Down Expand Up @@ -376,15 +375,23 @@ pub fn mm2_main(version: String, datetime: String) {
return;
}

if first_arg == Some("--version") || first_arg == Some("-v") || first_arg == Some("version") {
println!("AtomicDEX API: {version}");
return;
}

if first_arg == Some("--help") || first_arg == Some("-h") || first_arg == Some("help") {
help();
return;
}

if cfg!(windows) && first_arg == Some("/?") {
help();
return;
}

log!("AtomicDEX API {} DT {}", version, datetime);

if let Err(err) = run_lp_main(first_arg, &|_| (), version, datetime) {
log!("{}", err);
exit(1);
Expand Down