mirror of
https://github.com/pyTooling/Actions.git
synced 2026-02-12 02:56:56 +08:00
Added Python 3.12 support.
Merge junit files. Merge coverage files. Extending UnitTesting to support code coverage in a matrix too.
This commit is contained in:
160
.github/workflows/PublishCoverageResults.yml
vendored
160
.github/workflows/PublishCoverageResults.yml
vendored
@@ -19,15 +19,35 @@
|
||||
# #
|
||||
# SPDX-License-Identifier: Apache-2.0 #
|
||||
# ==================================================================================================================== #
|
||||
name: Publish Unit Test Results
|
||||
name: Publish Code Coverage Results
|
||||
|
||||
on:
|
||||
workflow_call:
|
||||
inputs:
|
||||
report_files:
|
||||
description: 'Pattern of report files to upload. Can be a comma separated list.'
|
||||
coverage_config:
|
||||
description: 'Path to the .coveragerc file. Use pyproject.toml by default.'
|
||||
required: false
|
||||
default: 'artifacts/**/*.xml'
|
||||
default: 'pyproject.toml'
|
||||
type: string
|
||||
coverage_sqlite_artifact:
|
||||
description: 'Name of the SQLite coverage artifact.'
|
||||
required: false
|
||||
default: ''
|
||||
type: string
|
||||
coverage_xml_artifact:
|
||||
description: 'Name of the XML coverage artifact.'
|
||||
required: false
|
||||
default: ''
|
||||
type: string
|
||||
coverage_json_artifact:
|
||||
description: 'Name of the JSON coverage artifact.'
|
||||
required: false
|
||||
default: ''
|
||||
type: string
|
||||
coverage_html_artifact:
|
||||
description: 'Name of the HTML coverage artifact.'
|
||||
required: false
|
||||
default: ''
|
||||
type: string
|
||||
secrets:
|
||||
codacy_token:
|
||||
@@ -35,8 +55,8 @@ on:
|
||||
required: true
|
||||
|
||||
jobs:
|
||||
PublishTestResults:
|
||||
name: 📊 Publish Test Results
|
||||
PublishCoverageResults:
|
||||
name: 📊 Publish Code Coverage Results
|
||||
runs-on: ubuntu-latest
|
||||
if: always()
|
||||
|
||||
@@ -49,6 +69,134 @@ jobs:
|
||||
with:
|
||||
path: artifacts
|
||||
|
||||
- name: 🔧 Install coverage and tomli
|
||||
run: |
|
||||
python -m pip install --disable-pip-version-check -U coverage[toml] tomli
|
||||
|
||||
- name: 🔁 Extract configurations from pyproject.toml
|
||||
id: getVariables
|
||||
shell: python
|
||||
run: |
|
||||
from os import getenv
|
||||
from pathlib import Path
|
||||
from sys import version
|
||||
from textwrap import dedent
|
||||
|
||||
print(f"Python: {version}")
|
||||
|
||||
from tomli import load as tomli_load
|
||||
|
||||
htmlDirectory = Path("htmlcov")
|
||||
xmlFile = Path("./coverage.xml")
|
||||
jsonFile = Path("./coverage.json")
|
||||
coverageRC = "${{ inputs.coverage_config }}".strip()
|
||||
|
||||
# Read output paths from 'pyproject.toml' file
|
||||
if coverageRC == "pyproject.toml":
|
||||
pyProjectFile = Path("pyproject.toml")
|
||||
if pyProjectFile.exists():
|
||||
with pyProjectFile.open("rb") as file:
|
||||
pyProjectSettings = tomli_load(file)
|
||||
|
||||
htmlDirectory = Path(pyProjectSettings["tool"]["coverage"]["html"]["directory"])
|
||||
xmlFile = Path(pyProjectSettings["tool"]["coverage"]["xml"]["output"])
|
||||
jsonFile = Path(pyProjectSettings["tool"]["coverage"]["json"]["output"])
|
||||
else:
|
||||
print(f"File '{pyProjectFile}' not found and no '.coveragerc' file specified.")
|
||||
|
||||
# Read output paths from '.coveragerc' file
|
||||
elif len(coverageRC) > 0:
|
||||
coverageRCFile = Path(coverageRC)
|
||||
if coverageRCFile.exists():
|
||||
with coverageRCFile.open("rb") as file:
|
||||
coverageRCSettings = tomli_load(file)
|
||||
|
||||
htmlDirectory = Path(coverageRCSettings["html"]["directory"])
|
||||
xmlFile = Path(coverageRCSettings["xml"]["output"])
|
||||
jsonFile = Path(coverageRCSettings["json"]["output"])
|
||||
else:
|
||||
print(f"File '{coverageRCFile}' not found.")
|
||||
|
||||
# Write jobs to special file
|
||||
github_output = Path(getenv("GITHUB_OUTPUT"))
|
||||
print(f"GITHUB_OUTPUT: {github_output}")
|
||||
with github_output.open("a+", encoding="utf-8") as f:
|
||||
f.write(dedent(f"""\
|
||||
coverage_report_html_directory={htmlDirectory.as_posix()}
|
||||
coverage_report_xml={xmlFile}
|
||||
coverage_report_json={jsonFile}
|
||||
"""))
|
||||
|
||||
print(f"DEBUG:\n html={htmlDirectory}\n xml={xmlFile}\n json={jsonFile}")
|
||||
|
||||
- name: Rename .coverage files and collect them all to coverage/
|
||||
run: |
|
||||
mkdir -p coverage
|
||||
find . -type f -path "*artifacts*SQLite*.coverage" -exec sh -c 'cp -v $0 "coverage/$(basename $0).$(basename $(dirname $0))"' {} ';'
|
||||
tree -a coverage
|
||||
|
||||
- name: Combine SQLite files (using Coverage.py)
|
||||
if: inputs.coverage_xml_artifact != ''
|
||||
run: coverage combine coverage/
|
||||
|
||||
- name: Report code coverage
|
||||
run: coverage report --rcfile=pyproject.toml --data-file=.coverage
|
||||
|
||||
- name: Convert to XML format (Cobertura)
|
||||
if: inputs.coverage_xml_artifact != ''
|
||||
run: coverage xml --data-file=.coverage
|
||||
|
||||
- name: Convert to JSON format
|
||||
if: inputs.coverage_json_artifact != ''
|
||||
run: coverage json --data-file=.coverage
|
||||
|
||||
- name: Convert to HTML format
|
||||
if: inputs.coverage_html_artifact != ''
|
||||
run: |
|
||||
coverage html --data-file=.coverage -d report/coverage/html
|
||||
rm report/coverage/html/.gitignore
|
||||
tree -a report/coverage/html
|
||||
|
||||
- name: 📤 Upload 'Coverage SQLite Database' artifact
|
||||
if: inputs.coverage_sqlite_artifact != ''
|
||||
continue-on-error: true
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: ${{ inputs.coverage_sqlite_artifact }}
|
||||
path: .coverage
|
||||
if-no-files-found: error
|
||||
retention-days: 1
|
||||
|
||||
- name: 📤 Upload 'Coverage XML Report' artifact
|
||||
if: inputs.coverage_xml_artifact != ''
|
||||
continue-on-error: true
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: ${{ inputs.coverage_xml_artifact }}
|
||||
path: ${{ steps.getVariables.outputs.coverage_report_xml }}
|
||||
if-no-files-found: error
|
||||
retention-days: 1
|
||||
|
||||
- name: 📤 Upload 'Coverage JSON Report' artifact
|
||||
if: inputs.coverage_json_artifact != ''
|
||||
continue-on-error: true
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: ${{ inputs.coverage_json_artifact }}
|
||||
path: ${{ steps.getVariables.outputs.coverage_report_json }}
|
||||
if-no-files-found: error
|
||||
retention-days: 1
|
||||
|
||||
- name: 📤 Upload 'Coverage HTML Report' artifact
|
||||
if: inputs.coverage_html_artifact != ''
|
||||
continue-on-error: true
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: ${{ inputs.coverage_html_artifact }}
|
||||
path: ${{ steps.getVariables.outputs.coverage_report_html_directory }}
|
||||
if-no-files-found: error
|
||||
retention-days: 1
|
||||
|
||||
- name: 📊 Publish code coverage at CodeCov
|
||||
if: inputs.CodeCov == true
|
||||
continue-on-error: true
|
||||
|
||||
Reference in New Issue
Block a user