Skip to content

Commit

Permalink
🚀 Add Rust Test Coverage GitHub Action and update workflows (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
yezz123 authored Feb 7, 2025
1 parent 9cd0298 commit 9ddb1d4
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/rust-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Rust Test

on:
workflow_call:
secrets:
codecov_token:
required: false

jobs:
test:
permissions:
# required for all workflows
security-events: write
checks: write
pull-requests: write
# only required for workflows in private repositories
actions: read
contents: read
runs-on: ubuntu-latest
name: Rust Test Coverage
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Rust Test
uses: astraly-labs/workflows/rust/test@main
3 changes: 3 additions & 0 deletions .github/workflows/rust.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ jobs:
Scan:
uses: astraly-labs/workflows/.github/workflows/rust-scan.yaml@main
secrets: inherit
Test:
uses: astraly-labs/workflows/.github/workflows/rust-test.yaml@main
secrets: inherit
54 changes: 54 additions & 0 deletions rust/test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Rust Test Coverage - Github Action

This action runs Rust tests with code coverage using cargo-llvm-cov and nextest

The action runs the following:
- Sets up Rust toolchain
- Installs cargo-llvm-cov and nextest
- Runs tests with coverage collection
- Uploads coverage reports to Codecov

## Inputs

```yaml
fail_ci:
description: 'Fail CI if coverage upload fails'
required: false
default: false
token:
description: 'Codecov token'
required: false
```
## Outputs
- LCOV coverage report
- Coverage data uploaded to Codecov
## Detailed example
```yaml
name: Rust Test Coverage

on:
pull_request: {}
workflow_dispatch: {}
push:
branches:
- main

jobs:
test:
name: Rust Tests
runs-on: ubuntu-latest

steps:
- name: Checkout source code
uses: actions/checkout@v3

- name: Run Tests
uses: astraly-labs/workflows/rust/test@main
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci: false
```
46 changes: 46 additions & 0 deletions rust/test/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Rust Test Coverage
description: Rust Test Coverage using cargo-llvm-cov and nextest
author: 'Yezz123'
inputs:
fail_ci:
description: 'Fail CI if coverage upload fails'
required: false
default: false
type: choice
options:
- 'true'
- 'false'
token:
description: 'Codecov token'
required: false

runs:
using: composite
steps:
- name: Setup Rust toolchain
shell: bash
run: rustup show

- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov

- name: Install nextest
uses: taiki-e/install-action@nextest

- name: Clean workspace
shell: bash
run: cargo llvm-cov clean --workspace

- name: Setup Rust cache
uses: Swatinem/rust-cache@v2

- name: Run tests with coverage
shell: bash
run: cargo llvm-cov nextest --release --lcov --output-path lcov.info

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
files: lcov.info
token: ${{ inputs.token }}
fail_ci_if_error: ${{ inputs.fail_ci }}
14 changes: 14 additions & 0 deletions rust/test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "@rust/test",
"version": "1.0.0",
"description": "This action runs Rust tests with code coverage using cargo-llvm-cov and nextest",
"main": "index.js",
"repository": {
"type": "git",
"url": "https://github.com/astraly-labs/workflows",
"directory": "rust/test"
},
"private": false,
"author": "Astraly Labs",
"license": "UNLICENSED"
}

0 comments on commit 9ddb1d4

Please sign in to comment.