From beb3884f493f249691c680d74cbdeff3e92e6ed4 Mon Sep 17 00:00:00 2001 From: David Bernard Date: Sat, 30 Dec 2023 13:29:01 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=89=20init=20cdviz-svc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 36 ++++++++++++++++++++++++++++++ Cargo.toml | 30 +++++++++++++++++++++++++ cdviz-svc/Cargo.toml | 19 ++++++++++++++++ cdviz-svc/src/main.rs | 24 ++++++++++++++++++++ justfile | 48 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 157 insertions(+) create mode 100644 .github/workflows/ci.yml create mode 100644 Cargo.toml create mode 100644 cdviz-svc/Cargo.toml create mode 100644 cdviz-svc/src/main.rs create mode 100644 justfile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..c092fc3 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,36 @@ +--- +name: ci + +on: + push: + workflow_dispatch: + +permissions: + contents: read + +jobs: + tests: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest] + env: + CARGO_TERM_COLOR: always + RUST_BACKTRACE: full + steps: + - uses: actions/checkout@v4 + - uses: jdx/rtx-action@v1 + - name: Cache cargo registry + uses: actions/cache@v3 + continue-on-error: false + with: + path: | + ~/.cargo/registry + ~/.cargo/git + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + restore-keys: | + ${{ runner.os }}-cargo- + - run: just check + - run: just lint + - run: just test diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..057168c --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,30 @@ +[workspace] +resolver = "2" +members = [ + "cdviz-svc", + # "examples/*", +] + +[workspace.package] +edition = "2021" +version = "0.1.0" +authors = ["David Bernard"] +license = "AGPL-3.0-or-later" +repository = "https://github.com/davidB/cdviz" +rust-version = "1.75" +publish = false + +[workspace.dependencies] +rstest = "0.18" + +[profile.dev.package.insta] +opt-level = 3 + +[profile.dev.package.similar] +opt-level = 3 + +[workspace.metadata.release] +pre-release-commit-message = "🚀 (cargo-release) version {{version}}" +tag-prefix = "" +tag-name = "{{prefix}}{{version}}" +tag-message = "🔖 {{version}}" diff --git a/cdviz-svc/Cargo.toml b/cdviz-svc/Cargo.toml new file mode 100644 index 0000000..0030739 --- /dev/null +++ b/cdviz-svc/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "cvdiz-svc" +description = "The service to collect cdevents" +readme = "README.md" +keywords = ["cd"] +categories = [] +edition.workspace = true +version.workspace = true +authors.workspace = true +repository.workspace = true +license.workspace = true +publish.workspace = true + +[dependencies] +axum = "0.7" +tokio = { version = "1.0", features = ["full"] } + +[dev-dependencies] +rstest = { workspace = true } diff --git a/cdviz-svc/src/main.rs b/cdviz-svc/src/main.rs new file mode 100644 index 0000000..8be059f --- /dev/null +++ b/cdviz-svc/src/main.rs @@ -0,0 +1,24 @@ +//! Run with +//! +//! ```not_rust +//! cargo run +//! ``` + +use axum::{response::Html, routing::get, Router}; + +#[tokio::main] +async fn main() { + // build our application with a route + let app = Router::new().route("/", get(handler)); + + // run it + let listener = tokio::net::TcpListener::bind("127.0.0.1:3000") + .await + .unwrap(); + println!("listening on {}", listener.local_addr().unwrap()); + axum::serve(listener, app).await.unwrap(); +} + +async fn handler() -> Html<&'static str> { + Html("

Hello, World!

") +} diff --git a/justfile b/justfile new file mode 100644 index 0000000..0828e6c --- /dev/null +++ b/justfile @@ -0,0 +1,48 @@ +requirements: + cargo install cargo-binstall + cargo binstall cargo-nextest + cargo binstall cargo-sort + cargo binstall cargo-hack + # cargo binstall cargo-insta + cargo binstall cargo-release + cargo binstall git-cliff + +check: + cargo hack check --each-feature --no-dev-deps + +build: + cargo build + +# Format the code and sort dependencies +format: + cargo fmt + cargo sort --workspace --grouped + +deny: + cargo deny check advisories + cargo deny check bans licenses sources + +# Lint the rust code +lint: + cargo fmt --all -- --check + cargo sort --workspace --grouped --check + cargo clippy --workspace --all-features --all-targets -- --deny warnings --allow deprecated --allow unknown-lints + +megalinter: + @just _container run --pull always --rm -it -v "$PWD:/tmp/lint:rw" "megalinter/megalinter:v7" + +# Launch tests +test: + cargo nextest run + cargo test --doc + cargo hack test --each-feature -- --test-threads=1 + +changelog: + git-cliff -o "CHANGELOG.md" + git add CHANGELOG.md && git commit -m "📝 update CHANGELOG" + +release *arguments: + cargo release --workspace --execute {{arguments}} + # git-cliff could not be used as `pre-release-hook` of cargo-release because it uses tag + git-cliff -o "CHANGELOG.md" + git add CHANGELOG.md && git commit -m "📝 update CHANGELOG" && git push