Create scorecard.yml #90
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI | |
on: | |
push: | |
branches: [main] | |
pull_request: | |
branches: [main] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Install latest stable | |
uses: actions-rs/toolchain@v1 | |
with: | |
toolchain: stable | |
components: rustfmt, clippy | |
- uses: cachix/install-nix-action@v20 | |
with: | |
nix_path: nixpkgs=channel:nixos-unstable | |
- name: Install just | |
run: | | |
# Update nix | |
nix-channel --add https://nixos.org/channels/nixpkgs-unstable | |
nix-channel --update | |
nix-env -iA nixpkgs.just | |
nix-env -iA nixpkgs.xmlstarlet | |
nix-env -iA nixpkgs.cargo-tarpaulin | |
- name: Lint code | |
run: just lint | |
env: | |
CARGO_TERM_COLOR: always | |
- name: Build and run tests | |
run: | | |
just test | |
- name: Calculate test coverage | |
run: | | |
cargo install cargo-tarpaulin | |
cargo tarpaulin --out Xml | |
COVERAGE=$(cat cobertura.xml | xmlstarlet sel -t -v "/coverage/@line-rate" | awk '{printf "%.2f", $1 * 100}')% | |
echo "COVERAGE=$COVERAGE" >> $GITHUB_ENV | |
env: | |
CARGO_TERM_COLOR: always | |
- name: Upload file | |
uses: actions/upload-artifact@v2 | |
with: | |
name: coverage-file | |
path: cobertura.xml | |
- name: Create the Badge | |
if: github.ref == 'refs/heads/main' | |
uses: schneegans/dynamic-badges-action@v1.7.0 | |
with: | |
auth: ${{ secrets.CODE_COVERAGE_BADGE }} | |
gistID: 2b7862c80c14d562c8659e1283543190 | |
filename: coverage-scope.json | |
label: Test Coverage | |
message: ${{ env.COVERAGE }} | |
color: green | |
run-action: | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Install latest stable | |
uses: actions-rs/toolchain@v1 | |
with: | |
toolchain: stable | |
components: rustfmt, clippy | |
- name: Download coverage | |
uses: actions/download-artifact@v2 | |
with: | |
name: coverage-file | |
- name: Coverage scope action main | |
uses: ./ # Uses an action in the root directory | |
id: coverage | |
with: | |
coverage-filepath: cobertura.xml | |
branch: main | |
threshold-total: 80 | |
threshold-change: 90 | |
fetch-action: | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Download coverage | |
uses: actions/download-artifact@v2 | |
with: | |
name: coverage-file | |
- uses: dennisjensen95/coverage-scope@v0.5.0 | |
with: | |
coverage-filepath: cobertura.xml | |
branch: main | |
threshold-total: 80 | |
threshold-change: 90 |