From 17d973720a8771ce5478cc476260c0223aa69056 Mon Sep 17 00:00:00 2001 From: Anish Date: Fri, 8 Sep 2023 14:38:59 -0400 Subject: [PATCH] Add coverage comment workflow action --- .coveragerc | 1 + .github/workflows/coverage.yml | 31 +++++++++++++++++++++ .github/workflows/main.yml | 49 ++++++++++++++++++---------------- pytest.ini | 6 ++++- 4 files changed, 63 insertions(+), 24 deletions(-) create mode 100644 .github/workflows/coverage.yml diff --git a/.coveragerc b/.coveragerc index 3c69f131..2222ec9e 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,5 +1,6 @@ [run] source = em_workflows +relative_files = true omit = # Omit test code test/*, diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml new file mode 100644 index 00000000..d109b896 --- /dev/null +++ b/.github/workflows/coverage.yml @@ -0,0 +1,31 @@ +name: Post coverage comment + +on: + workflow_run: + workflows: ["main"] + types: + - completed + +jobs: + comment: + name: Run tests & display coverage + runs-on: ubuntu-latest + if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' + permissions: + # Gives the action the necessary permissions for publishing new + # comments in pull requests. + pull-requests: write + # Gives the action the necessary permissions for editing existing + # comments (to avoid publishing multiple comments in the same PR) + contents: write + # Gives the action the necessary permissions for looking up the + # workflow that launched this workflow, and download the related + # artifact that contains the comment to be published + actions: read + steps: + + - name: Post comment + uses: py-cov-action/python-coverage-comment-action@v3 + with: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_PR_RUN_ID: ${{ github.event.workflow_run.id }} diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 23eb8a2e..867ff6da 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,6 +16,7 @@ env: jobs: docs: runs-on: ubuntu-latest + name: Docs needs: test steps: - uses: actions/checkout@v2 @@ -52,6 +53,15 @@ jobs: test: runs-on: ubuntu-latest + name: Check coverage + permissions: + # Gives the action the necessary permissions for publishing new + # comments in pull requests. + pull-requests: write + # Gives the action the necessary permissions for pushing data to the + # python-coverage-comment-action branch, and for editing existing + # comments (to avoid publishing multiple comments in the same PR) + contents: write strategy: matrix: python-version: ["3.8"] @@ -79,30 +89,9 @@ jobs: - name: Git LFS Pull run: | git lfs pull -# - name: IMOD Container Build -# id: docker-build-imod -# env: -# DOCKERFILE_PATH: utils/imod/ -# run: | -# docker build -t imod $DOCKERFILE_PATH -# - name: IMOD Container Test -# run: | -# docker run imod dm2mrc -h -# - name: Graphicsmagick Container Build -# id: docker-build-graphicsmagick -# env: -# DOCKERFILE_PATH: utils/graphicsmagick/ -# run: | -# docker build -t graphicsmagick $DOCKERFILE_PATH -# - name: Graphicsmagick Container Test -# run: | -# docker run graphicsmagick gm -version -# - name: Set up Python ${{ matrix.python-version }} -# uses: actions/setup-python@v2 -# with: -# python-version: ${{ matrix.python-version }} - name: Install dependencies run: | + sudo apt -y update && sudo apt -y install libgl-dev graphicsmagick libblosc1 IMOD=imod_4.11.24_RHEL7-64_CUDA10.1.sh export IMOD_DIR=/usr/local/IMOD export PATH=$IMOD_DIR/bin:$PATH @@ -114,7 +103,6 @@ jobs: wget https://github.com/glencoesoftware/bioformats2raw/releases/download/v${BIO2R_V}/${BIO2R_Z} && sudo unzip ${BIO2R_Z} -d ${BIO2R_DIR} && rm -f ${BIO2R_Z} python -m pip install --upgrade pip pip install -e . -r requirements.txt - sudo apt -y update && sudo apt -y install libgl-dev graphicsmagick libblosc1 - name: Test Coverage continue-on-error: true @@ -127,3 +115,18 @@ jobs: - name: Coverage Badge uses: tj-actions/coverage-badge-py@v2 + + - name: Coverage comment + id: coverage_comment + uses: py-cov-action/python-coverage-comment-action@v3 + with: + GITHUB_TOKEN: ${{ github.token }} + + - name: Store Pull Request comment to be posted + uses: actions/upload-artifact@v3 + if: steps.coverage_comment.outputs.COMMENT_FILE_WRITTEN == 'true' + with: + # If you use a different name, update COMMENT_ARTIFACT_NAME accordingly + name: python-coverage-comment-action + # If you use a different name, update COMMENT_FILENAME accordingly + path: python-coverage-comment-action.txt diff --git a/pytest.ini b/pytest.ini index ddab6ce6..9f24e99e 100644 --- a/pytest.ini +++ b/pytest.ini @@ -3,7 +3,11 @@ env = HEDWIG_ENV=dev USER=test -addopts = --strict-markers +addopts = + --cov-report term-missing --cov-branch --cov-report xml --cov-report term + --cov=em_workflows -vv + --strict-markers -rfE + markers = slow: mark test as long-running localdata: test data not always available