mirror of
https://github.com/microsoft/onefuzz.git
synced 2025-06-17 04:18:07 +00:00
set more detailed version information during builds (#58)
This commit is contained in:
4
.github/workflows/ci.yml
vendored
4
.github/workflows/ci.yml
vendored
@ -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
|
||||
|
@ -1,3 +1,4 @@
|
||||
use std::env;
|
||||
use std::error::Error;
|
||||
use std::fs::File;
|
||||
use std::io::prelude::*;
|
||||
@ -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"))
|
||||
}
|
||||
@ -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)
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
use std::env;
|
||||
use std::error::Error;
|
||||
use std::fs::File;
|
||||
use std::io::prelude::*;
|
||||
@ -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"))
|
||||
}
|
||||
@ -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)
|
||||
}
|
||||
|
@ -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
src/ci/get-version.sh
Executable file
28
src/ci/get-version.sh
Executable file
@ -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,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"
|
||||
|
17
src/ci/unset-versions.sh
Executable file
17
src/ci/unset-versions.sh
Executable file
@ -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}
|
@ -1,3 +1,4 @@
|
||||
use std::env;
|
||||
use std::error::Error;
|
||||
use std::fs::File;
|
||||
use std::io::prelude::*;
|
||||
@ -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"))
|
||||
}
|
||||
@ -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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user