This repository was archived by the owner on Aug 20, 2024. It is now read-only.
forked from GSI/bn-api
-
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.
semantic version releases (issue #463) (#575)
* Added .editorconfig Idea runs editorconfig by default, all other editors support this via extensions * Add `X-App-Version` header to all responses * Added cargo version bumping to travis * Rather have one commit for version bumping * init-reset script should fail loudly * Cargo fmt fixes * #rustnoob caching the header name and header value Not necessary but wanted to try it out, also this is run on every request so may as well be efficient * Only tag for master builds
- Loading branch information
1 parent
9693be0
commit 802fe63
Showing
7 changed files
with
94 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# EditorConfig helps developers define and maintain consistent | ||
# coding styles between different editors and IDEs | ||
# editorconfig.org | ||
|
||
root = true | ||
|
||
[*] | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
indent_style = space | ||
indent_size = 4 |
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 |
---|---|---|
|
@@ -67,6 +67,7 @@ before_install: | |
|
||
before_script: | ||
|
||
after_script: | ||
|
||
after_script: | ||
- ./scripts/bump-version.sh --with-git | ||
|
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,37 @@ | ||
use actix_web::http::header::{HeaderName, HeaderValue}; | ||
use actix_web::http::HttpTryFrom; | ||
use actix_web::middleware::{Middleware, Response}; | ||
use actix_web::{HttpRequest, HttpResponse, Result}; | ||
|
||
use server::AppState; | ||
|
||
const SEMVER_HEADER_NAME: &'static str = "X-App-Version"; | ||
const APP_VERSION: &'static str = env!("CARGO_PKG_VERSION"); | ||
|
||
pub struct AppVersionHeader { | ||
header_name: HeaderName, | ||
app_version: HeaderValue, | ||
} | ||
|
||
impl AppVersionHeader { | ||
pub fn new() -> AppVersionHeader { | ||
AppVersionHeader { | ||
header_name: HeaderName::try_from(SEMVER_HEADER_NAME).unwrap(), | ||
app_version: HeaderValue::from_static(APP_VERSION), | ||
} | ||
} | ||
} | ||
|
||
impl Middleware<AppState> for AppVersionHeader { | ||
fn response( | ||
&self, | ||
_request: &HttpRequest<AppState>, | ||
mut response: HttpResponse, | ||
) -> Result<Response> { | ||
response | ||
.headers_mut() | ||
.insert(&self.header_name, self.app_version.clone()); | ||
|
||
Ok(Response::Done(response)) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
pub use self::app_version_header::*; | ||
pub use self::database_transaction::*; | ||
|
||
mod app_version_header; | ||
mod database_transaction; |
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
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
set -o allexport | ||
source .env | ||
set +o allexport | ||
|
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,38 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
if [[ "$TRAVIS_BRANCH" != "master" ]];then | ||
echo "Skipping tag-version because branch is not master (but is '$TRAVIS_BRANCH')" | ||
exit 0 | ||
fi | ||
|
||
new_version="" | ||
|
||
function bump_patch { | ||
local file="$1" | ||
local version=`sed -En 's/version[[:space:]]*=[[:space:]]*"([[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+)"/\1/p' < $file` | ||
new_version=`echo $version | awk -F. -v OFS=. 'NF==1{print ++$NF}; NF>1{$NF=sprintf("%0*d", length($NF), ($NF+1)); print}'` | ||
local search='^(version[[:space:]]*=[[:space:]]*).+' | ||
local replace="\1\"${new_version}\"" | ||
|
||
sed -i ".tmp" -E "s/${search}/${replace}/g" "$1" | ||
echo "$file bumped from $version to $new_version" | ||
rm "$1.tmp" | ||
} | ||
|
||
FILES=( "db/Cargo.toml" "api/Cargo.toml" ) | ||
|
||
for target in "${FILES[@]}"; do | ||
bump_patch "$target" | ||
if [[ $1 == "--with-git" ]]; then | ||
git add "$target" | ||
fi | ||
done | ||
|
||
if [[ $1 == "--with-git" ]]; then | ||
git commit -m "Version bump to ${new_version}" | ||
git tag ${new_version} | ||
git push origin | ||
git push --tags | ||
fi |