Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ci): improve feature handling and CI #428

Merged
merged 18 commits into from
Jul 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
[alias]
ci-build-all = "build --all-targets --all-features"
ci-build-inx = "build --all-targets --no-default-features --features inx,stardust"
ci-build-api = "build --all-targets --no-default-features --features api-core,api-history,analytics,stardust"
ci-check-all = "check --all-targets --all-features"
ci-check-inx = "check --all-targets --no-default-features --features inx,stardust"
ci-check-api = "check --all-targets --no-default-features --features api,stardust"

ci-clippy-all = "clippy --all-targets --all-features -- -D warnings"
ci-clippy-inx = "clippy --all-targets --no-default-features --features inx,stardust -- -D warnings"
ci-clippy-api = "clippy --all-targets --no-default-features --features api-core,api-history,analytics,stardust -- -D warnings"
ci-clippy-api = "clippy --all-targets --no-default-features --features api,stardust -- -D warnings"

ci-doctest = "test --doc --all-features --release"
ci-doctest = "test --doc --all-features"
ci-doc = "doc --all-features --no-deps --document-private-items"
ci-fmt = "fmt --all -- --check"
ci-test = "test --all-targets --all-features --release"
ci-test = "test --all-targets --all-features"
ci-toml = "sort --grouped --check"
ci-udeps = "udeps --all-targets --all-features --backend=depinfo"

Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/_build.yml → .github/workflows/_check.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build and Test
name: Check and Test

on:
workflow_call:
Expand All @@ -11,7 +11,7 @@ on:
type: string

jobs:
build-and-test:
check-and-test:
name: '${{ inputs.os }}, ${{ inputs.rust }}'
runs-on: ${{ inputs.os }}
# Unfortunately, we can't do this right now because `indexmap` does not seem to follow semver.
Expand Down Expand Up @@ -42,22 +42,22 @@ jobs:

- uses: Swatinem/rust-cache@v1

- name: Build with all features
- name: Check (all features)
uses: actions-rs/cargo@v1
with:
command: ci-build-all
command: ci-check-all

- name: Build with INX only
- name: Check (INX only)
if: contains(inputs.os, 'ubuntu')
uses: actions-rs/cargo@v1
with:
command: ci-build-inx
command: ci-check-inx

- name: Build with API only
- name: Check (API only)
if: contains(inputs.os, 'ubuntu')
uses: actions-rs/cargo@v1
with:
command: ci-build-api
command: ci-check-api

- name: Test
uses: actions-rs/cargo@v1
Expand Down
49 changes: 34 additions & 15 deletions .github/workflows/canary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,29 @@ on:

jobs:

build-and-test-1:
name: "build and test"
uses: ./.github/workflows/_build.yml
check-and-test-1:
name: "check and test"
uses: ./.github/workflows/_check.yml
with: { os: windows-latest, rust: stable }

build-and-test-2:
name: "build and test"
uses: ./.github/workflows/_build.yml
check-and-test-2:
name: "check and test"
uses: ./.github/workflows/_check.yml
with: { os: macos-latest, rust: stable }

build-and-test-3:
name: "build and test"
uses: ./.github/workflows/_build.yml
check-and-test-3:
name: "check and test"
uses: ./.github/workflows/_check.yml
with: { os: ubuntu-latest, rust: beta }

build-and-test-4:
name: "build and test"
uses: ./.github/workflows/_build.yml
check-and-test-4:
name: "check and test"
uses: ./.github/workflows/_check.yml
with: { os: windows-latest, rust: beta }

build-and-test-5:
name: "build and test"
uses: ./.github/workflows/_build.yml
check-and-test-5:
name: "check and test"
uses: ./.github/workflows/_check.yml
with: { os: macos-latest, rust: beta }

docker:
Expand Down Expand Up @@ -58,4 +58,23 @@ jobs:
with:
command: ci-udeps

check-all-features:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true

- uses: actions-rs/cargo@v1
with:
command: install
args: --force cargo-all-features

- uses: actions-rs/cargo@v1
with:
command: check-all-features

6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ concurrency:
cancel-in-progress: true

jobs:
build-and-test:
name: "build and test"
uses: ./.github/workflows/_build.yml
check-and-test:
name: "check and test"
uses: ./.github/workflows/_check.yml
with: { os: ubuntu-latest, rust: stable }

format:
Expand Down
16 changes: 4 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ uuid = { version = "1.1", default-features = false, features = ["v4"] }
auth-helper = { version = "0.3", default-features = false, optional = true }
axum = { version = "0.5", default-features = false, features = ["http1", "json", "query", "original-uri", "headers"], optional = true }
ed25519 = { version = "1.5", default-features = false, features = ["alloc", "pkcs8", "pem"], optional = true }
ed25519-dalek = { version = "1.0", default-features = false, optional = true }
ed25519-dalek = { version = "1.0", default-features = false, features = ["u64_backend"], optional = true }
hex = { version = "0.4", default-features = false, optional = true }
hyper = { version = "0.14", default-features = false, features = ["server", "tcp", "stream"], optional = true }
lazy_static = { version = "1.4", default-features = false, optional = true }
Expand Down Expand Up @@ -82,14 +82,11 @@ packable = { version = "0.4", default-features = false }

