Skip to content

Commit

Permalink
Adding artifacts for release automation.
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Swiber <[email protected]>
  • Loading branch information
kevinswiber committed Aug 21, 2020
1 parent 2bf2c18 commit 49c37e4
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "postman2openapi"
version = "0.1.0"
authors = ["Kevin Swiber <[email protected]>"]
build = "build.rs"
edition = "2018"

[lib]
Expand Down
44 changes: 44 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use std::env;
use std::fs::{self, File};
use std::path::Path;
use std::process;

fn main() {
// OUT_DIR is set by Cargo and it's where any additional build artifacts
// are written.
let outdir = match env::var_os("OUT_DIR") {
Some(outdir) => outdir,
None => {
eprintln!(
"OUT_DIR environment variable not defined. \
Please file a bug: \
https://github.com/kevinswiber/postman2openapi/issues/new"
);
process::exit(1);
}
};
fs::create_dir_all(&outdir).unwrap();

let stamp_path = Path::new(&outdir).join("postman2openapi-stamp");
if let Err(err) = File::create(&stamp_path) {
panic!("failed to write {}: {}", stamp_path.display(), err);
}
// Make the current git hash available to the build.
if let Some(rev) = git_revision_hash() {
println!("cargo:rustc-env=POSTMAN2OPENAPI_BUILD_GIT_HASH={}", rev);
}
}

fn git_revision_hash() -> Option<String> {
let result = process::Command::new("git")
.args(&["rev-parse", "--short=10", "HEAD"])
.output();
result.ok().and_then(|output| {
let v = String::from_utf8_lossy(&output.stdout).trim().to_string();
if v.is_empty() {
None
} else {
Some(v)
}
})
}
19 changes: 19 additions & 0 deletions ci/cargo-out-dir
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

# Finds Cargo's `OUT_DIR` directory from the most recent build.
#
# This requires one parameter corresponding to the target directory
# to search for the build output.

if [ $# != 1 ]; then
echo "Usage: $(basename "$0") <target-dir>" >&2
exit 2
fi

# This works by finding the most recent stamp file, which is produced by
# every postman2openapi build.
target_dir="$1"
find "$target_dir" -name postman2openapi-stamp -print0 \
| xargs -0 ls -t \
| head -n1 \
| xargs dirname

0 comments on commit 49c37e4

Please sign in to comment.