Skip to content

Update coverage report deployment in PR #308

Update coverage report deployment in PR

Update coverage report deployment in PR #308

name: weighted-code-coverage
on:
push:
branches:
- master
paths:
- "src/**"
- "tests/**"
- "crates/**"
- ".github/**"
- "Cargo.toml"
- "Cargo.lock"
pull_request:
branches:
- master
paths:
- "src/**"
- "tests/**"
- "crates/**"
- ".github/**"
- "Cargo.toml"
- "Cargo.lock"
env:
#
# Dependency versioning
#
GRCOV_VERSION: "0.8.13"
WCC_VERSION: "0.2.0"
UDEPS_VERSION: "0.1.35"
CAREFUL_VERSION: "0.3.4"
jobs:
################################## LEGAL AND FORMAT LAYER ######################
# clippy-rustfmt:
#
# runs-on: ubuntu-latest
#
# steps:
# - uses: actions/checkout@v4
#
# - name: Install Rust stable
# uses: dtolnay/rust-toolchain@stable
# with:
# components: clippy, rustfmt
#
# - name: Run rustfmt
# run:
# cargo fmt --all -- --check --verbose
#
# - name: Run cargo clippy
# uses: giraffate/clippy-action@v1
# with:
# github_token: ${{ secrets.GITHUB_TOKEN }}
# clippy_flags: --all-targets -- -D warnings
# reporter: github-pr-check
################################## BUILD AND DOCS LAYER ########################
# build:
#
# needs: clippy-rustfmt
#
# strategy:
# matrix:
# platform: [ubuntu-latest, macos-latest, windows-latest]
#
# runs-on: ${{ matrix.platform }}
#
# steps:
# - uses: actions/checkout@v4
#
# - name: Install Rust stable
# uses: dtolnay/rust-toolchain@stable
#
# - name: Build
# run: cargo build --verbose
#
# docs:
#
# needs: clippy-rustfmt
#
# strategy:
# matrix:
# platform: [ubuntu-latest, macos-latest, windows-latest]
#
# runs-on: ${{ matrix.platform }}
#
# steps:
# - uses: actions/checkout@v4
#
# - name: Install Rust stable
# uses: dtolnay/rust-toolchain@stable
#
# - name: Generate docs
# run: cargo doc --verbose --no-deps
################################## CODE COVERAGE LAYER ##################################
# code-coverage:
#
# needs: [build, docs]
#
# runs-on: ubuntu-latest
#
# steps:
# - uses: actions/checkout@v4
#
# - name: Install Rust stable
# uses: dtolnay/rust-toolchain@stable
# with:
# components: llvm-tools-preview
#
# - name: Install grcov
# env:
# GRCOV_LINK: https://github.com/mozilla/grcov/releases/download
# GRCOV_VERSION: v0.8.13
# run: |
# curl -L "$GRCOV_LINK/$GRCOV_VERSION/grcov-x86_64-unknown-linux-musl.tar.bz2" |
# tar xj -C $HOME/.cargo/bin
#
# - name: Run tests
# env:
# RUSTFLAGS: "-Cinstrument-coverage"
# LLVM_PROFILE_FILE: "weighted-code-coverage-%p-%m.profraw"
# run: |
# cargo test --verbose
#
# - name: Get coverage data for codecov
# run: |
# grcov . --binary-path ./target/debug/ -s . -t lcov --branch \
# --ignore-not-existing --ignore "/*" --ignore "../*" \
# --ignore "templates/*" -o lcov.info
#
# - name: Codecov upload
# uses: codecov/codecov-action@v4
# with:
# files: lcov.info
# token: ${{ secrets.CODECOV_TOKEN }}
weighted-code-coverage:
# needs: [build, docs]
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
# and pull-requests write pemission for the pull request comment.
permissions:
contents: write
pages: write
id-token: write
pull-requests: write
environment:
name: wcc
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust stable
uses: dtolnay/rust-toolchain@stable
with:
components: llvm-tools-preview
- name: Set up Python
if: github.event_name == 'pull_request'
uses: actions/setup-python@v5
with:
python-version: '>=3.7'
- name: Install smokeshow
if: github.event_name == 'pull_request'
run: pip install smokeshow
- name: Install grcov
env:
GRCOV_LINK: https://github.com/mozilla/grcov/releases/download
GRCOV_BINARY: grcov-x86_64-unknown-linux-musl.tar.bz2
run: |
curl -L "$GRCOV_LINK/v$GRCOV_VERSION/$GRCOV_BINARY" |
tar xj -C $HOME/.cargo/bin
- name: Install weighted-code-coverage
run: |
cargo install --path .
- name: Run tests
env:
RUSTFLAGS: "-Cinstrument-coverage"
LLVM_PROFILE_FILE: "weighted-code-coverage-%p-%m.profraw"
run: |
cargo test --verbose
- name: Run grcov
run: |
grcov . --binary-path ./target/debug/ --ignore "**/.cargo/**" --ignore "**/rustc/**" --ignore "./target/**" -t coveralls -s . --token YOUR_COVERALLS_TOKEN > coveralls.json
- name: Run weighted-code-coverage
id: wcc-run
run: |
mkdir $HOME/wcc-output
echo "html=$HOME/wcc-output" >> $GITHUB_OUTPUT
echo "json=$HOME/wcc-output/wcc.json" >> $GITHUB_OUTPUT
weighted-code-coverage --project-path ./ --grcov-format coveralls --grcov-path ./coveralls.json -m functions --json $HOME/wcc-output/wcc.json --html $HOME/wcc-output/
- name: Setup GitHub Pages
if: github.event_name != 'pull_request'
uses: actions/[email protected]
with:
enablement: true
- name: Upload Wcc html output
if: github.event_name != 'pull_request'
uses: actions/[email protected]
with:
path: ${{ steps.wcc-run.outputs.html }}
- name: Deploy to GitHub Pages
if: github.event_name != 'pull_request'
id: deployment
uses: actions/[email protected]
- name: Generate upload key for smokeshow
if: github.event_name == 'pull_request'
id: generate_key
run: |
SMOKESHOW_AUTH_KEY=$(smokeshow generate-key | grep -o "SMOKESHOW_AUTH_KEY='[^']*'" | sed "s/^SMOKESHOW_AUTH_KEY='\([^']*\)'$/\1/")
echo "SMOKESHOW_AUTH_KEY=$SMOKESHOW_AUTH_KEY" >> $GITHUB_ENV
shell: bash
- name: Set smokeshow key as env variable
if: github.event_name == 'pull_request'
run: echo "SMOKESHOW_AUTH_KEY=$(cat upload_key.txt)" >> $GITHUB_ENV
- name: Deploy to smokeshow
id: upload_site
if: github.event_name == 'pull_request'
env:
SMOKESHOW_AUTH_KEY: ${{ env.SMOKESHOW_AUTH_KEY }}
run: |
url=$(smokeshow upload $HOME/wcc-output | grep -o 'https://smokeshow.helpmanual.io/[^"]*')
echo "site_url=$url" >> $GITHUB_OUTPUT
shell: bash
- name: Extract metric values
if: github.event_name == 'pull_request'
id: metrics
env:
JSON: ${{ steps.wcc-run.outputs.json }}
run: |
content=`cat ${JSON}`
echo "json=$content" >> $GITHUB_OUTPUT
- name: Extract branch name
id: extract-branch
if: github.event_name != 'pull_request'
run: echo "branch=${GITHUB_REF#refs/heads/}" >> "${GITHUB_OUTPUT}"
- name: Define badge path
id: badge-path
if: github.event_name != 'pull_request'
env:
BADGE_PATH: .github/badges/wcc.svg
run: echo "path=${BADGE_PATH}" >> "${GITHUB_OUTPUT}"
- name: Create badge directory
if: github.event_name != 'pull_request'
env:
BADGE_PATH: ${{ steps.badge-path.outputs.path }}
run: mkdir -p "${BADGE_PATH%/*}"
- name: Determine badge color
if: github.event_name != 'pull_request'
id: badge-color
env:
WCC: ${{ fromJson(steps.metrics.outputs.json).projectMetrics.total.cyclomatic.wcc }}
run: |
if [ $(echo "${WCC} < 60.0" | bc) -eq 1 ]; then
echo "color=red" >> "${GITHUB_OUTPUT}"
else
echo "color=green" >> "${GITHUB_OUTPUT}"
fi
- name: Create badge
if: github.event_name != 'pull_request'
uses: emibcn/[email protected]
id: badge
with:
label: wcc
status: ${{ fromJson(steps.metrics.outputs.json).projectMetrics.total.cyclomatic.wcc }}%
color: ${{ steps.badge-color.outputs.color }}
path: ${{ steps.badge-path.outputs.path }}
- name: Verify if badge changed
if: github.event_name != 'pull_request'
uses: tj-actions/verify-changed-files@v20
id: badge-changed
with:
files: ${{ steps.badge-path.outputs.path }}
- name: Commit badge
if: ${{ github.event_name != 'pull_request' && steps.badge-changed.outputs.files_changed == 'true' }}
env:
BADGE: ${{ steps.badge-path.outputs.path }}
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add "${BADGE}"
git commit -m "Add/Update wcc badge"
- name: Push badge
uses: ad-m/github-push-action@master
if: ${{ github.event_name != 'pull_request' && success() }}
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ steps.extract-branch.outputs.branch }}
- name: Find comment
if: github.event_name == 'pull_request'
uses: peter-evans/find-comment@v3
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: Weighted Code Coverage
- name: Create or update comment
if: github.event_name == 'pull_request'
uses: peter-evans/create-or-update-comment@v4
env:
COVERAGE: ${{ fromJson(steps.metrics.outputs.json).projectMetrics.total.coverage }}
WCC_CYC: ${{ fromJson(steps.metrics.outputs.json).projectMetrics.total.cyclomatic.wcc }}
WCC_COG: ${{ fromJson(steps.metrics.outputs.json).projectMetrics.total.cognitive.wcc }}
CRAP_CYC: ${{ fromJson(steps.metrics.outputs.json).projectMetrics.total.cyclomatic.crap }}
CRAP_COG: ${{ fromJson(steps.metrics.outputs.json).projectMetrics.total.cognitive.crap }}
SKUNK_CYC: ${{ fromJson(steps.metrics.outputs.json).projectMetrics.total.cyclomatic.skunk }}
SKUNK_COG: ${{ fromJson(steps.metrics.outputs.json).projectMetrics.total.cognitive.skunk }}
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
## [Weighted Code Coverage](${{ steps.upload_site.outputs.site_url }})
Project metrics:
- **Coverage**: ${{ env.COVERAGE }}%
| | Wcc | CRAP | Skunk |
|-------------|----------------------|---------------------|----------------------|
| Cyclomatic | ${{ env.WCC_CYC }}% | ${{ env.CRAP_CYC }} | ${{ env.SKUNK_CYC }} |
| Cognitive | ${{ env.WCC_COG }}% | ${{ env.CRAP_COG }} | ${{ env.SKUNK_COG }} |
edit-mode: replace
################################## DEPENDENCY LAYER ###########################
# audit:
#
# needs: [code-coverage, weighted-code-coverage]
#
# runs-on: ubuntu-latest
#
# steps:
# - uses: actions/checkout@v4
#
# - name: Check dependencies changes
# uses: dorny/paths-filter@v3
# id: changes
# with:
# filters: |
# cargo:
# - 'Cargo.toml'
# - 'Cargo.lock'
#
# - name: Run cargo-audit
# if: steps.changes.outputs.cargo == 'true'
# uses: actions-rs/audit-check@v1
# with:
# token: ${{ secrets.GITHUB_TOKEN }}
#
# deny:
#
# needs: [code-coverage, weighted-code-coverage]
#
# runs-on: ubuntu-latest
#
# steps:
# - uses: actions/checkout@v4
#
# - name: Check dependencies changes
# uses: dorny/paths-filter@v3
# id: changes
# with:
# filters: |
# cargo:
# - 'Cargo.toml'
# - 'Cargo.lock'
#
# - name: Detect multiple versions of the same crate
# if: steps.changes.outputs.cargo == 'true'
# uses: EmbarkStudios/cargo-deny-action@v2
# with:
# command: check bans
#
# udeps:
#
# needs: [code-coverage, weighted-code-coverage]
#
# runs-on: ubuntu-latest
#
# steps:
# - uses: actions/checkout@v4
#
# - name: Check dependencies changes
# uses: dorny/paths-filter@v3
# id: changes
# with:
# filters: |
# cargo:
# - 'Cargo.toml'
# - 'Cargo.lock'
#
# - name: Install Rust nightly
# if: steps.changes.outputs.cargo == 'true'
# uses: dtolnay/rust-toolchain@nightly
#
# - name: Install cargo-udeps
# if: steps.changes.outputs.cargo == 'true'
# env:
# UDEPS_LINK: https://github.com/est31/cargo-udeps/releases/download
# run: |
# curl -L "$UDEPS_LINK/v$UDEPS_VERSION/cargo-udeps-v$UDEPS_VERSION-x86_64-unknown-linux-gnu.tar.gz" |
# tar xz -C $HOME/.cargo/bin --strip-components 2
#
# - name: Run cargo-udeps
# if: steps.changes.outputs.cargo == 'true'
# run: |
# cargo +nightly udeps --all-targets
################################## UNSAFE CHECKS LEVEL #########################
# careful:
#
# needs: [audit, deny, udeps]
#
# runs-on: ubuntu-latest
#
# steps:
# - uses: actions/checkout@v4
#
# - name: Install Rust nightly
# uses: dtolnay/rust-toolchain@nightly
# with:
# components: rust-src
#
# - name: Install cargo-careful
# env:
# CAREFUL_LINK: https://github.com/RalfJung/cargo-careful/releases/download
# run: |
# curl -L "$CAREFUL_LINK/v$CAREFUL_VERSION/cargo-careful.x86_64-unknown-linux-musl" \
# --output $HOME/.cargo/bin/cargo-careful
# chmod +x $HOME/.cargo/bin/cargo-careful
#
# - name: Run cargo-careful
# run: |
# cargo +nightly careful test
#
# address-sanitizer:
#
# needs: [audit, deny, udeps]
#
# runs-on: ubuntu-latest
#
# steps:
# - uses: actions/checkout@v4
#
# - name: Install Rust nightly
# uses: dtolnay/rust-toolchain@nightly
# with:
# components: rust-src
#
# - name: Run AddressSanitizer
# env:
# RUSTFLAGS: -Zsanitizer=address -Copt-level=3
# RUSTDOCFLAGS: -Zsanitizer=address
# run: cargo test -Zbuild-std --target x86_64-unknown-linux-gnu