Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Commit

Permalink
set more detailed version information during builds (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmc-msft authored Sep 30, 2020
1 parent bee23c5 commit 24f4347
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 37 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,11 @@ jobs:
cp -r src/agent/script/win64/libfuzzer-coverage src/deployment/tools/win64/libfuzzer-coverage
echo $GITHUB_RUN_ID | tee src/deployment/.build.id
echo $GITHUB_SHA | tee src/deployment/.sha
cp CURRENT_VERSION src/deployment/VERSION
./src/ci/get-version.sh > src/deployment/VERSION
(cd src/deployment ; zip -r onefuzz-deployment-$(cat VERSION).zip . )
cp src/deployment/onefuzz-deployment*zip release-artifacts
cp -r artifacts/sdk release-artifacts
cp -r artifacts/windows-cli/onefuzz.exe release-artifacts/onefuzz-cli-$(cat CURRENT_VERSION).exe
cp -r artifacts/windows-cli/onefuzz.exe release-artifacts/onefuzz-cli-$(./src/ci/get-version.sh).exe
- uses: actions/upload-artifact@v2.1.4
with:
name: release-artifacts
Expand Down
38 changes: 29 additions & 9 deletions src/agent/onefuzz-agent/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::env;
use std::error::Error;
use std::fs::File;
use std::io::prelude::*;
Expand All @@ -6,7 +7,7 @@ use std::process::Command;
fn run_cmd(args: &[&str]) -> Result<String, Box<dyn Error>> {
let cmd = Command::new(args[0]).args(&args[1..]).output()?;
if cmd.status.success() {
Ok(String::from_utf8_lossy(&cmd.stdout).to_string())
Ok(String::from_utf8_lossy(&cmd.stdout).trim().to_string())
} else {
Err(From::from("failed"))
}
Expand All @@ -16,21 +17,40 @@ fn read_file(filename: &str) -> Result<String, Box<dyn Error>> {
let mut file = File::open(filename)?;
let mut contents = String::new();
file.read_to_string(&mut contents)?;
contents = contents.trim().to_string();

Ok(contents)
}

fn main() -> Result<(), Box<dyn Error>> {
fn print_version(include_sha: bool) -> Result<(), Box<dyn Error>> {
let mut version = read_file("../../../CURRENT_VERSION")?;
let sha = run_cmd(&["git", "rev-parse", "HEAD"])?;
let with_changes = if run_cmd(&["git", "diff", "--quiet"]).is_err() {
"-local_changes"
} else {
""
};
println!("cargo:rustc-env=GIT_VERSION={}{}", sha, with_changes);

let version = read_file("../../../CURRENT_VERSION")?;
if include_sha {
version.push('-');
version.push_str(&sha);

// if we're a non-release build, check to see if git has
// unstaged changes
if run_cmd(&["git", "diff", "--quiet"]).is_err() {
version.push('.');
version.push_str("localchanges");
}
}

println!("cargo:rustc-env=GIT_VERSION={}", sha);
println!("cargo:rustc-env=ONEFUZZ_VERSION={}", version);

Ok(())
}

fn main() -> Result<(), Box<dyn Error>> {
// If we're built off of a tag, we accept CURRENT_VERSION as is. Otherwise
// modify it to indicate local build
let include_sha = if let Ok(val) = env::var("GITHUB_REF") {
!val.starts_with("refs/tags/")
} else {
true
};
print_version(include_sha)
}
38 changes: 29 additions & 9 deletions src/agent/onefuzz-supervisor/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::env;
use std::error::Error;
use std::fs::File;
use std::io::prelude::*;
Expand All @@ -6,7 +7,7 @@ use std::process::Command;
fn run_cmd(args: &[&str]) -> Result<String, Box<dyn Error>> {
let cmd = Command::new(args[0]).args(&args[1..]).output()?;
if cmd.status.success() {
Ok(String::from_utf8_lossy(&cmd.stdout).to_string())
Ok(String::from_utf8_lossy(&cmd.stdout).trim().to_string())
} else {
Err(From::from("failed"))
}
Expand All @@ -16,21 +17,40 @@ fn read_file(filename: &str) -> Result<String, Box<dyn Error>> {
let mut file = File::open(filename)?;
let mut contents = String::new();
file.read_to_string(&mut contents)?;
contents = contents.trim().to_string();

Ok(contents)
}

fn main() -> Result<(), Box<dyn Error>> {
fn print_version(include_sha: bool) -> Result<(), Box<dyn Error>> {
let mut version = read_file("../../../CURRENT_VERSION")?;
let sha = run_cmd(&["git", "rev-parse", "HEAD"])?;
let with_changes = if run_cmd(&["git", "diff", "--quiet"]).is_err() {
"-local_changes"
} else {
""
};
println!("cargo:rustc-env=GIT_VERSION={}{}", sha, with_changes);

let version = read_file("../../../CURRENT_VERSION")?;
if include_sha {
version.push('-');
version.push_str(&sha);

// if we're a non-release build, check to see if git has
// unstaged changes
if run_cmd(&["git", "diff", "--quiet"]).is_err() {
version.push('.');
version.push_str("localchanges");
}
}

println!("cargo:rustc-env=GIT_VERSION={}", sha);
println!("cargo:rustc-env=ONEFUZZ_VERSION={}", version);

Ok(())
}

fn main() -> Result<(), Box<dyn Error>> {
// If we're built off of a tag, we accept CURRENT_VERSION as is. Otherwise
// modify it to indicate local build
let include_sha = if let Ok(val) = env::var("GITHUB_REF") {
!val.starts_with("refs/tags/")
} else {
true
};
print_version(include_sha)
}
34 changes: 27 additions & 7 deletions src/api-service/dev-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,32 @@ fi
set -ex

TARGET=${1}
cd ${APP_DIR}
(cd ../pytypes && python setup.py sdist bdist_wheel && cp dist/*.whl ../api-service/__app__)
cd __app__
pushd ${APP_DIR}
VERSION=$(../ci/get-version.sh)
../ci/set-versions.sh

# clean up any previously built onefuzztypes packages
rm __app__/onefuzztypes*.whl

# build a local copy of onefuzztypes
rm -rf local-pytypes
cp -r ../pytypes local-pytypes
pushd local-pytypes
rm -f dist/*
python setup.py sdist bdist_wheel
cp dist/*.whl ../__app__
popd
rm -r local-pytypes

# deploy a the instance with the locally built onefuzztypes
pushd __app__
uuidgen > onefuzzlib/build.id
sed -i s,onefuzztypes==0.0.0,./onefuzztypes-0.0.0-py3-none-any.whl, requirements.txt
TYPELIB=$(ls onefuzztypes*.whl)
sed -i s,.*onefuzztypes.*,./${TYPELIB}, requirements.txt
func azure functionapp publish ${TARGET} --python
sed -i s,./onefuzztypes-0.0.0-py3-none-any.whl,onefuzztypes==0.0.0, requirements.txt
rm 'onefuzztypes-0.0.0-py3-none-any.whl'
cat onefuzzlib/build.id
sed -i s,./onefuzztypes.*,onefuzztypes==0.0.0, requirements.txt
rm onefuzztypes*.whl
popd

../ci/unset-versions.sh
cat __app__/onefuzzlib/build.id
28 changes: 28 additions & 0 deletions src/ci/get-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
#
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

set -e

SCRIPT_DIR=$(dirname ${BASH_SOURCE[0]})
BASE_VERSION=$(cat ${SCRIPT_DIR}/../../CURRENT_VERSION)
BRANCH=$(git rev-parse --abbrev-ref HEAD)
GIT_HASH=$(git rev-parse HEAD)

if [ "${GITHUB_REF}" != "" ]; then
TAG_VERSION=${GITHUB_REF#refs/tags/}

# this isn't a tag
if [ ${TAG_VERSION} == ${GITHUB_REF} ]; then
echo ${BASE_VERSION}-${GIT_HASH}
else
echo ${BASE_VERSION}
fi
else
if $(git diff --quiet); then
echo ${BASE_VERSION}-${GIT_HASH}
else
echo ${BASE_VERSION}-${GIT_HASH}.localchanges
fi
fi
5 changes: 4 additions & 1 deletion src/ci/set-versions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@

set -ex

VERSION=$(cat CURRENT_VERSION)
SCRIPT_DIR=$(dirname ${BASH_SOURCE[0]})
GET_VERSION=${SCRIPT_DIR}/get-version.sh
VERSION=$(${GET_VERSION})
cd ${SCRIPT_DIR}/../../

SET_VERSIONS="src/pytypes/onefuzztypes/__version__.py src/api-service/__app__/onefuzzlib/__version__.py src/cli/onefuzz/__version__.py"
SET_REQS="src/cli/requirements.txt src/api-service/__app__/requirements.txt"
Expand Down
17 changes: 17 additions & 0 deletions src/ci/unset-versions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
#
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

set -ex

SCRIPT_DIR=$(dirname ${BASH_SOURCE[0]})
GET_VERSION=${SCRIPT_DIR}/get-version.sh
VERSION=$(${GET_VERSION})
cd ${SCRIPT_DIR}/../../

SET_VERSIONS="src/pytypes/onefuzztypes/__version__.py src/api-service/__app__/onefuzzlib/__version__.py src/cli/onefuzz/__version__.py"
SET_REQS="src/cli/requirements.txt src/api-service/__app__/requirements.txt"

sed -i 's/__version__ = .*/__version__ = "0.0.0"/' ${SET_VERSIONS}
sed -i "s/onefuzztypes==.*/onefuzztypes==0.0.0/" ${SET_REQS}
38 changes: 29 additions & 9 deletions src/proxy-manager/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::env;
use std::error::Error;
use std::fs::File;
use std::io::prelude::*;
Expand All @@ -6,7 +7,7 @@ use std::process::Command;
fn run_cmd(args: &[&str]) -> Result<String, Box<dyn Error>> {
let cmd = Command::new(args[0]).args(&args[1..]).output()?;
if cmd.status.success() {
Ok(String::from_utf8_lossy(&cmd.stdout).to_string())
Ok(String::from_utf8_lossy(&cmd.stdout).trim().to_string())
} else {
Err(From::from("failed"))
}
Expand All @@ -16,21 +17,40 @@ fn read_file(filename: &str) -> Result<String, Box<dyn Error>> {
let mut file = File::open(filename)?;
let mut contents = String::new();
file.read_to_string(&mut contents)?;
contents = contents.trim().to_string();

Ok(contents)
}

fn main() -> Result<(), Box<dyn Error>> {
fn print_version(include_sha: bool) -> Result<(), Box<dyn Error>> {
let mut version = read_file("../../CURRENT_VERSION")?;
let sha = run_cmd(&["git", "rev-parse", "HEAD"])?;
let with_changes = if run_cmd(&["git", "diff", "--quiet"]).is_err() {
"-local_changes"
} else {
""
};
println!("cargo:rustc-env=GIT_VERSION={}{}", sha, with_changes);

let version = read_file("../../CURRENT_VERSION")?;
if include_sha {
version.push('-');
version.push_str(&sha);

// if we're a non-release build, check to see if git has
// unstaged changes
if run_cmd(&["git", "diff", "--quiet"]).is_err() {
version.push('.');
version.push_str("localchanges");
}
}

println!("cargo:rustc-env=GIT_VERSION={}", sha);
println!("cargo:rustc-env=ONEFUZZ_VERSION={}", version);

Ok(())
}

fn main() -> Result<(), Box<dyn Error>> {
// If we're built off of a tag, we accept CURRENT_VERSION as is. Otherwise
// modify it to indicate local build
let include_sha = if let Ok(val) = env::var("GITHUB_REF") {
!val.starts_with("refs/tags/")
} else {
true
};
print_version(include_sha)
}

0 comments on commit 24f4347

Please sign in to comment.