Skip to content

Commit

Permalink
Initial Version
Browse files Browse the repository at this point in the history
  • Loading branch information
Sewer56 committed Jun 21, 2024
1 parent 284fd03 commit fe18f4a
Show file tree
Hide file tree
Showing 6 changed files with 414 additions and 1 deletion.
158 changes: 158 additions & 0 deletions .github/workflows/test-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
name: Test Build Workflow

on:
schedule:
- cron: '0 0 * * *' # Run daily at midnight
workflow_dispatch:
push:
tags:
- 'v1'
- 'v1-test'
paths:
- 'action.yml'
- '.github/workflows/test-build-workflow.yml'
pull_request:
branches: [ master ]
paths:
- 'action.yml'
- '.github/workflows/test-build-workflow.yml'

jobs:
test-coverage-build:
strategy:
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
use-cross: false
- os: ubuntu-latest
target: i686-unknown-linux-gnu
use-cross: false
- os: ubuntu-latest
target: aarch64-unknown-linux-gnu
use-cross: true
- os: ubuntu-latest
target: armv7-unknown-linux-gnueabihf
use-cross: true
- os: windows-latest
target: x86_64-pc-windows-msvc
use-cross: false
- os: windows-latest
target: i686-pc-windows-msvc
use-cross: false
- os: windows-latest
target: aarch64-pc-windows-msvc
use-cross: false
- os: macos-13 # Intel
target: x86_64-apple-darwin
use-cross: false
- os: macos-14 # M1/M2 (aarch64)
target: aarch64-apple-darwin
use-cross: false
- os: ubuntu-latest
target: x86_64-pc-windows-gnu
use-cross: true
label: '[Wine] x86_64-pc-windows-gnu'
- os: ubuntu-latest
target: i686-pc-windows-gnu
use-cross: true
label: '[Wine] i686-pc-windows-gnu'
runs-on: ${{ matrix.os }}
steps:
- name: Checkout Test Repository
uses: actions/checkout@v4
with:
repository: Sewer56/prs-rs
ref: d08599ed5473616f57d57a0966939e1a5dbda9b4
- name: Test Coverage Build
uses: Reloaded-Project/devops-rust-test-and-coverage@v1-test
with:
rust-toolchain: stable
target: ${{ matrix.target }}
use-cross: ${{ matrix.use-cross }}
features: 'c-exports,std,build-binary'
no-default-features: true
additional-test-args: '--ignored --test-threads=1'
codecov-token: ${{ secrets.CODECOV_TOKEN }}

test-nightly-beta-build:
strategy:
matrix:
rust-toolchain: [nightly, beta]
runs-on: ubuntu-latest
steps:
- name: Checkout Test Repository
uses: actions/checkout@v4
with:
repository: Sewer56/prs-rs
ref: d08599ed5473616f57d57a0966939e1a5dbda9b4
- name: Test Nightly/Beta Build
uses: Reloaded-Project/devops-rust-test-and-coverage@v1-test
with:
rust-toolchain: ${{ matrix.rust-toolchain }}
target: x86_64-unknown-linux-gnu
features: 'c-exports,std,build-binary'
no-default-features: true
additional-test-args: '--ignored --test-threads=1'
codecov-token: ${{ secrets.CODECOV_TOKEN }}

test-skipping-rust-install:
strategy:
matrix:
include:
- os: ubuntu-latest
rust-toolchain: stable
target: x86_64-unknown-linux-gnu
- os: windows-latest
rust-toolchain: stable
target: x86_64-pc-windows-msvc
- os: macos-13 # Intel
rust-toolchain: stable
target: x86_64-apple-darwin
runs-on: ${{ matrix.os }}
steps:
- name: Checkout Test Repository
uses: actions/checkout@v4
with:
repository: Sewer56/prs-rs
ref: d08599ed5473616f57d57a0966939e1a5dbda9b4
- name: Install Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: ${{ matrix.rust-toolchain }}
target: ${{ matrix.target }}
- name: Test Skipping Rust Install
uses: Reloaded-Project/devops-rust-test-and-coverage@v1-test
with:
rust-toolchain: ${{ matrix.rust-toolchain }}
target: ${{ matrix.target }}
install-rust-toolchain: false
codecov-token: ${{ secrets.CODECOV_TOKEN }}

test-skipping-rust-cache:
runs-on: ubuntu-latest
steps:
- name: Checkout Test Repository
uses: actions/checkout@v4
with:
repository: Sewer56/prs-rs
ref: d08599ed5473616f57d57a0966939e1a5dbda9b4
- name: Test Skipping Rust Cache
uses: Reloaded-Project/devops-rust-test-and-coverage@v1-test
with:
setup-rust-cache: false
codecov-token: ${{ secrets.CODECOV_TOKEN }}

test-skipping-coverage-upload:
runs-on: ubuntu-latest
steps:
- name: Checkout Test Repository
uses: actions/checkout@v4
with:
repository: Sewer56/prs-rs
ref: d08599ed5473616f57d57a0966939e1a5dbda9b4
- name: Test Skipping Coverage Upload
uses: Reloaded-Project/devops-rust-test-and-coverage@v1-test
with:
upload-coverage: false
codecov-token: ${{ secrets.CODECOV_TOKEN }}
7 changes: 7 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2023 Sewer56

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
141 changes: 141 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
<div align="center">
<a href="https://github.com/Reloaded-Project/devops-rust-test-and-coverage" target="_blank">
<img src="assets/reloaded-logo.png" alt="Logo" width="100" height="100">
</a>

