From f904fd28bd365457d948acf054aaa93df160f02d Mon Sep 17 00:00:00 2001 From: JS Ng Date: Sat, 20 Sep 2025 13:03:42 +0000 Subject: [PATCH] fix: separate CI and test report workflows for automated testing and coverage reporting This resolves a bug that causes CI unit tests to fail when run from forked repositories without write permission. --- .github/workflows/{build_test.yml => ci.yml} | 22 ++++------ .github/workflows/test-report.yml | 44 ++++++++++++++++++++ 2 files changed, 52 insertions(+), 14 deletions(-) rename .github/workflows/{build_test.yml => ci.yml} (61%) create mode 100644 .github/workflows/test-report.yml diff --git a/.github/workflows/build_test.yml b/.github/workflows/ci.yml similarity index 61% rename from .github/workflows/build_test.yml rename to .github/workflows/ci.yml index 0b549ca..44213c1 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/ci.yml @@ -1,7 +1,7 @@ # This workflow will install opendis dependencies, and then run tests and lint with a variety of Python versions # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python -name: Build and Test OpenDis +name: CI on: push: @@ -9,7 +9,7 @@ on: pull_request: jobs: - build: + build-test: runs-on: ubuntu-latest strategy: fail-fast: false @@ -28,16 +28,10 @@ jobs: poetry install --with dev - name: Test with pytest run: | - poetry run pytest --junitxml=./test_results/test_results.xml --cov=opendis --cov-report term --cov-report=xml:./test_results/coverage.xml - - name: Upload Test Results - uses: dorny/test-reporter@v1 - if: always() + poetry run pytest --junitxml=./test_results/test_results_${{ matrix.python-version }}.xml --cov=opendis --cov-report term --cov-report=xml:./test_results/coverage_${{ matrix.python-version }}.xml + - name: Upload test results + uses: actions/upload-artifact@v4 + if: ${{ !cancelled() }} with: - name: JUnit Tests - path: test_results/test_results.xml - reporter: java-junit - - name: Pytest coverage comment - uses: MishaKav/pytest-coverage-comment@main - with: - pytest-xml-coverage-path: ./test_results/coverage.xml - junitxml-path: ./test_results/test_results.xml \ No newline at end of file + name: test-results-${{ matrix.python-version }} + path: test_results/ \ No newline at end of file diff --git a/.github/workflows/test-report.yml b/.github/workflows/test-report.yml new file mode 100644 index 0000000..20d1d04 --- /dev/null +++ b/.github/workflows/test-report.yml @@ -0,0 +1,44 @@ +name: 'Test Report' +on: + workflow_run: + workflows: ['CI'] # runs after CI workflow + types: + - completed +permissions: + contents: read + actions: read + checks: write +jobs: + report: + runs-on: ubuntu-latest + steps: + - uses: dorny/test-reporter@v2 + with: + artifact: test-results-3.10 # artifact name for Python 3.10 + name: Python 3.10 Tests # Name of the check run which will be created + path: '*.xml' # Path to test results (inside artifact .zip) + reporter: java-junit # Format of test results + - uses: dorny/test-reporter@v2 + with: + artifact: test-results-3.11 # artifact name for Python 3.11 + name: Python 3.11 Tests # Name of the check run which will be created + path: '*.xml' # Path to test results (inside artifact .zip) + reporter: java-junit # Format of test results + + coverage-report: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/download-artifact@v4 + with: + name: test-results-3.10 + path: test_results_3_10/ + - uses: actions/download-artifact@v4 + with: + name: test-results-3.11 + path: test_results_3_11/ + - name: Pytest coverage comment + uses: MishaKav/pytest-coverage-comment@main + with: + pytest-xml-coverage-path: test_results_3_10/coverage_3.10.xml + junitxml-path: test_results_3_10/test_results_3.10.xml \ No newline at end of file