paper-age 1.0.0

Easy and secure paper backups of secrets
name: Rust

on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

permissions:
  checks: write
  contents: read
  pull-requests: write

env:
  CARGO_TERM_COLOR: always

jobs:
  test:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v3
    - name: Install markdown-test-report
      run: |
        mkdir -p "${HOME}/.local/bin"
        echo "${HOME}/.local/bin" >> $GITHUB_PATH
        wget --quiet -O "${HOME}/.local/bin/markdown-test-report" https://github.com/ctron/markdown-test-report/releases/download/v0.3.6/markdown-test-report-linux-amd64
        chmod +x "${HOME}/.local/bin/markdown-test-report"
    - name: Install grcov
      run: |
        mkdir -p /tmp/grcov
        wget --quiet -O /tmp/grcov/grcov-x86_64-unknown-linux-gnu.tar.bz2 https://github.com/mozilla/grcov/releases/download/v0.8.13/grcov-x86_64-unknown-linux-gnu.tar.bz2
        tar -xvf /tmp/grcov/grcov-x86_64-unknown-linux-gnu.tar.bz2
        mv grcov "${HOME}/.local/bin"
        chmod +x "${HOME}/.local/bin/grcov"
    - name: Add llvm-tools
      run: rustup component add llvm-tools
    - name: Configure cache
      uses: actions/cache@v3
      with:
        path: |
          ~/.cargo/bin/
          ~/.cargo/registry/index/
          ~/.cargo/registry/cache/
          ~/.cargo/git/db/
          target/
        key: test-${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
    - name: Run tests
      run: cargo test --verbose -- -Z unstable-options --report-time --format json | tee test-output.json
      env:
        CARGO_INCREMENTAL: 0
        RUSTFLAGS: -Cinstrument-coverage
        LLVM_PROFILE_FILE: cargo-test-%p-%m.profraw
    - name: Process code coverage with grcov
      run: grcov . --binary-path ./target/debug/deps/ -s . -t cobertura --branch --ignore-not-existing --ignore '../*' --ignore "/*" -o target/cobertura.xml
    - name: Code Coverage Report
      uses: irongut/CodeCoverageSummary@v1.3.0
      with:
        filename: target/cobertura.xml
        badge: true
        fail_below_min: false
        format: markdown
        hide_branch_rate: false
        hide_complexity: true
        indicators: true
        output: both
        thresholds: "50 75"
    - name: Add Coverage PR Comment
      uses: marocchino/sticky-pull-request-comment@v2
      if: github.event_name == 'pull_request'
      with:
        recreate: true
        path: code-coverage-results.md
    - name: Job Summary (coverage)
      if: ${{ always() }}
      run: |
        echo "# Coverage report " >> $GITHUB_STEP_SUMMARY
        [ -f code-coverage-results.md ] && cat code-coverage-results.md >> $GITHUB_STEP_SUMMARY
        echo "---" >> $GITHUB_STEP_SUMMARY
      continue-on-error: true
    - name: Job Summary (tests)
      if: ${{ always() }}
      run: "[ -f test-output.json ] && markdown-test-report --no-front-matter --output - >> $GITHUB_STEP_SUMMARY"
      continue-on-error: true