Bump diff-cover from 10.3.0 to 10.5.0 #447
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: 🧪 test | |
| on: | |
| push: | |
| paths-ignore: | |
| - "**.md" | |
| branches: | |
| - main | |
| tags: | |
| - "**" | |
| pull_request: | |
| paths-ignore: | |
| - "**.md" | |
| branches: | |
| - "**" | |
| schedule: | |
| - cron: "0 13 * * *" | |
| concurrency: | |
| group: ${{ github.event_name == 'pull_request' && format('{0}-{1}', github.workflow_ref, github.event.pull_request.number) || github.run_id }} | |
| cancel-in-progress: true | |
| jobs: | |
| test: | |
| name: ${{ matrix.os.name }} - ${{ matrix.python.name }} | |
| runs-on: ${{ matrix.os.runs-on }} | |
| timeout-minutes: 30 | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: | |
| - name: "Ubuntu Intel" | |
| runs-on: ubuntu-latest | |
| platform: "ubuntu" | |
| pytest-threads: 2 | |
| - name: "Ubuntu Arm" | |
| runs-on: ubuntu-24.04-arm | |
| platform: "ubuntu" | |
| pytest-threads: 2 | |
| - name: "MacOS Intel" | |
| runs-on: "macos-15-intel" | |
| platform: "macos" | |
| pytest-threads: 4 | |
| - name: "MacOS M1" | |
| runs-on: "macos-15" | |
| platform: "macos" | |
| pytest-threads: 4 | |
| - name: "Windows" | |
| runs-on: windows-latest | |
| platform: "windows" | |
| pytest-threads: 4 | |
| python: | |
| - version: "3.10" | |
| - version: "3.11" | |
| - version: "3.12" | |
| - version: "3.13" | |
| env: | |
| CHIA_ROOT: ${{ github.workspace }}/.chia/mainnet | |
| JOB_FILE_NAME: tests_${{ matrix.os.name }}_python-${{ matrix.python.version }} | |
| BLOCKS_AND_PLOTS_VERSION: 0.45.20 | |
| steps: | |
| - name: Configure git | |
| run: | | |
| git config --global core.autocrlf false | |
| - name: Checkout code | |
| uses: actions/checkout@v6.0.2 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set Env | |
| uses: Chia-Network/actions/setjobenv@main | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Setup Python environment | |
| uses: Chia-Network/actions/setup-python@main | |
| with: | |
| python-version: ${{ matrix.python.version }} | |
| - uses: chia-network/actions/cache-pip@main | |
| with: | |
| mode: poetry | |
| - uses: ./.github/actions/install | |
| with: | |
| python-version: ${{ matrix.python.version }} | |
| development: true | |
| editable: false | |
| - uses: chia-network/actions/activate-venv@main | |
| - name: Verify source and installed tests collect and match | |
| shell: bash | |
| run: | | |
| echo '==== collecting source tests ====' | |
| if pytest --collect-only -qq --import-mode=prepend chia_pool/_tests > source_tests_raw | |
| then | |
| cat source_tests_raw | sed -n 's;^\(chia_pool/_tests.*\);\1;p' | sort > source_tests | |
| else | |
| echo ' ==== source test collection failure' | |
| cat source_tests_raw | |
| exit 1 | |
| fi | |
| echo '==== collecting installed tests ====' | |
| if pytest --collect-only -qq --import-mode=append --pyargs chia_pool._tests > installed_tests_raw | |
| then | |
| cat installed_tests_raw | sed -n 's;^\.venv/.*/\(chia_pool/_tests.*\);\1;p' | sort > installed_tests | |
| else | |
| echo ' ==== installed test collection failure' | |
| cat installed_tests_raw | |
| exit 1 | |
| fi | |
| echo '==== collected tests ====' | |
| for mode in source installed | |
| do | |
| echo "::group::collected ${mode} tests" | |
| cat ${mode}_tests | |
| echo '::endgroup::' | |
| done | |
| echo '==== diffing collected tests ====' | |
| echo "::group::collected tests diff" | |
| diff --unified source_tests installed_tests; DIFF_EXIT_CODE=$? | |
| echo '::endgroup::' | |
| exit $DIFF_EXIT_CODE | |
| - name: Cache test blocks and plots | |
| uses: actions/cache@v5 | |
| env: | |
| SEGMENT_DOWNLOAD_TIMEOUT_MIN: 1 | |
| id: test-blocks-plots | |
| with: | |
| path: | | |
| ${GITHUB_WORKSPACE}/.chia/blocks | |
| ${GITHUB_WORKSPACE}/.chia/test-plots | |
| ${GITHUB_WORKSPACE}/.chia/test-bundles | |
| key: ${{ env.BLOCKS_AND_PLOTS_VERSION }} | |
| - name: Checkout test blocks and plots | |
| if: steps.test-blocks-plots.outputs.cache-hit != 'true' | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| shell: bash | |
| run: | | |
| gh release download -R Chia-Network/test-cache ${{ env.BLOCKS_AND_PLOTS_VERSION }} --archive=tar.gz -O - | tar xzf - | |
| mkdir "${GITHUB_WORKSPACE}/.chia" | |
| mv "${GITHUB_WORKSPACE}/test-cache-${{ env.BLOCKS_AND_PLOTS_VERSION }}/"* "${GITHUB_WORKSPACE}/.chia" | |
| - name: Test code with pytest | |
| shell: bash | |
| run: | | |
| pytest . -n ${{ matrix.os.pytest-threads }} --cov=chia_pool --cov-config=.coveragerc --cov-report= | |
| - name: Process coverage data | |
| shell: bash | |
| run: | | |
| coverage xml --rcfile=.coveragerc -o coverage.xml | |
| mkdir -p coverage-data | |
| cp .coverage "coverage-data/.coverage.${{ env.JOB_FILE_NAME }}" | |
| cp coverage.xml "coverage-data/coverage.${{ env.JOB_FILE_NAME }}.xml" | |
| coverage report --rcfile=.coveragerc --show-missing | |
| - name: Publish coverage data | |
| uses: actions/upload-artifact@v7 | |
| with: | |
| name: coverage-data-${{ env.JOB_FILE_NAME }} | |
| path: coverage-data/* | |
| include-hidden-files: true | |
| if-no-files-found: error | |
| coverage: | |
| if: always() && github.repository_owner == 'Chia-Network' | |
| name: Coverage - Python 3.12 | |
| runs-on: ubuntu-latest | |
| needs: test | |
| steps: | |
| - uses: re-actors/alls-green@v1.2.2 | |
| id: alls-green | |
| with: | |
| jobs: ${{ toJSON(needs) }} | |
| - uses: actions/checkout@v6.0.2 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set Env | |
| uses: Chia-Network/actions/setjobenv@main | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Download Coverage | |
| uses: actions/download-artifact@v8 | |
| with: | |
| merge-multiple: true | |
| pattern: coverage-data-* | |
| path: coverage-data | |
| - name: Setup Python environment | |
| uses: Chia-Network/actions/setup-python@main | |
| with: | |
| python-version: "3.12" | |
| - uses: ./.github/actions/install | |
| with: | |
| python-version: "3.12" | |
| development: true | |
| - uses: chia-network/actions/activate-venv@main | |
| - name: Coverage Processing | |
| run: | | |
| coverage combine --rcfile=.coveragerc --data-file=coverage-reports/.coverage coverage-data/ | |
| coverage xml --rcfile=.coveragerc --data-file=coverage-reports/.coverage -o coverage-reports/coverage.xml | |
| coverage html --rcfile=.coveragerc --data-file=coverage-reports/.coverage --directory coverage-reports/html/ | |
| - uses: coverallsapp/github-action@v2 | |
| if: always() && steps.alls-green.outputs.success == 'true' && github.event.repository.visibility == 'public' | |
| env: | |
| COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }} | |
| with: | |
| fail-on-error: false | |
| - name: Coverage report (chia_pool/) | |
| if: always() && steps.alls-green.outputs.success == 'true' | |
| run: | | |
| set -o pipefail | |
| coverage report --rcfile=.coveragerc --data-file=coverage-reports/.coverage --include='chia_pool/**/*' --omit='chia_pool/_tests/**/*' --show-missing | tee coverage-reports/coverage-chia_pool-stdout | |
| - name: Coverage report (chia_pool/_tests/) | |
| if: always() && steps.alls-green.outputs.success == 'true' | |
| run: | | |
| set -o pipefail | |
| coverage report --rcfile=.coveragerc --data-file=coverage-reports/.coverage --include='chia_pool/_tests/**/*' --show-missing | tee coverage-reports/coverage-tests-stdout | |
| - name: Identify parent commit | |
| id: parent-commit | |
| run: | | |
| echo "hash=$(git rev-parse HEAD~1)" >> "$GITHUB_OUTPUT" | |
| - name: Coverage report (diff) | |
| if: (github.base_ref != '' || github.event.before != '') && always() && steps.alls-green.outputs.success == 'true' | |
| env: | |
| compare-branch: ${{ github.base_ref == '' && steps.parent-commit.outputs.hash || format('origin/{0}', github.base_ref) }} | |
| run: | | |
| set -o pipefail | |
| diff-cover --config-file=.diffcover.toml --compare-branch=${{ env.compare-branch }} --fail-under=100 --format html:coverage-reports/diff-cover.html,markdown:coverage-reports/diff-cover.md coverage-reports/coverage.xml | tee coverage-reports/diff-cover-stdout | |
| COV_STATUS="${PIPESTATUS[0]}" | |
| echo "COV_STATUS=$COV_STATUS" >> "$GITHUB_ENV" | |
| if [[ $COV_STATUS != '0' && "$GITHUB_BASE_REF" != '' ]]; then | |
| exit 1 | |
| fi | |
| - name: Remove previous coverage report comment and label from PR | |
| if: github.base_ref != '' && always() && steps.alls-green.outputs.success == 'true' | |
| shell: bash | |
| env: | |
| COV_STATUS: ${{ env.COV_STATUS }} | |
| GH_TOKEN: ${{ github.token }} | |
| ORG_REPO: ${{ github.repository }} | |
| run: | | |
| PR_NUM=$(jq -r '.number' "$GITHUB_EVENT_PATH") | |
| COMMENTS=$(gh api -X GET /repos/"${ORG_REPO}"/issues/"${PR_NUM}"/comments) | |
| COMMENT_ID=$(echo "$COMMENTS" | jq '.[] | select(.user.login == "github-actions[bot]" and (.body | tostring | contains("<!-- COVERAGE_COMMENT_'"${PR_NUM}"' -->"))) | .id') | |
| COVERAGE_LABEL=$(gh pr view "$PR_NUM" --json labels --jq ' .labels[].name | select(. == "coverage-diff")') | |
| if [[ -n "$COMMENT_ID" ]]; then | |
| gh api -X DELETE /repos/"${ORG_REPO}"/issues/comments/"${COMMENT_ID}" | |
| fi | |
| if [[ "$COV_STATUS" == '0' ]]; then | |
| if [[ "$COVERAGE_LABEL" == "coverage-diff" ]]; then | |
| gh pr edit "$PR_NUM" --remove-label "coverage-diff" | |
| fi | |
| fi | |
| - name: Add diff coverage report comment to PR | |
| if: github.base_ref != '' && always() && steps.alls-green.outputs.success == 'true' | |
| env: | |
| BRANCH_NAME: ${{ github.sha }} | |
| COV_STATUS: ${{ env.COV_STATUS }} | |
| GH_TOKEN: ${{ github.token }} | |
| ORG_REPO: ${{ github.repository }} | |
| run: | | |
| if [[ $COV_STATUS != '0' ]]; then | |
| BASE_URL="https://github.com/${ORG_REPO}/blob/${BRANCH_NAME}" | |
| PR_NUM=$(jq -r '.number' "$GITHUB_EVENT_PATH") | |
| COVERAGE_LABEL=$(gh pr view "$PR_NUM" --json labels --jq ' .labels[].name | select(. == "coverage-diff")') | |
| CONTENT=$(<coverage-reports/diff-cover-stdout) | |
| OUTPUT="<!-- COVERAGE_COMMENT_${PR_NUM} -->\n| File | Coverage | Missing Lines |\n|------|----------|---------------|\n" | |
| TOTAL_LINES="Unknown" | |
| MISSING_LINES="Unknown" | |
| TOTAL_COVERAGE="Unknown" | |
| IFS=$'\n' | |
| for LINE in $CONTENT; do | |
| if [[ $LINE =~ ^(.*\.py)\ \(([0-9\.]+%)\)\:\ Missing\ lines\ (.*)$ ]]; then | |
| FILE="${BASH_REMATCH[1]}" | |
| COVERAGE="${BASH_REMATCH[2]}" | |
| MISSING="${BASH_REMATCH[3]}" | |
| MISSING_TRANSFORMED="lines " | |
| IFS=',' read -ra MISSING_PARTS <<< "$MISSING" | |
| for PART in "${MISSING_PARTS[@]}"; do | |
| if [[ $PART =~ ^([0-9]+)\-([0-9]+)$ ]]; then | |
| MISSING_TRANSFORMED+="[${BASH_REMATCH[1]}-${BASH_REMATCH[2]}](${BASE_URL}/${FILE}#L${BASH_REMATCH[1]}-L${BASH_REMATCH[2]}), " | |
| else | |
| MISSING_TRANSFORMED+="[${PART}](${BASE_URL}/${FILE}#L${PART}), " | |
| fi | |
| done | |
| MISSING_TRANSFORMED=${MISSING_TRANSFORMED%, } | |
| OUTPUT+="| [\`${FILE}\`](${BASE_URL}/${FILE}) | ${COVERAGE} | ${MISSING_TRANSFORMED} |\n" | |
| elif [[ $LINE =~ ^Total:\ \ \ (.*)\ lines$ ]]; then | |
| TOTAL_LINES="${BASH_REMATCH[1]} lines" | |
| elif [[ $LINE =~ ^Missing:\ (.*)\ lines$ ]]; then | |
| MISSING_LINES="${BASH_REMATCH[1]} lines" | |
| elif [[ $LINE =~ ^Coverage:\ (.*)%$ ]]; then | |
| TOTAL_COVERAGE="${BASH_REMATCH[1]}%" | |
| fi | |
| done | |
| OUTPUT+="\n| Total | Missing | Coverage |\n|-------|---------|----------|\n| ${TOTAL_LINES} | ${MISSING_LINES} | ${TOTAL_COVERAGE} |\n" | |
| echo -e "$OUTPUT" > temp_comment.txt | |
| gh pr comment "$PR_NUM" -F temp_comment.txt | |
| if [[ $COVERAGE_LABEL != "coverage-diff" ]]; then | |
| gh pr edit "$PR_NUM" --add-label "coverage-diff" | |
| fi | |
| fi | |
| - name: Add diff coverage report to workflow summary | |
| if: (github.base_ref != '' || github.event.before != '') && always() && steps.alls-green.outputs.success == 'true' | |
| run: | | |
| cat coverage-reports/diff-cover.md >> "$GITHUB_STEP_SUMMARY" | |
| - name: Publish coverage reports | |
| if: always() && steps.alls-green.outputs.success == 'true' | |
| uses: actions/upload-artifact@v7 | |
| with: | |
| name: coverage-reports | |
| path: coverage-reports/* | |
| if-no-files-found: error |