From e06a77af28d760f9d5aa7a889b3ad014e90fd8e8 Mon Sep 17 00:00:00 2001 From: Wyatt Verchere Date: Fri, 17 Nov 2023 17:58:15 -0800 Subject: [PATCH] Adds code coverage (#757) * coverage initial push * compiles on PR * adds db env variable * fixed env variables being on the wrong action * added more tests yml code * refresh * tried copying over tests.yml * removed accidental tests * shotgun attempts * generated yml * more tries * shotgun again * small mistakes * repush * repush * Adds env variables to tarp * removes unused actions and tests cfg attribute on main.rs * only will work on push to master * changed to 60% --------- Co-authored-by: Geometrically <18202329+Geometrically@users.noreply.github.com> --- .codecov.yml | 13 ++++++++++ .github/workflows/coverage.yml | 44 ++++++++++++++++++++++++++++++++++ .gitignore | 2 ++ src/main.rs | 1 + 4 files changed, 60 insertions(+) create mode 100644 .codecov.yml create mode 100644 .github/workflows/coverage.yml diff --git a/.codecov.yml b/.codecov.yml new file mode 100644 index 000000000..3b187dd0d --- /dev/null +++ b/.codecov.yml @@ -0,0 +1,13 @@ +comment: false + +coverage: + status: + project: + default: + threshold: 60% # make CI green + patch: + default: + threshold: 60% # make CI green + +ignore: # ignore code coverage on following paths + - "**/tests" \ No newline at end of file diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml new file mode 100644 index 000000000..6e67a3aca --- /dev/null +++ b/.github/workflows/coverage.yml @@ -0,0 +1,44 @@ +name: Coverage-Tarpaulin + +env: + CARGO_TERM_COLOR: always + SQLX_OFFLINE: true + +on: + push: + branches: [ master ] + # Uncomment to allow PRs to trigger the workflow + # pull_request: + # branches: [ master ] +jobs: + citarp: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + # Start Docker Compose + - name: Start Docker Compose + run: docker-compose up -d + + - name: Install cargo tarpaulin + uses: taiki-e/install-action@cargo-tarpaulin + - name: Generate code coverage + run: | + cargo tarpaulin --verbose --all-features --timeout 120 --out xml + env: + BACKBLAZE_BUCKET_ID: ${{ secrets.BACKBLAZE_BUCKET_ID }} + BACKBLAZE_KEY: ${{ secrets.BACKBLAZE_KEY }} + BACKBLAZE_KEY_ID: ${{ secrets.BACKBLAZE_KEY_ID }} + S3_ACCESS_TOKEN: ${{ secrets.S3_ACCESS_TOKEN }} + S3_SECRET: ${{ secrets.S3_SECRET }} + S3_URL: ${{ secrets.S3_URL }} + S3_REGION: ${{ secrets.S3_REGION }} + S3_BUCKET_NAME: ${{ secrets.S3_BUCKET_NAME }} + SQLX_OFFLINE: true + DATABASE_URL: postgresql://labrinth:labrinth@localhost/postgres + + - name: Upload to codecov.io + uses: codecov/codecov-action@v2 + with: + # token: ${{secrets.CODECOV_TOKEN}} # not required for public repos + fail_ci_if_error: true diff --git a/.gitignore b/.gitignore index 0fcb7d0a0..516893c62 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +codecov.json + # Created by https://www.gitignore.io/api/rust,clion # Edit at https://www.gitignore.io/?templates=rust,clion diff --git a/src/main.rs b/src/main.rs index 4b25580ea..7aff4d601 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,6 +17,7 @@ pub struct Pepper { pub pepper: String, } +#[cfg(not(tarpaulin_include))] #[actix_rt::main] async fn main() -> std::io::Result<()> { dotenvy::dotenv().ok();