forked from kevinswiber/postman2openapi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding artifacts for release automation.
Signed-off-by: Kevin Swiber <[email protected]>
- Loading branch information
1 parent
2bf2c18
commit 49c37e4
Showing
3 changed files
with
64 additions
and
0 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 |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
name = "postman2openapi" | ||
version = "0.1.0" | ||
authors = ["Kevin Swiber <[email protected]>"] | ||
build = "build.rs" | ||
edition = "2018" | ||
|
||
[lib] | ||
|
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,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) | ||
} | ||
}) | ||
} |
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,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 |