From 23d964b051b4e7eb8db83f1fe4e73763dbed69c3 Mon Sep 17 00:00:00 2001 From: Arunanshu Biswas Date: Sat, 17 Feb 2024 16:46:26 +0530 Subject: [PATCH 1/6] ci(actions): implement code coverage --- .github/workflows/build.yml | 53 ++++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4d7de6a02..8958c8e3a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,15 +7,20 @@ on: - '**.rs' - 'Cargo.*' - '*/Cargo.*' + - '.github/workflows/*' name: Build and Test env: RUSTFLAGS: "-D warnings" +defaults: + run: + shell: bash + jobs: test: - name: Build and test on ${{ matrix.os }} with ${{ matrix.features }} + name: Build and test on ${{ matrix.os }} runs-on: ${{ matrix.os }} strategy: fail-fast: false @@ -35,9 +40,9 @@ jobs: with: shared-key: ${{ runner.os }}-cargo - - uses: taiki-e/install-action@v1 + - uses: taiki-e/install-action@v2 with: - tool: cargo-hack + tool: cargo-hack,cargo-llvm-cov,nextest # - name: Check benchmarks # uses: actions-rs/cargo@v1 @@ -57,4 +62,44 @@ jobs: run: cargo hack doc --verbose --no-deps --each-feature --no-dev-deps --optional-deps url -p rumqttc -p rumqttd - name: Test rumqttc and rumqttd - run: cargo hack test --verbose --each-feature --optional-deps url -p rumqttc -p rumqttd + run: | + # each of them produces their own llvm-cov-target profraw data + cargo hack --each-feature --optional-deps url llvm-cov -p rumqttc -p rumqttd --no-report nextest + + - name: Upload coverage artifacts + uses: actions/upload-artifact@v4 + with: + name: coverage + path: target/llvm-cov-target/ + + upload-coverage: + runs-on: ubuntu-latest + needs: [test] + + steps: + - uses: actions/checkout@v4 + + - name: get coverage files + uses: actions/download-artifact@v4 + with: + name: coverage + path: target/llvm-cov-target/ + + - uses: taiki-e/install-action@v2 + with: + tool: cargo-llvm-cov + + # combines the llvm-cov-target/*.profraw data + - name: Create coverage report + run: cargo llvm-cov report --html + + - name: Install Smokeshow + run: pipx install smokeshow + + - name: Upload code coverage to smokeshow + run: smokeshow upload target/llvm-cov/html/ + env: + SMOKESHOW_GITHUB_STATUS_DESCRIPTION: 'Code Coverage: {coverage-percentage}' + SMOKESHOW_GITHUB_COVERAGE_THRESHOLD: 50 + SMOKESHOW_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SMOKESHOW_GITHUB_PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }} From bf441841d756417699e27fa558323e0c59d92bae Mon Sep 17 00:00:00 2001 From: Arunanshu Biswas Date: Sat, 17 Feb 2024 17:32:06 +0530 Subject: [PATCH 2/6] ci(actions): use coveralls to upload lcov files --- .github/workflows/build.yml | 50 ++++++++++++------------------------- 1 file changed, 16 insertions(+), 34 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8958c8e3a..96ea5312f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -30,7 +30,7 @@ jobs: - macOS-latest - windows-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable with: @@ -63,43 +63,25 @@ jobs: - name: Test rumqttc and rumqttd run: | - # each of them produces their own llvm-cov-target profraw data cargo hack --each-feature --optional-deps url llvm-cov -p rumqttc -p rumqttd --no-report nextest - - name: Upload coverage artifacts - uses: actions/upload-artifact@v4 + - name: Combine coverage + run: cargo llvm-cov report --lcov --output-path coverage.lcov + + - name: Upload Coverage Report + uses: coverallsapp/github-action@v2.2.3 with: - name: coverage - path: target/llvm-cov-target/ + github-token: ${{ secrets.GITHUB_TOKEN }} + file: ./coverage.lcov + parallel: true + flag-name: run-${{ matrix.os }}-cargo - upload-coverage: - runs-on: ubuntu-latest + finish-coverage: needs: [test] - + runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - - name: get coverage files - uses: actions/download-artifact@v4 + - name: Finish Coverage Report + uses: coverallsapp/github-action@v2.2.3 with: - name: coverage - path: target/llvm-cov-target/ - - - uses: taiki-e/install-action@v2 - with: - tool: cargo-llvm-cov - - # combines the llvm-cov-target/*.profraw data - - name: Create coverage report - run: cargo llvm-cov report --html - - - name: Install Smokeshow - run: pipx install smokeshow - - - name: Upload code coverage to smokeshow - run: smokeshow upload target/llvm-cov/html/ - env: - SMOKESHOW_GITHUB_STATUS_DESCRIPTION: 'Code Coverage: {coverage-percentage}' - SMOKESHOW_GITHUB_COVERAGE_THRESHOLD: 50 - SMOKESHOW_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SMOKESHOW_GITHUB_PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }} + github-token: ${{ secrets.GITHUB_TOKEN }} + parallel-finished: true From 0bde24009faf2ae68e48970417b2b74a17b432ef Mon Sep 17 00:00:00 2001 From: Arunanshu Biswas Date: Sat, 17 Feb 2024 18:10:35 +0530 Subject: [PATCH 3/6] ci(actions): remove duplicate workflow and run job when pushed to main --- .github/workflows/build.yml | 3 ++ .github/workflows/main.yml | 80 ------------------------------------- 2 files changed, 3 insertions(+), 80 deletions(-) delete mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 96ea5312f..e773d60dc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,6 +8,9 @@ on: - 'Cargo.*' - '*/Cargo.*' - '.github/workflows/*' + push: + branches: + - main name: Build and Test diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index fd63b1c22..000000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,80 +0,0 @@ -on: - push: - branches: - - main - -name: main - -env: - PROJECT_ID: ${{ secrets.GCE_PROJECT }} - GCE_INSTANCE: ${{ secrets.GCE_INSTANCE }} - GCE_INSTANCE_ZONE: ${{ secrets.GCE_INSTANCE_ZONE }} - -jobs: - test: - name: Source test - # runs-on: [self-hosted, linux, X64, rumqtt] - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: dtolnay/rust-toolchain@stable - with: - components: clippy - - run: cargo test --all-features - - # deploy: - # name: Source build, docker build and deploy - # runs-on: [self-hosted, linux, X64, rumqtt] - - # steps: - # - uses: actions/checkout@v2 - - # # Install cargo - # - uses: actions-rs/toolchain@v1 - # with: - # toolchain: stable - - # # Build - # - name: Release build rumqtt - # uses: actions-rs/cargo@v1 - # with: - # command: build - # args: --release --all-features - - # # Setup gcloud CLI - # - name: Gcloud commandline setup - # uses: GoogleCloudPlatform/github-actions/setup-gcloud@master - # with: - # version: '290.0.1' - # service_account_key: ${{ secrets.GCE_SA_KEY }} - # project_id: ${{ secrets.GCE_PROJECT }} - - # # Configure Docker to use the gcloud command-line tool as a credential - # helper for authentication - # - name: Docker google cloud registry auth - # run: |- - # gcloud --quiet auth configure-docker - - # # Copy rumqttd and config files - # - name: Prepare config and binary - # run: |- - # cp -r target/release/rumqttd docker/stage/ - # cp -r rumqttd/config docker/stage/ - - # # Build the Docker image - # - name: Docker build - # working-directory: docker - # run: |- - # docker build --tag "asia.gcr.io/$PROJECT_ID/$GCE_INSTANCE-image:$GITHUB_SHA" . - - # # Push the Docker image to Google Container Registry - # - name: Docker image publish - # run: |- - # docker push "asia.gcr.io/$PROJECT_ID/$GCE_INSTANCE-image:$GITHUB_SHA" - - # # Deploy the container - # - name: Deploy to google cloud - # run: |- - # gcloud compute instances update-container "$GCE_INSTANCE" \ - # --zone "$GCE_INSTANCE_ZONE" \ - # --container-image "asia.gcr.io/$PROJECT_ID/$GCE_INSTANCE-image:$GITHUB_SHA" From 9a4a6165a5dd1fa5b9d156114b5a01415b6f3267 Mon Sep 17 00:00:00 2001 From: Arunanshu Biswas Date: Mon, 19 Feb 2024 21:04:00 +0530 Subject: [PATCH 4/6] ci(actions): test docs as an additional step --- .github/workflows/build.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e773d60dc..e8dedcae8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -64,6 +64,9 @@ jobs: if: ${{ matrix.os != 'windows-latest' }} run: cargo hack doc --verbose --no-deps --each-feature --no-dev-deps --optional-deps url -p rumqttc -p rumqttd + - name: Doctests + run: cargo hack --each-feature --optional-deps url test --doc -p rumqttc -p rumqttd + - name: Test rumqttc and rumqttd run: | cargo hack --each-feature --optional-deps url llvm-cov -p rumqttc -p rumqttd --no-report nextest From 75882f5ffeb85a0f7ca23a648786ae56f9d0021e Mon Sep 17 00:00:00 2001 From: Arunanshu Biswas Date: Tue, 20 Feb 2024 11:10:29 +0530 Subject: [PATCH 5/6] docs(readme): add coverage badge to readme --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index c3a81b773..c20f0ed1b 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,9 @@ build status + + Coverage Status + Discord chat From a860eebbc873f99e539cd602f8ec746f0b761db7 Mon Sep 17 00:00:00 2001 From: Arunanshu Biswas Date: Tue, 20 Feb 2024 11:42:06 +0530 Subject: [PATCH 6/6] ci(actions): rename workflow to `CI` and include it in README --- .github/workflows/{build.yml => ci.yml} | 2 +- README.md | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) rename .github/workflows/{build.yml => ci.yml} (99%) diff --git a/.github/workflows/build.yml b/.github/workflows/ci.yml similarity index 99% rename from .github/workflows/build.yml rename to .github/workflows/ci.yml index e8dedcae8..13d2b2c98 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/ci.yml @@ -12,7 +12,7 @@ on: branches: - main -name: Build and Test +name: CI env: RUSTFLAGS: "-D warnings" diff --git a/README.md b/README.md index c20f0ed1b..92cc0c97d 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@
- rumqtt Logo + rumqtt Logo