Skip to content

Build & Tests

Build & Tests #724

Workflow file for this run

name: Build & Tests
on:
workflow_dispatch:
schedule:
# Trigger the CI from 7am-7pm EST every 2 hours.
#
# 11:00 UTC = 07:00 EST
# 23:00 UTC = 19:00 EST
#
# The first run of the day is triggered separately because that
# needs to be executed if there is any change in the last 12 hours,
# and not 2 hours.
- cron: '0 11 * * *'
- cron: '0 13,15,17,19,21,23 * * *'
env:
CARGO_TERM_COLOR: always
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
jobs:
count_commits:
name: Count Commits
runs-on: ubuntu-latest
outputs:
count: ${{ env.COMMIT_COUNT }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
# Required to count the commits
fetch-depth: 0
- name: Get new commits (2h)
if: github.event.schedule != '0 11 * * *'
run: echo "COMMIT_COUNT=$(git log --oneline --since '2 hours ago' | wc -l)" >> $GITHUB_ENV
- name: Get new commits (12h)
if: github.event.schedule == '0 11 * * *'
run: echo "COMMIT_COUNT=$(git log --oneline --since '12 hours ago' | wc -l)" >> $GITHUB_ENV
build:
name: Cargo Build
runs-on: ubuntu-latest
needs: count_commits
if: ${{ needs.count_commits.outputs.count != '0' }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Rust Toolchain
run: |
rm rust-toolchain
rustup toolchain install stable --profile minimal
- name: Rust Cache
uses: Swatinem/rust-cache@v2
with:
cache-directories: ~/.cargo/registry/src/**/librocksdb-sys-*
cache-all-crates: "true"
- name: Build Release
run: cargo build --all --release
test:
name: Cargo Test
runs-on: ubuntu-latest
needs: count_commits
if: ${{ needs.count_commits.outputs.count != '0' }}
timeout-minutes: 30
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Rust Toolchain
run: |
rm rust-toolchain
rustup toolchain install stable --profile minimal
- name: Rust Cache
uses: Swatinem/rust-cache@v2
with:
cache-directories: ~/.cargo/registry/src/**/librocksdb-sys-*
cache-all-crates: "true"
- name: Setup junitify
run: cargo install junitify
- name: Cargo Test
# RUSTC_BOOTSTRAP=1 is used to ensure unstable features are allowed in order to use unstable
# json output and report times in tests. This is in preparation for rust 1.70 which will not
# allow this anymore:
# - https://github.com/rust-lang/rust/issues/75526
# - https://github.com/johnterickson/cargo2junit/issues/79
run: |
RUSTC_BOOTSTRAP=1 \
cargo test --all -- \
--format=json -Z unstable-options --report-time \
> tests.out
- name: Parse Test Output
if: always()
run: cat tests.out | junitify -i --out test_results/
- name: Publish Test Summary
uses: test-summary/action@v2
if: always()
with:
paths: 'test_results/*.xml'
coverage:
name: Code Coverage
runs-on: ubuntu-latest
needs: count_commits
if: ${{ needs.count_commits.outputs.count != '0' }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Rust Toolchain
run: |
rm rust-toolchain
rustup toolchain install stable --profile minimal --component llvm-tools-preview
- name: Rust Cache
uses: Swatinem/rust-cache@v2
with:
cache-directories: ~/.cargo/registry/src/**/librocksdb-sys-*
cache-all-crates: "true"
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov
- name: Generate Code Coverage
run: cargo llvm-cov --all-features --workspace --lcov --output-path lcov.info
- name: Upload to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: lcov.info
fail_ci_if_error: false