Skip to content

Commit

Permalink
Initial GitHub Action structure with action for running unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbfm committed Dec 14, 2023
1 parent 2d7a75c commit 7232372
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 0 deletions.
84 changes: 84 additions & 0 deletions .github/actions/rust-setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Rust common setup steps
description: Setup rust with cached dependencies
inputs:
cargo-deny:
description: |
Install cargo-deny. Default is false.
default: false
cargo-sbom:
description: |
Install cargo-sbom. Default is false.
default: false
cargo-tarpaulin:
description: |
Install cargo-tarpaulin. Default is false.
default: false
cargo-cross:
description: |
Install cross. Default is false.
default: false
cargo-trunk:
description: |
Install trunk. Default is false.
default: false

# https://docs.github.com/en/actions/learn-github-actions/expressions#contains
#
runs:
using: "composite"
steps:
- name: Install Rust Toolchain
uses: dtolnay/rust-toolchain@8504a5cb1826786b18ef7a8819e6fddaf9f3eb8d
with:
toolchain: nightly
targets: x86_64-unknown-linux-gnu
- name: Prepare Rust Toolchain Cache
uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84
with:
path: |
~/.rustup/toolchains
~/.rustup/update-hashes
~/.rustup/settings.toml
key: rust-toolchain-${{ github.job }}
- name: Prepare Rust Script Cache
uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84
with:
path: |
~/.cache/rust-script/
key: rust-script-${{ github.job }}
- name: Prepare Rust Dependency Cache
uses: Swatinem/rust-cache@359a70e43a0bb8a13953b04a90f76428b4959bb6
- name: Install Cargo Rust-Script
uses: taiki-e/cache-cargo-install-action@f6e15f71e967ea23e30091f4d38ca6300f5c7760
with:
tool: rust-script

- name: Install cargo-deny
uses: taiki-e/cache-cargo-install-action@f6e15f71e967ea23e30091f4d38ca6300f5c7760
with:
tool: cargo-deny
if: ${{ inputs.cargo-deny == 'true' || inputs.cargo-deny == 'yes' }}

- name: Install cargo-sbom
uses: taiki-e/cache-cargo-install-action@f6e15f71e967ea23e30091f4d38ca6300f5c7760
with:
tool: cargo-sbom
if: ${{ inputs.cargo-sbom == 'true' || inputs.cargo-sbom == 'yes' }}

- name: Install cargo-tarpaulin
uses: taiki-e/cache-cargo-install-action@f6e15f71e967ea23e30091f4d38ca6300f5c7760
with:
tool: cargo-tarpaulin
if: ${{ inputs.cargo-tarpaulin == 'true' || inputs.cargo-tarpaulin == 'yes' }}

- name: Install Cross
uses: taiki-e/cache-cargo-install-action@f6e15f71e967ea23e30091f4d38ca6300f5c7760
with:
tool: cross
if: ${{ inputs.cargo-cross == 'true' || inputs.cargo-cross == 'yes' }}

- name: Install Trunk
uses: taiki-e/cache-cargo-install-action@f6e15f71e967ea23e30091f4d38ca6300f5c7760
with:
tool: trunk
if: ${{ inputs.cargo-trunk == 'true' || inputs.cargo-trunk == 'yes' }}
18 changes: 18 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: build
on:
push:
paths-ignore:
- 'doc/**'
- 'README.md'
- 'LICENSE'

# Required GitHub repository variables:
# https://docs.github.com/en/actions/using-jobs/choosing-the-runner-for-a-job
# OPENDUT_GH_RUNNER_SMALL: runner labels for small jobs
# OPENDUT_GH_RUNNER_LARGE: runner labels for large jobs

jobs:
test:
uses: ./.github/workflows/test.yaml
with:
runs-on: "${{ vars.OPENDUT_GH_RUNNER_LARGE }}"
37 changes: 37 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: test
on:
workflow_call: # allow this workflow to be called from other workflows
inputs:
runs-on:
default: "['ubuntu-latest']"
required: false
type: string

jobs:
test:
name: Test and Verify
runs-on: ${{ fromJson(inputs.runs-on) }}
steps:
- name: Checkout sources
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab
- name: Rust setup
uses: ./.github/actions/rust-setup
with:
cargo-tarpaulin: true

- name: Test with Coverage
run: cargo tarpaulin --verbose --all-features --workspace --timeout 30 --out xml html lcov
- name: Prepare Coverage Reports
run: |
mkdir -p coverage
mv cobertura.xml ./coverage/coverage.cobertura.xml
mv tarpaulin-report.html ./coverage/coverage.tarpaulin.html
mv lcov.info ./coverage/coverage.lcov.info
shell: bash
- name: Upload coverage artifact
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce
with:
name: opendut-coverage
path: ./coverage
if-no-files-found: error
retention-days: 30

0 comments on commit 7232372

Please sign in to comment.