Skip to content

Commit

Permalink
Add code coverage reporting to edgelet checkin build (Azure#1303)
Browse files Browse the repository at this point in the history
* Add code coverage reporting to edgelet ci build

* Set environment variables for entire phase

* Skip check submodules

* Fix cobertura converter download

* Allow warnings

* Fix the build on nightly

* cargo fmt

* Fix working directory

* Add path to sources

* Fix paths

* Remove report generation

* Use sources directory

* Add sources directory

* Move code coverage to checkin build

* Fix cargo path

* Ignore the docker code gen crate

* Break build on coverage drop

* Use fixed threshold

* Use env var

* Update workload crate to rust 2018

* cargo fmt

* Address comments

* Remove docker-rs from lcov results too

* Bump up coverage goal to 68

* Unquote the CARGO_HOME env var

* Don't escape the CARGO_HOME var
  • Loading branch information
myagley authored Jun 10, 2019
1 parent f59646c commit 4a1087b
Show file tree
Hide file tree
Showing 19 changed files with 122 additions and 52 deletions.
57 changes: 57 additions & 0 deletions builds/checkin/edgelet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,60 @@ jobs:
displayName: Format Code
- bash: edgelet/build/linux/clippy.sh
displayName: Clippy

################################################################################
- job: code_coverage
################################################################################
displayName: Code Coverage
variables:
coverage.excludes: "docker-rs*"
coverage.goal: 68
rust.toolchain: nightly-2019-06-07
pool:
vmImage: 'ubuntu-16.04'
steps:
- script: |
echo "##vso[task.setvariable variable=NO_VALGRIND;]true"
echo "##vso[task.setvariable variable=CARGO_INCREMENTAL;]0"
echo "##vso[task.setvariable variable=RUSTFLAGS;]-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Zno-landing-pads"
echo "##vso[task.setvariable variable=IOTEDGE_HOMEDIR;]/tmp"
echo "##vso[task.setvariable variable=CARGO;]${CARGO_HOME:-"$HOME/.cargo"}/bin/cargo"
displayName: Set env variables
- script: edgelet/build/linux/install.sh -t "${RUST_TOOLCHAIN}"
displayName: Install Rust
- script: |
curl -L https://github.com/mozilla/grcov/releases/download/v0.5.1/grcov-linux-x86_64.tar.bz2 | tar jxf -
curl -L https://raw.github.com/eriwen/lcov-to-cobertura-xml/8c55cd11f80a21e7e46f20f8c81fcde0bf11f5e5/lcov_cobertura/lcov_cobertura.py -o lcov_cobertura.py
workingDirectory: edgelet
displayName: Install code coverage tools
- script: $CARGO "+${RUST_TOOLCHAIN}" build --verbose
displayName: Build
workingDirectory: edgelet
env:
RUST_TOOLCHAIN: $(rust.toolchain)
- script: $CARGO "+${RUST_TOOLCHAIN}" test --verbose
displayName: Test
workingDirectory: edgelet
env:
RUST_TOOLCHAIN: $(rust.toolchain)
- script: |
zip -0 target/ccov.zip `find ./target \( -name "*.gc*" \) -print`
./grcov target/ccov.zip -s . -t lcov --llvm --branch --ignore-not-existing --ignore-dir "/*" --ignore-dir "*docker-rs*" > target/lcov.info
python lcov_cobertura.py target/lcov.info --output target/coverage.xml --demangle --base-dir $(Build.SourcesDirectory)/edgelet -e "${COVERAGE_EXCLUDES}"
displayName: Assemble code coverage results
workingDirectory: edgelet
env:
COVERAGE_EXCLUDES: $(coverage.excludes)
- task: PublishCodeCoverageResults@1
displayName: Publish code coverage results
inputs:
codeCoverageTool: cobertura
summaryFileLocation: "edgelet/target/coverage.xml"
- task: mspremier.BuildQualityChecks.QualityChecks-task.BuildQualityChecks@5
displayName: 'Check build quality'
inputs:
checkCoverage: true
coverageFailOption: fixed
coverageType: lines
coverageThreshold: $(coverage.goal)

4 changes: 3 additions & 1 deletion edgelet/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
target
**/bin/**
**/obj/**
cobertura.xml
cobertura.xml
report/
lcov.info
1 change: 1 addition & 0 deletions edgelet/workload/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "workload"
version = "0.1.0"
authors = ["Azure IoT Edge Devs"]
publish = false
edition = "2018"

[dependencies]
base64 = "0.9"
Expand Down
6 changes: 3 additions & 3 deletions edgelet/workload/src/apis/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use super::configuration::Configuration;
use hyper;

pub struct APIClient {
workload_api: Box<::apis::WorkloadApi>,
workload_api: Box<dyn (crate::apis::WorkloadApi)>,
}

impl APIClient {
Expand All @@ -15,11 +15,11 @@ impl APIClient {
let configuration = Arc::new(configuration);

APIClient {
workload_api: Box::new(::apis::WorkloadApiClient::new(configuration.clone())),
workload_api: Box::new(crate::apis::WorkloadApiClient::new(configuration.clone())),
}
}

pub fn workload_api(&self) -> &::apis::WorkloadApi {
pub fn workload_api(&self) -> &dyn (crate::apis::WorkloadApi) {
self.workload_api.as_ref()
}
}
4 changes: 2 additions & 2 deletions edgelet/workload/src/apis/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
* Generated by: https://github.com/swagger-api/swagger-codegen.git
*/

use failure::Error;
use failure::{format_err, Error};
use hyper::client::connect::Connect;
use hyper::{Client, Uri};

pub struct Configuration<C: Connect> {
pub base_path: String,
pub user_agent: Option<String>,
pub client: Client<C>,
pub uri_composer: Box<Fn(&str, &str) -> Result<Uri, Error>>,
pub uri_composer: Box<dyn Fn(&str, &str) -> Result<Uri, Error>>,
}

impl<C: Connect> Configuration<C> {
Expand Down
62 changes: 34 additions & 28 deletions edgelet/workload/src/apis/workload_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,40 +33,40 @@ pub trait WorkloadApi {
&self,
api_version: &str,
name: &str,
request: ::models::IdentityCertificateRequest,
) -> Box<Future<Item = ::models::CertificateResponse, Error = Error<serde_json::Value>>>;
request: crate::models::IdentityCertificateRequest,
) -> Box<dyn Future<Item = crate::models::CertificateResponse, Error = Error<serde_json::Value>>>;
fn create_server_certificate(
&self,
api_version: &str,
name: &str,
genid: &str,
request: ::models::ServerCertificateRequest,
) -> Box<Future<Item = ::models::CertificateResponse, Error = Error<serde_json::Value>>>;
request: crate::models::ServerCertificateRequest,
) -> Box<dyn Future<Item = crate::models::CertificateResponse, Error = Error<serde_json::Value>>>;
fn decrypt(
&self,
api_version: &str,
name: &str,
genid: &str,
payload: ::models::DecryptRequest,
) -> Box<Future<Item = ::models::DecryptResponse, Error = Error<serde_json::Value>>>;
payload: crate::models::DecryptRequest,
) -> Box<dyn Future<Item = crate::models::DecryptResponse, Error = Error<serde_json::Value>>>;
fn encrypt(
&self,
api_version: &str,
name: &str,
genid: &str,
payload: ::models::EncryptRequest,
) -> Box<Future<Item = ::models::EncryptResponse, Error = Error<serde_json::Value>>>;
payload: crate::models::EncryptRequest,
) -> Box<dyn Future<Item = crate::models::EncryptResponse, Error = Error<serde_json::Value>>>;
fn sign(
&self,
api_version: &str,
name: &str,
genid: &str,
payload: ::models::SignRequest,
) -> Box<Future<Item = ::models::SignResponse, Error = Error<serde_json::Value>>>;
payload: crate::models::SignRequest,
) -> Box<dyn Future<Item = crate::models::SignResponse, Error = Error<serde_json::Value>>>;
fn trust_bundle(
&self,
api_version: &str,
) -> Box<Future<Item = ::models::TrustBundleResponse, Error = Error<serde_json::Value>>>;
) -> Box<dyn Future<Item = crate::models::TrustBundleResponse, Error = Error<serde_json::Value>>>;
}

