From 6f85e2eb465edb2022428c13a33c25a8c1944dd1 Mon Sep 17 00:00:00 2001 From: David Rousselie Date: Tue, 5 Apr 2022 21:04:42 +0200 Subject: [PATCH] Update Github CI configuration --- .../actions/cargo-tarpaulin-action/action.yml | 22 --- .../cargo-tarpaulin-action/cargo-tarpaulin.sh | 15 -- .github/workflows/audit.yml | 10 +- .github/workflows/ci.yml | 149 +++++++++++++----- README.md | 6 +- api/src/configuration.rs | 2 +- api/src/lib.rs | 4 +- api/tests/api/helpers.rs | 2 +- 8 files changed, 125 insertions(+), 85 deletions(-) delete mode 100644 .github/actions/cargo-tarpaulin-action/action.yml delete mode 100755 .github/actions/cargo-tarpaulin-action/cargo-tarpaulin.sh diff --git a/.github/actions/cargo-tarpaulin-action/action.yml b/.github/actions/cargo-tarpaulin-action/action.yml deleted file mode 100644 index b656b33..0000000 --- a/.github/actions/cargo-tarpaulin-action/action.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: 'cargo tarpaulin' -description: 'Gather Rust code coverage information with Tarpaulin' -inputs: - version: - description: 'The version of cargo-tarpaulin to install' - required: true - default: '0.19.0' - - args: - required: false - description: 'Extra command line arguments passed to cargo-tarpaulin' - - out-type: - description: 'Output format of coverage report [possible values: Json, Toml, Stdout, Xml, Html, Lcov]' - required: false - default: 'Xml' - -runs: - using: 'composite' - steps: - - run: ${{ github.action_path }}/cargo-tarpaulin.sh ${{ inputs.out-type }} ${{ inputs.version }} ${{ inputs.args }} - shell: bash diff --git a/.github/actions/cargo-tarpaulin-action/cargo-tarpaulin.sh b/.github/actions/cargo-tarpaulin-action/cargo-tarpaulin.sh deleted file mode 100755 index 363b0d1..0000000 --- a/.github/actions/cargo-tarpaulin-action/cargo-tarpaulin.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -sudo apt-get update -y -sudo apt-get install -y --no-install-recommends openssl taskwarrior - -out_type="$1" -version="$2" -args="$3" -tar_file="cargo-tarpaulin-${version}-travis.tar.gz" - -wget "https://github.com/xd009642/tarpaulin/releases/download/${version}/${tar_file}" -tar zxvf "$tar_file" -chmod +x cargo-tarpaulin - -exec env RUST_LOG=debug ./cargo-tarpaulin tarpaulin --ignore-tests -o "$out_type" $args diff --git a/.github/workflows/audit.yml b/.github/workflows/audit.yml index f7302be..7b47dbf 100644 --- a/.github/workflows/audit.yml +++ b/.github/workflows/audit.yml @@ -10,7 +10,15 @@ jobs: security_audit: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 + - name: Checkout repository + uses: actions/checkout@v3 + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + override: true + - uses: Swatinem/rust-cache@v1 - uses: actions-rs/audit-check@v1 with: token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 533430d..9e5fbfb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,57 +1,126 @@ -on: [push] - name: CI +on: + push: + branches: + - main + pull_request: + jobs: - format: - name: rustfmt + + rustfmt: + name: Rustfmt runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - toolchain: nightly - components: rustfmt - override: true - - uses: LoliGothick/rustfmt-check@v0.2 - with: - token: ${{ secrets.GITHUB_TOKEN }} - flags: --all - options: --manifest-path=Cargo.toml - - build_and_test: - name: Build & test - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - - uses: actions-rs/toolchain@v1 + - name: Checkout repository + uses: actions/checkout@v3 + - name: Install Rust toolchain + uses: actions-rs/toolchain@v1 with: toolchain: stable - components: clippy + profile: minimal + components: rustfmt + - name: Check formatting + uses: actions-rs/cargo@v1 + with: + command: fmt + args: --all -- --check + build: + name: Build + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + - name: Install Rust toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + - name: Install Wasm Rust toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + target: wasm32-unknown-unknown + - uses: Swatinem/rust-cache@v1 + with: + sharedKey: ci - uses: actions-rs/cargo@v1 with: command: build - args: --release --all-features + args: --all-features --workspace - - uses: actions-rs/clippy-check@v1 + test: + needs: build + name: Test Suite + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + - name: Install Rust toolchain + uses: actions-rs/toolchain@v1 with: - token: ${{ secrets.GITHUB_TOKEN }} - args: --tests -- -D warnings + toolchain: stable + profile: minimal + - uses: awalsh128/cache-apt-pkgs-action@v1 + with: + packages: taskwarrior + version: 1.0 + - uses: Swatinem/rust-cache@v1 + with: + sharedKey: ci + - uses: actions-rs/cargo@v1 + with: + command: test + args: --all-features --workspace + clippy: + needs: build + name: Clippy + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + - name: Install Rust toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + components: clippy + - uses: Swatinem/rust-cache@v1 + with: + sharedKey: ci + - name: Clippy check + uses: actions-rs/cargo@v1 + with: + command: clippy + args: --all-targets --all-features --workspace -- -D warnings + + coverage: + name: Code coverage + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + - name: Install Rust toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + - uses: awalsh128/cache-apt-pkgs-action@v1 + with: + packages: taskwarrior + version: 1.0 + - uses: Swatinem/rust-cache@v1 - name: Run cargo-tarpaulin - uses: ./.github/actions/cargo-tarpaulin-action/ + uses: actions-rs/tarpaulin@v0.1 with: - args: '-- --test-threads 1' - - - name: Upload to codecov.io - uses: codecov/codecov-action@v1.0.2 + args: '--all-features --workspace --ignore-tests --out Lcov' + - name: Upload to Coveralls + # upload only if push + if: ${{ github.event_name == 'push' }} + uses: coverallsapp/github-action@master with: - token: ${{secrets.CODECOV_TOKEN}} - - - name: Archive code coverage results - uses: actions/upload-artifact@v1 - with: - name: code-coverage-report - path: cobertura.xml + github-token: ${{ secrets.GITHUB_TOKEN }} + path-to-lcov: './lcov.info' diff --git a/README.md b/README.md index 363c836..b951354 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # Contextswitch -[![AGPL License](https://img.shields.io/badge/license-AGPL-blue.svg)](http://www.gnu.org/licenses/agpl-3.0) -[![codecov](https://codecov.io/gh/dax/contextswitch/branch/main/graph/badge.svg?token=CHUSURDB5Q)](https://codecov.io/gh/dax/contextswitch) -![CI](https://github.com/dax/contextswitch/actions/workflows/ci.yml/badge.svg) +[![AGPL License](https://img.shields.io/badge/license-AGPL-blue.svg)](http://www.gnu.org/licenses/agpl-3.0) +[![Coverage Status](https://coveralls.io/repos/github/dax/contextswitch/badge.svg?branch=main)](https://coveralls.io/github/dax/contextswitch?branch=main) +[![CI](https://github.com/dax/contextswitch/workflows/CI/badge.svg)](https://github.com/dax/contextswitch/actions) Contextswitch is a todo list application linking bookmarks to a task. Integrations with third parties applications add context to a task: diff --git a/api/src/configuration.rs b/api/src/configuration.rs index 5c04d1f..531d45d 100644 --- a/api/src/configuration.rs +++ b/api/src/configuration.rs @@ -29,7 +29,7 @@ impl Settings { let config_file_required = file.is_some(); let config_path = env::var("CONFIG_PATH").unwrap_or_else(|_| "config".into()); let config_file = file.unwrap_or_else(|| { - env::var("CONFIG_FILE").unwrap_or_else(|_| format!("{}/dev", &config_path).into()) + env::var("CONFIG_FILE").unwrap_or_else(|_| format!("{}/dev", &config_path)) }); let default_config_file = format!("{}/default", config_path); diff --git a/api/src/lib.rs b/api/src/lib.rs index 5f8e53f..767dc04 100644 --- a/api/src/lib.rs +++ b/api/src/lib.rs @@ -55,9 +55,9 @@ pub fn run(listener: TcpListener, settings: &Settings) -> Result String { let listener = TcpListener::bind("127.0.0.1:0").expect("Failed to bind random port"); let port = listener.local_addr().unwrap().port(); - let server = contextswitch_api::run(listener, &settings).expect("Failed to bind address"); + let server = contextswitch_api::run(listener, settings).expect("Failed to bind address"); let _ = tokio::spawn(server); format!("http://127.0.0.1:{}", port) }