name: Rust
on:
push:
branches: [ "main", "next" ]
pull_request:
branches: [ "main", "next" ]
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: Compile binary
run: cargo build --release
- name: Store binary artifact
uses: actions/upload-artifact@v3
with:
name: paper-age-binary
path: target/release/paper-age
- 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
visual-snapshots:
runs-on: ubuntu-latest
needs: [test]
steps:
- name: Install GhostScript
run: |
sudo apt-get update
sudo apt-get install ghostscript
- name: Change ImageMagick policy to allow PDF→PNG conversion
run: |
sudo sed -i_bak \
's/rights="none" pattern="PDF"/rights="read | write" pattern="PDF"/' \
/etc/ImageMagick-6/policy.xml
- name: Download paper-age binary
uses: actions/download-artifact@v3
with:
name: paper-age-binary
- name: Make the bianry executable
run: chmod u+x paper-age
- name: Generate PDFs
run: |
mkdir -p visual-snapshots
echo "Hello World" | ./paper-age --title="A4 secret" --page-size=a4 --output=visual-snapshots/a4.pdf
echo "Hello World" | ./paper-age --title="Letter secret" --page-size=letter --output=visual-snapshots/letter.pdf
env:
PAPERAGE_PASSPHRASE: supersecret
- name: Convert the PDFs to PNGs
run: |
convert -density 300 -alpha remove visual-snapshots/a4.pdf PNG32:visual-snapshots/a4.png
convert -density 300 -alpha remove visual-snapshots/letter.pdf PNG32:visual-snapshots/letter.png
- name: Save snapshots
uses: actions/upload-artifact@v3
with:
name: visual-snapshots
path: visual-snapshots