[features]
default = [
"analytics",
"api-history",
"api-core",
"api",
"inx",
"stardust",
"metrics",
"stardust",
]
analytics = []
api = [
"dep:auth-helper",
"dep:axum",
Expand All @@ -106,12 +103,7 @@ api = [
"dep:tower",
"dep:tower-http",
"dep:zeroize",
]
api-history = [
"api",
]
api-core = [
"api",
"stardust",
]
console = [
"dep:console-subscriber",
Expand Down
69 changes: 39 additions & 30 deletions bin/inx-chronicle/src/api/extractors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

use async_trait::async_trait;
use axum::extract::{FromRequest, Query};
use chronicle::types::stardust::milestone::MilestoneTimestamp;
use serde::Deserialize;
use time::{Duration, OffsetDateTime};

Expand Down Expand Up @@ -44,43 +43,53 @@ pub struct TimeRangeQuery {
end_timestamp: Option<u32>,
}

#[derive(Copy, Clone)]
pub struct TimeRange {
pub start_timestamp: MilestoneTimestamp,
pub end_timestamp: MilestoneTimestamp,
}
#[cfg(feature = "stardust")]
mod stardust {
use chronicle::types::stardust::milestone::MilestoneTimestamp;

fn days_ago_utc(days: i64) -> u32 {
let then = OffsetDateTime::now_utc() - Duration::days(days);
then.unix_timestamp() as u32
}
use super::*;

fn now_utc() -> u32 {
OffsetDateTime::now_utc().unix_timestamp() as u32
}
#[derive(Copy, Clone)]
pub struct TimeRange {
pub start_timestamp: MilestoneTimestamp,
pub end_timestamp: MilestoneTimestamp,
}

#[async_trait]
impl<B: Send> FromRequest<B> for TimeRange {
type Rejection = ApiError;
fn days_ago_utc(days: i64) -> u32 {
let then = OffsetDateTime::now_utc() - Duration::days(days);
then.unix_timestamp() as u32
}

async fn from_request(req: &mut axum::extract::RequestParts<B>) -> Result<Self, Self::Rejection> {
let Query(TimeRangeQuery {
start_timestamp,
end_timestamp,
}) = Query::<TimeRangeQuery>::from_request(req)
.await
.map_err(ApiError::QueryError)?;
let time_range = TimeRange {
start_timestamp: start_timestamp.unwrap_or_else(|| days_ago_utc(30)).into(),
end_timestamp: end_timestamp.unwrap_or_else(now_utc).into(),
};
if time_range.end_timestamp < time_range.start_timestamp {
return Err(ApiError::BadTimeRange);
fn now_utc() -> u32 {
OffsetDateTime::now_utc().unix_timestamp() as u32
}

#[async_trait]
impl<B: Send> FromRequest<B> for TimeRange {
type Rejection = ApiError;

async fn from_request(req: &mut axum::extract::RequestParts<B>) -> Result<Self, Self::Rejection> {
let Query(TimeRangeQuery {
start_timestamp,
end_timestamp,
}) = Query::<TimeRangeQuery>::from_request(req)
.await
.map_err(ApiError::QueryError)?;
let time_range = TimeRange {
start_timestamp: start_timestamp.unwrap_or_else(|| days_ago_utc(30)).into(),
end_timestamp: end_timestamp.unwrap_or_else(now_utc).into(),
};
if time_range.end_timestamp < time_range.start_timestamp {
return Err(ApiError::BadTimeRange);
}
Ok(time_range)
}
Ok(time_range)
}
}

#[cfg(feature = "stardust")]
pub use stardust::*;

#[derive(Copy, Clone, Deserialize)]
#[serde(default)]
pub struct Included {
Expand Down
66 changes: 37 additions & 29 deletions bin/inx-chronicle/src/api/responses.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
// Copyright 2022 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

use chronicle::{
db::collections::SyncData,
types::{ledger::LedgerInclusionState, tangle::MilestoneIndex},
};
use serde::{Deserialize, Serialize};

macro_rules! impl_success_response {
Expand Down Expand Up @@ -33,31 +29,6 @@ pub struct InfoResponse {

impl_success_response!(InfoResponse);

/// An aggregation type that represents the ranges of completed milestones and gaps.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct SyncDataDto(pub SyncData);

impl_success_response!(SyncDataDto);

#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Record {
pub id: String,
pub inclusion_state: Option<LedgerInclusionState>,
pub milestone_index: Option<MilestoneIndex>,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Transfer {
pub transaction_id: String,
pub output_index: u16,
pub is_spending: bool,
pub inclusion_state: Option<LedgerInclusionState>,
pub block_id: String,
pub amount: u64,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MaybeSpentOutput {
Expand All @@ -71,3 +42,40 @@ pub struct Unlock {
pub block_id: String,
pub block: Value,
}

/// An aggregation type that represents the ranges of completed milestones and gaps.
#[cfg(feature = "stardust")]
mod stardust {
use chronicle::{
db::collections::SyncData,
types::{ledger::LedgerInclusionState, tangle::MilestoneIndex},
};
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct SyncDataDto(pub SyncData);

impl_success_response!(SyncDataDto);

#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Record {
pub id: String,
pub inclusion_state: Option<LedgerInclusionState>,
pub milestone_index: Option<MilestoneIndex>,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Transfer {
pub transaction_id: String,
pub output_index: u16,
pub is_spending: bool,
pub inclusion_state: Option<LedgerInclusionState>,
pub block_id: String,
pub amount: u64,
}
}

#[cfg(feature = "stardust")]
pub use stardust::*;
Loading