impl<C: hyper::client::connect::Connect> WorkloadApi for WorkloadApiClient<C>
Expand All @@ -79,8 +79,9 @@ where
&self,
api_version: &str,
name: &str,
request: ::models::IdentityCertificateRequest,
) -> Box<Future<Item = ::models::CertificateResponse, Error = Error<serde_json::Value>>> {
request: crate::models::IdentityCertificateRequest,
) -> Box<dyn Future<Item = crate::models::CertificateResponse, Error = Error<serde_json::Value>>>
{
let configuration: &configuration::Configuration<C> = self.configuration.borrow();

let method = hyper::Method::POST;
Expand Down Expand Up @@ -135,7 +136,7 @@ where
}
})
.and_then(|body| {
let parsed: Result<::models::CertificateResponse, _> =
let parsed: Result<crate::models::CertificateResponse, _> =
serde_json::from_slice(&body);
parsed.map_err(Error::from)
}),
Expand All @@ -147,8 +148,9 @@ where
api_version: &str,
name: &str,
genid: &str,
request: ::models::ServerCertificateRequest,
) -> Box<Future<Item = ::models::CertificateResponse, Error = Error<serde_json::Value>>> {
request: crate::models::ServerCertificateRequest,
) -> Box<dyn Future<Item = crate::models::CertificateResponse, Error = Error<serde_json::Value>>>
{
let configuration: &configuration::Configuration<C> = self.configuration.borrow();

let method = hyper::Method::POST;
Expand Down Expand Up @@ -204,7 +206,7 @@ where
}
})
.and_then(|body| {
let parsed: Result<::models::CertificateResponse, _> =
let parsed: Result<crate::models::CertificateResponse, _> =
serde_json::from_slice(&body);
parsed.map_err(Error::from)
}),
Expand All @@ -216,8 +218,9 @@ where
api_version: &str,
name: &str,
genid: &str,
payload: ::models::DecryptRequest,
) -> Box<Future<Item = ::models::DecryptResponse, Error = Error<serde_json::Value>>> {
payload: crate::models::DecryptRequest,
) -> Box<dyn Future<Item = crate::models::DecryptResponse, Error = Error<serde_json::Value>>>
{
let configuration: &configuration::Configuration<C> = self.configuration.borrow();

let method = hyper::Method::POST;
Expand Down Expand Up @@ -273,7 +276,7 @@ where
}
})
.and_then(|body| {
let parsed: Result<::models::DecryptResponse, _> =
let parsed: Result<crate::models::DecryptResponse, _> =
serde_json::from_slice(&body);
parsed.map_err(Error::from)
}),
Expand All @@ -285,8 +288,9 @@ where
api_version: &str,
name: &str,
genid: &str,
payload: ::models::EncryptRequest,
) -> Box<Future<Item = ::models::EncryptResponse, Error = Error<serde_json::Value>>> {
payload: crate::models::EncryptRequest,
) -> Box<dyn Future<Item = crate::models::EncryptResponse, Error = Error<serde_json::Value>>>
{
let configuration: &configuration::Configuration<C> = self.configuration.borrow();

let method = hyper::Method::POST;
Expand Down Expand Up @@ -342,7 +346,7 @@ where
}
})
.and_then(|body| {
let parsed: Result<::models::EncryptResponse, _> =
let parsed: Result<crate::models::EncryptResponse, _> =
serde_json::from_slice(&body);
parsed.map_err(Error::from)
}),
Expand All @@ -354,8 +358,8 @@ where
api_version: &str,
name: &str,
genid: &str,
payload: ::models::SignRequest,
) -> Box<Future<Item = ::models::SignResponse, Error = Error<serde_json::Value>>> {
payload: crate::models::SignRequest,
) -> Box<dyn Future<Item = crate::models::SignResponse, Error = Error<serde_json::Value>>> {
let configuration: &configuration::Configuration<C> = self.configuration.borrow();

let method = hyper::Method::POST;
Expand Down Expand Up @@ -411,7 +415,8 @@ where
}
})
.and_then(|body| {
let parsed: Result<::models::SignResponse, _> = serde_json::from_slice(&body);
let parsed: Result<crate::models::SignResponse, _> =
serde_json::from_slice(&body);
parsed.map_err(Error::from)
}),
)
Expand All @@ -420,7 +425,8 @@ where
fn trust_bundle(
&self,
api_version: &str,
) -> Box<Future<Item = ::models::TrustBundleResponse, Error = Error<serde_json::Value>>> {
) -> Box<dyn Future<Item = crate::models::TrustBundleResponse, Error = Error<serde_json::Value>>>
{
let configuration: &configuration::Configuration<C> = self.configuration.borrow();

let method = hyper::Method::GET;
Expand Down Expand Up @@ -464,7 +470,7 @@ where
}
})
.and_then(|body| {
let parsed: Result<::models::TrustBundleResponse, _> =
let parsed: Result<crate::models::TrustBundleResponse, _> =
serde_json::from_slice(&body);
parsed.map_err(Error::from)
}),
Expand Down
14 changes: 1 addition & 13 deletions edgelet/workload/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
// Copyright (c) Microsoft. All rights reserved.

