diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml new file mode 100644 index 00000000..8007b5cd --- /dev/null +++ b/.github/workflows/coverage.yml @@ -0,0 +1,87 @@ +name: Coverage + +on: + pull_request: + push: + branches: + - main + +jobs: + coverage: + runs-on: ubuntu-latest + services: + postgres: + image: postgres:12 + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: password + POSTGRES_DB: postgres + ports: + - 5432:5432 + env: + SQLX_VERSION: 0.6.2 + SQLX_FEATURES: postgres,rustls + CARGO_TERM_COLOR: always + + steps: + - name: Checkout repository, + uses: actions/checkout@v3 + + - name: Cache dependencies + id: cache-dependencies + uses: actions/cache@v2 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + target + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + + - name: Install Rust + run: rustup update nightly + + - name: Massage sqlx features env variable... + run: | + TMP=${{ env.SQLX_FEATURES }} + SQLX_FEATURES_CACHE="${TMP//,/_}" + echo "SQLX_FEATURES_CACHE=${SQLX_FEATURES_CACHE}" >> $GITHUB_ENV + + - name: Cache sqlx-cli + uses: actions/cache@v2 + id: cache-sqlx + with: + path: | + ~/.cargo/bin/sqlx + ~/.cargo/bin/cargo-sqlx + key: ${{ runner.os }}-sqlx-${{ env.SQLX_VERSION }}-${{ env.SQLX_FEATURES_CACHE }} + + - name: Install sqlx-cli + uses: actions-rs/cargo@v1 + if: steps.cache-sqlx.outputs.cache-hit == false + with: + command: install + args: > + sqlx-cli + --force + --version=${{ env.SQLX_VERSION }} + --features=${{ env.SQLX_FEATURES }} + --no-default-features + --locked + + - name: Migrate database + run: | + sudo apt-get install libpq-dev -y + SKIP_DOCKER=true ./scripts/init_db.sh + + - name: Install cargo-llvm-cov + uses: taiki-e/install-action@cargo-llvm-cov + + - name: Generate code coverage + run: cargo +nightly llvm-cov --doctests --all-features --workspace --lcov --output-path lcov.info + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v3 + with: + #token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos + files: lcov.info + fail_ci_if_error: true \ No newline at end of file