<h1 align="center">Reloaded Rust Test and Coverage GitHub Action</h1>

<p align="center">
<a href="https://github.com/Reloaded-Project/devops-rust-test-and-coverage/actions"><img alt="GitHub Actions status" src="https://github.com/Reloaded-Project/devops-rust-test-and-coverage/workflows/main/badge.svg"></a>
<a href="https://codecov.io/gh/Reloaded-Project/devops-rust-test-and-coverage"><img src="https://codecov.io/gh/Reloaded-Project/devops-rust-test-and-coverage/branch/main/graph/badge.svg" alt="Coverage Status"></a>
<a href="https://github.com/Reloaded-Project/devops-rust-test-and-coverage/blob/main/LICENSE"><img src="https://img.shields.io/badge/License-MIT-blue.svg" alt="License"></a>
</p>
</div>

This GitHub Action allows you to easily run tests for your Rust library and upload the coverage results to Codecov. It supports various configurations, including specifying the Rust toolchain, target platform, features, and more.

## Features

- 🦀 Test your Rust library using `cargo` or `cross`
- 📊 Generate coverage reports using Tarpaulin
- 📤 Upload coverage results to Codecov
- 🛠️ Customize Rust toolchain and target platform
- 📦 Enable or disable default features
- 🔧 Specify additional features to test with
- 💾 Optional Rust toolchain caching for faster builds
- 🎛️ Pass additional arguments to the `cargo test` command

## Usage

To use this action in your GitHub workflow, add the following step:

```yaml
- name: Run Tests and Upload Coverage
uses: Reloaded-Project/devops-rust-test-and-coverage@v1
with:
rust-project-path: '.'
rust-toolchain: 'stable'
target: 'x86_64-unknown-linux-gnu'
install-rust-toolchain: true
setup-rust-cache: true
upload-coverage: true
codecov-token: ${{ secrets.CODECOV_TOKEN }}
codecov-flags: 'unittests'
codecov-name: 'codecov-umbrella'
features: 'feature1 feature2'
no-default-features: false
use-cross: false
additional-test-args: '--ignored --test-threads=1'
```
## Inputs
| Input | Description | Required | Default |
| ------------------------ | ---------------------------------------------------------------------- | -------- | -------------------- |
| `rust-project-path` | Path to the Rust project | No | `'.'` |
| `rust-toolchain` | Rust toolchain to use for building and testing (e.g., stable, nightly) | No | `'stable'` |
| `target` | The target platform for the Rust compiler | No | `''` |
| `install-rust-toolchain` | Whether to install the specified Rust toolchain | No | `true` |
| `setup-rust-cache` | Whether to set up Rust caching | No | `true` |
| `upload-coverage` | Whether to upload coverage to Codecov | No | `true` |
| `codecov-token` | Codecov token for uploading coverage | No | N/A |
| `codecov-flags` | Flags to pass to Codecov | No | `'unittests'` |
| `codecov-name` | Custom defined name for the upload | No | `'codecov-umbrella'` |
| `features` | Space-separated list of features to enable during testing | No | `''` |
| `no-default-features` | Disable default features during testing | No | `false` |
| `use-cross` | Use cross-rs for testing. If false, use cargo. | No | `false` |
| `additional-test-args` | Additional arguments to pass to the cargo test command | No | `''` |

## Example Workflow

Here's an example workflow that uses this action with a matrix of configurations:

```yaml
name: Test and Coverage
on: [push]
jobs:
test_and_coverage:
strategy:
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
use-cross: false
- os: ubuntu-latest
target: i686-unknown-linux-gnu
use-cross: false
- os: ubuntu-latest
target: aarch64-unknown-linux-gnu
use-cross: true
- os: ubuntu-latest
target: armv7-unknown-linux-gnueabihf
use-cross: true
- os: windows-latest
target: x86_64-pc-windows-msvc
use-cross: false
- os: windows-latest
target: i686-pc-windows-msvc
use-cross: false
- os: windows-latest
target: aarch64-pc-windows-msvc
use-cross: false
- os: macos-13 # x86
target: x86_64-apple-darwin
use-cross: false
- os: macos-14 # M1
target: aarch64-apple-darwin
use-cross: false
# Wine targets.
- os: ubuntu-latest
target: x86_64-pc-windows-gnu
use-cross: true
- os: ubuntu-latest
target: i686-pc-windows-gnu
use-cross: true
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: Run Tests and Upload Coverage
uses: Reloaded-Project/devops-rust-test-and-coverage@v1
with:
codecov-token: ${{ secrets.CODECOV_TOKEN }}
features: 'feature1 feature2'
no-default-features: true
use-cross: ${{ matrix.use-cross }}
target: ${{ matrix.target }}
```

This workflow runs on every push and performs the following steps:
1. Checks out the repository
2. Runs the tests using `cargo` or `cross` based on the matrix configuration
3. Generates a coverage report using Tarpaulin
4. Uploads the coverage report to Codecov

The matrix includes various target platforms, including Linux, Windows, macOS, and Wine targets
(Windows targets on Linux using `cross`).

## License

This GitHub Action is released under the [MIT License](LICENSE).
1 change: 0 additions & 1 deletion README.md

This file was deleted.

Loading

0 comments on commit fe18f4a

Please sign in to comment.