#![deny(unused_extern_crates, warnings)]
#![deny(rust_2018_idioms, warnings)]
#![deny(clippy::all, clippy::pedantic)]
#![allow(clippy::module_name_repetitions, clippy::use_self)]

#[macro_use]
extern crate serde_derive;

#[macro_use]
extern crate failure;
extern crate futures;
extern crate hyper;
extern crate serde;
extern crate serde_json;
extern crate typed_headers;
extern crate url;

pub mod apis;
pub mod models;
15 changes: 10 additions & 5 deletions edgelet/workload/src/models/certificate_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
* Generated by: https://github.com/swagger-api/swagger-codegen.git
*/

use serde_derive::{Deserialize, Serialize};
#[allow(unused_imports)]
use serde_json::Value;

#[derive(Debug, Serialize, Deserialize)]
pub struct CertificateResponse {
#[serde(rename = "privateKey")]
private_key: ::models::PrivateKey,
private_key: crate::models::PrivateKey,
/// Base64 encoded PEM formatted byte array containing the certificate and its chain.
#[serde(rename = "certificate")]
certificate: String,
Expand All @@ -24,24 +25,28 @@ pub struct CertificateResponse {
}

impl CertificateResponse {
pub fn new(private_key: ::models::PrivateKey, certificate: String, expiration: String) -> Self {
pub fn new(
private_key: crate::models::PrivateKey,
certificate: String,
expiration: String,
) -> Self {
CertificateResponse {
private_key,
certificate,
expiration,
}
}

pub fn set_private_key(&mut self, private_key: ::models::PrivateKey) {
pub fn set_private_key(&mut self, private_key: crate::models::PrivateKey) {
self.private_key = private_key;
}

pub fn with_private_key(mut self, private_key: ::models::PrivateKey) -> Self {
pub fn with_private_key(mut self, private_key: crate::models::PrivateKey) -> Self {
self.private_key = private_key;
self
}

pub fn private_key(&self) -> &::models::PrivateKey {
pub fn private_key(&self) -> &crate::models::PrivateKey {
&self.private_key
}

Expand Down
1 change: 1 addition & 0 deletions edgelet/workload/src/models/decrypt_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Generated by: https://github.com/swagger-api/swagger-codegen.git
*/

use serde_derive::{Deserialize, Serialize};
#[allow(unused_imports)]
use serde_json::Value;

Expand Down
1 change: 1 addition & 0 deletions edgelet/workload/src/models/decrypt_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Generated by: https://github.com/swagger-api/swagger-codegen.git
*/

use serde_derive::{Deserialize, Serialize};
#[allow(unused_imports)]
use serde_json::Value;

Expand Down
1 change: 1 addition & 0 deletions edgelet/workload/src/models/encrypt_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Generated by: https://github.com/swagger-api/swagger-codegen.git
*/

use serde_derive::{Deserialize, Serialize};
#[allow(unused_imports)]
use serde_json::Value;

Expand Down
1 change: 1 addition & 0 deletions edgelet/workload/src/models/encrypt_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Generated by: https://github.com/swagger-api/swagger-codegen.git
*/

use serde_derive::{Deserialize, Serialize};
#[allow(unused_imports)]
use serde_json::Value;

Expand Down
Loading

0 comments on commit 4a1087b

Please sign in to comment.