Skip to content

Commit

Permalink
build: add xtask scripts (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
camshaft authored Oct 24, 2024
1 parent 58d8e80 commit 256c8a9
Show file tree
Hide file tree
Showing 27 changed files with 454 additions and 85 deletions.
2 changes: 2 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[alias]
xtask = "run --package xtask --"
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
integration/snapshots/*.snap filter=lfs diff=lfs merge=lfs -text
93 changes: 22 additions & 71 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,67 +38,24 @@ jobs:
export VERSIONS=$(echo $RAW_VERSIONS | jq -scR 'rtrimstr("\n")|split(" ")|.')
echo "versions=$VERSIONS" >> "$GITHUB_OUTPUT"
rustfmt:
checks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: actions-rs/toolchain@v1
id: toolchain
with:
toolchain: ${{ env.RUST_NIGHTLY_TOOLCHAIN }}
profile: minimal
override: true
components: rustfmt

- name: Run cargo fmt
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check

clippy:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- toolchain: stable
# fail on stable warnings
args: "-D warnings"
- toolchain: beta
steps:
- uses: actions/checkout@v3
with:
submodules: true

- uses: actions-rs/[email protected]
id: toolchain
with:
toolchain: ${{ matrix.toolchain }}
profile: minimal
override: true
components: clippy

- uses: camshaft/rust-cache@v1

- name: Cache node_modules
uses: actions/[email protected]
continue-on-error: true
with:
path: duvet/www/node_modules
key: node-modules-${{ runner.os }}-${{ hashFiles('duvet/www/package-lock.json') }}
- name: Install rustfmt toolchain
run: |
rustup toolchain install ${{ env.RUST_NIGHTLY_TOOLCHAIN }} --profile minimal --component rustfmt
rustup override set ${{ env.RUST_NIGHTLY_TOOLCHAIN }}
- name: Build script.js
- name: Install clippy toolchain
run: |
make duvet/www/public/script.js
rustup toolchain install stable --profile minimal --component clippy
rustup override set stable
# TODO translate json reports to in-action warnings
- name: Run cargo clippy
uses: actions-rs/[email protected]
with:
command: clippy
args: --all-features --all-targets -- -A clippy::uninlined_format_args ${{ matrix.args }}
- name: Run checks
run: |
cargo xtask checks --rustfmt-toolchain ${{ env.RUST_NIGHTLY_TOOLCHAIN }}
udeps:
runs-on: ubuntu-latest
Expand All @@ -107,12 +64,11 @@ jobs:
with:
submodules: true

- uses: actions-rs/toolchain@v1.0.7
- name: Install toolchain
id: toolchain
with:
toolchain: ${{ env.RUST_NIGHTLY_TOOLCHAIN }}
profile: minimal
override: true
run: |
rustup toolchain install ${{ env.RUST_NIGHTLY_TOOLCHAIN }} --profile minimal
rustup override set ${{ env.RUST_NIGHTLY_TOOLCHAIN }}
- uses: camshaft/rust-cache@v1

Expand All @@ -129,7 +85,7 @@ jobs:

- name: Build script.js
run: |
make duvet/www/public/script.js
cargo xtask build
- name: Run cargo udeps
run: cargo udeps --workspace --all-targets
Expand All @@ -148,11 +104,11 @@ jobs:
with:
lfs: true

- uses: actions-rs/toolchain@v1
- name: Install toolchain
id: toolchain
with:
toolchain: ${{ matrix.rust }}
override: true
run: |
rustup toolchain install ${{ matrix.rust }}
rustup override set ${{ matrix.rust }}
- uses: camshaft/rust-cache@v1
with:
Expand All @@ -165,14 +121,9 @@ jobs:
path: duvet/www/node_modules
key: node-modules-${{ runner.os }}-${{ hashFiles('duvet/www/package-lock.json') }}

- name: Build script.js
- name: Run tests
run: |
make duvet/www/public/script.js
- name: Run cargo test
uses: actions-rs/cargo@v1
with:
command: test
cargo xtask test
action: # make sure the action works on a clean machine without building
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
Cargo.lock
target
.history
*.snap.new
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ members = [
"duvet",
"duvet-core",
"duvet-macros",
"xtask",
]
resolver = "2"

Expand Down
14 changes: 0 additions & 14 deletions Makefile

This file was deleted.

10 changes: 10 additions & 0 deletions duvet/src/report/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,16 @@ impl Report {
html::report(&report, dir)?;
}

// used for internal duvet CI checks
if let Ok(file) = std::env::var("DUVET_INTERNAL_CI_JSON") {
json::report(&report, std::path::Path::new(&file))?;
}

// used for internal duvet CI checks
if let Ok(file) = std::env::var("DUVET_INTERNAL_CI_HTML") {
html::report(&report, std::path::Path::new(&file))?;
}

if self.ci {
ci::report(&report)?;
}
Expand Down
7 changes: 7 additions & 0 deletions integration/aws-cryptographic-material-providers-library.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name = "aws-cryptographic-material-providers-library"
repo = "https://github.com/aws/aws-cryptographic-material-providers-library"
version = "v1.7.0"
cmd = [
"make duvet"
]
html_report = "specification_compliance_report.html"
7 changes: 7 additions & 0 deletions integration/aws-database-encryption-sdk-dynamodb.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name = "aws-database-encryption-sdk-dynamodb"
repo = "https://github.com/aws/aws-database-encryption-sdk-dynamodb"
version = "v3.7.0"
cmd = [
"make duvet"
]
html_report = "specification_compliance_report.html"
7 changes: 7 additions & 0 deletions integration/aws-encryption-sdk-dafny.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name = "aws-encryption-sdk-dafny"
repo = "https://github.com/aws/aws-encryption-sdk-dafny"
version = "v4.1.0"
cmd = [
"make duvet"
]
html_report = "specification_compliance_report.html"
8 changes: 8 additions & 0 deletions integration/h3.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name = "h3"
repo = "https://github.com/hyperium/h3"
version = "c6b92cbca902a62850b72269384fcbc32d30cb96"
cmd = [
"bash ci/compliance/extract.sh",
"bash ci/compliance/report.sh",
]
html_report = "ci/compliance/report.html"
5 changes: 5 additions & 0 deletions integration/s2n-quic.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name = "s2n-quic"
repo = "https://github.com/aws/s2n-quic"
version = "005f9461612df4f882b91844fa978a5ee603e9f8"
cmd = ["bash scripts/compliance"]
html_report = "target/compliance/report.html"
5 changes: 5 additions & 0 deletions integration/s2n-tls.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name = "s2n-tls"
repo = "https://github.com/aws/s2n-tls"
version = "v1.5.5"
cmd = ["bash compliance/generate_report.sh"]
html_report = "compliance/report.html"
Git LFS file not shown
Git LFS file not shown
3 changes: 3 additions & 0 deletions integration/snapshots/aws-encryption-sdk-dafny.snap
Git LFS file not shown
3 changes: 3 additions & 0 deletions integration/snapshots/h3.snap
Git LFS file not shown
3 changes: 3 additions & 0 deletions integration/snapshots/s2n-quic.snap
Git LFS file not shown
3 changes: 3 additions & 0 deletions integration/snapshots/s2n-tls.snap
Git LFS file not shown
13 changes: 13 additions & 0 deletions xtask/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "xtask"
edition = "2021"
publish = false

[dependencies]
anyhow = "1"
clap = { version = "4", features = ["derive"] }
insta = { version = "1", features = ["json"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
toml = "0.8"
xshell = "0.2"
52 changes: 52 additions & 0 deletions xtask/src/args.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
use crate::Result;
use clap::Parser;
use xshell::Shell;

#[derive(Debug, Parser)]
pub enum Args {
Build(crate::build::Build),
Changelog(crate::changelog::Changelog),
Checks(crate::checks::Checks),
Publish(crate::publish::Publish),
Test(crate::tests::Tests),
}

impl Args {
pub fn run(&self, sh: &Shell) -> Result {
match self {
Args::Build(args) => args.run(sh).map(|_| ()),
Args::Changelog(args) => args.run(sh),
Args::Checks(args) => args.run(sh),
Args::Publish(args) => args.run(sh),
Args::Test(args) => args.run(sh),
}
}
}

pub trait FlagExt {
fn is_enabled(&self, default: bool) -> bool;
}

impl FlagExt for Option<bool> {
fn is_enabled(&self, default: bool) -> bool {
match self {
Some(v) => *v,
None => default,
}
}
}

/// Allows for argument flexibility
/// * `duvet` -> default
/// * `duvet --foo` -> true
/// * `duvet --foo=true` -> true
/// * `duvet --foo=false` -> false
impl FlagExt for Option<Option<bool>> {
fn is_enabled(&self, default: bool) -> bool {
match self {
Some(Some(v)) => *v,
Some(None) => true,
None => default,
}
}
}
37 changes: 37 additions & 0 deletions xtask/src/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use crate::{args::FlagExt as _, Result};
use clap::Parser;
use std::path::PathBuf;
use xshell::{cmd, Shell};

#[derive(Debug, Default, Parser)]
pub struct Build {
#[clap(long)]
pub release: Option<Option<bool>>,
}

impl Build {
pub fn run(&self, sh: &Shell) -> Result<PathBuf> {
{
let _dir = sh.push_dir("duvet/www");
cmd!(sh, "make").run()?;
}

let mut args = vec![];

let is_release = self.release.is_enabled(true);

if is_release {
args.push("--release".to_string());
}

cmd!(sh, "cargo build -p duvet {args...}").run()?;

let path = if is_release {
sh.current_dir().join("target/release/duvet")
} else {
sh.current_dir().join("target/debug/duvet")
};

Ok(path)
}
}
18 changes: 18 additions & 0 deletions xtask/src/changelog.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use crate::Result;
use clap::Parser;
use xshell::{cmd, Shell};

#[derive(Debug, Default, Parser)]
pub struct Changelog {}

impl Changelog {
pub fn run(&self, sh: &Shell) -> Result {
cmd!(
sh,
"npx conventional-changelog-cli -p conventionalcommits -i CHANGELOG.md -s"
)
.run()?;

Ok(())
}
}
Loading

0 comments on commit 256c8a9

Please sign in to comment.