Skip to content

Commit

Permalink
Merge pull request #132 from cicirello/131-feature-req-edit-workflow-…
Browse files Browse the repository at this point in the history
…summary-values

Option to customize heading for GitHub Actions workflow job summary
  • Loading branch information
cicirello authored Sep 15, 2023
2 parents 4efbe1f + 31004a6 commit 59b9b07
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ jobs:
generate-branches-badge: true
coverage-badge-filename: coverageMulti.svg
branches-badge-filename: branchesMulti.svg
workflow-summary-heading: "JaCoCo Test Coverage Summary: Multimodule Testcase"

- name: Log integration test outputs with multiple jacoco.csv files
run: |
Expand All @@ -66,6 +67,7 @@ jobs:
generate-branches-badge: false
generate-coverage-endpoint: true
generate-branches-endpoint: true
workflow-summary-heading: "JaCoCo Test Coverage Summary: Endpoints Testcase"

- name: Log integration endpoints test outputs
run: |
Expand All @@ -83,6 +85,7 @@ jobs:
generate-coverage-endpoint: false
generate-branches-endpoint: false
generate-summary: true
workflow-summary-heading: "JaCoCo Test Coverage Summary: Summary Report Testcase"

- name: Log integration summary report test outputs
run: |
Expand All @@ -104,6 +107,7 @@ jobs:
branches-endpoint-filename: customBranches.json
coverage-label: custom coverage label one
branches-label: custom coverage label two
workflow-summary-heading: "JaCoCo Test Coverage Summary: Custom Labels Testcase"

- name: Log integration test outputs with custom labels
run: |
Expand All @@ -119,6 +123,7 @@ jobs:
generate-branches-badge: true
coverage-badge-filename: coverageMulti.svg
branches-badge-filename: branchesMulti.svg
workflow-summary-heading: "JaCoCo Test Coverage Summary: Glob Testcase"

- name: Log integration test outputs with multiple csv files with glob
run: |
Expand Down
13 changes: 8 additions & 5 deletions .github/workflows/pypi-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,20 @@ jobs:
deploy:

runs-on: ubuntu-latest

environment:
name: pypi
url: https://pypi.org/p/jacoco-badge-generator
permissions:
id-token: write

steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
python-version: '3.11'

- name: Install dependencies
run: |
Expand All @@ -30,7 +36,4 @@ jobs:
run: python3 -m build

- name: Publish package
uses: pypa/[email protected]
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
uses: pypa/gh-action-pypi-publish@release/v1
12 changes: 10 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased] - 2023-09-08
## [Unreleased] - 2023-09-15

### Added

Expand All @@ -17,11 +17,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

### Dependencies
* Bump cicirello/pyaction from 4.22.0 to 4.23.0

### CI/CD


## [2.11.0] - 2023-09-15

### Added
* Option to customize heading for GitHub Actions workflow job summary

### Dependencies
* Bump cicirello/pyaction from 4.22.0 to 4.23.0


## [2.10.0] - 2023-09-04

### Added
Expand Down
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -534,9 +534,19 @@ you also set `generate-summary: true` and commit the summary report JSON file to
#### `generate-workflow-summary`

This input controls whether or not to log the coverage percentages to the GitHub Actions
Workflow Job Summary. The default is `generate-workflow-summary: true`. This input is only
workflow job summary. The default is `generate-workflow-summary: true`. This input is only
relevant when running in GitHub Actions mode, and not when running as a CLI tool.

#### `workflow-summary-heading`

This input is used to override the heading for the GitHub Actions workflow job summary that
can be found on the Actions tab with detailed workflow logs. It defaults to:
`workflow-summary-heading: JaCoCo Test Coverage Summary`. This default should be fine in most
cases. If you are using this action in a multimodule project, and generating separate badges
for each module, then you might consider using this input so that the GitHub workflow job
summary is clearer as to which output corresponds to which module. See the
[Multi-Module Example Workflows](#multi-module-example-workflows) section for examples. This
input is only relevant when running in GitHub Actions mode, and not when running as a CLI tool.

### Outputs

Expand Down Expand Up @@ -666,7 +676,7 @@ You can also use a specific release with:
```yml
- name: Generate JaCoCo Badge
uses: cicirello/jacoco-badge-generator@v2.10.0
uses: cicirello/jacoco-badge-generator@v2.11.0
with:
generate-branches-badge: true
```
Expand Down Expand Up @@ -705,6 +715,7 @@ what these inputs do.
fail-on-coverage-decrease: false
fail-on-branches-decrease: false
generate-workflow-summary: true
workflow-summary-heading: JaCoCo Test Coverage Summary
```

Since the above shows all of the default values of the action inputs,
Expand Down Expand Up @@ -997,6 +1008,7 @@ jobs:
branches-badge-filename: branches1.svg
coverage-label: coverage (module 1)
branches-label: branches (module 1)
workflow-summary-heading: Module 1 JaCoCo Test Coverage Summary
- name: Generate JaCoCo Badges for Module 2
id: jacocoMod2
Expand All @@ -1008,6 +1020,7 @@ jobs:
branches-badge-filename: branches2.svg
coverage-label: coverage (module 2)
branches-label: branches (module 2)
workflow-summary-heading: Module 2 JaCoCo Test Coverage Summary
- name: Commit the badge (if it changed)
run: |
Expand Down Expand Up @@ -1228,6 +1241,7 @@ you do not need to include them.
| `fail-on-coverage-decrease: false` | `--fail-on-coverage-decrease false` |
| `fail-on-branches-decrease: false` | `--fail-on-branches-decrease false` |
| `generate-workflow-summary: true` | n/a |
| `workflow-summary-heading: JaCoCo Test Coverage Summary` | n/a |

## Built With

Expand Down
7 changes: 6 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,13 @@ inputs:
required: false
default: 'coverage-summary.json'
generate-workflow-summary:
description: 'Controls whether or not to append markdown summary to the GitHub Workflow Summary page.'
description: 'Controls whether or not to append summary to the GitHub workflow summary page.'
required: false
default: true
workflow-summary-heading:
description: 'The heading for the GitHub workflow job summary'
required: false
default: JaCoCo Test Coverage Summary
outputs:
coverage:
description: 'The jacoco coverage percentage as computed from the data in the jacoco.csv file.'
Expand Down Expand Up @@ -151,3 +155,4 @@ runs:
- ${{ inputs.generate-workflow-summary }}
- ${{ inputs.coverage-label }}
- ${{ inputs.branches-label }}
- ${{ inputs.workflow-summary-heading }}
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "jacoco-badge-generator"
version = "2.10.0"
version = "2.11.0"
authors = [
{ name="Vincent A. Cicirello", email="[email protected]" },
]
Expand Down
3 changes: 2 additions & 1 deletion src/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,6 @@
appendWorkflowSummary = sys.argv[20].lower() == "true",
coverageLabel = sys.argv[21],
branchesLabel = sys.argv[22],
ghActionsMode = True
ghActionsMode = True,
workflowJobSummaryHeading = sys.argv[23]
)
3 changes: 2 additions & 1 deletion src/jacoco_badge_generator/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,5 +228,6 @@
appendWorkflowSummary = False,
coverageLabel = args.coverageLabel,
branchesLabel = args.branchesLabel,
ghActionsMode = False
ghActionsMode = False,
workflowJobSummaryHeading = "JaCoCo Test Coverage Summary"
)
16 changes: 11 additions & 5 deletions src/jacoco_badge_generator/coverage_badges.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@

defaultColors = [ "#4c1", "#97ca00", "#a4a61d", "#dfb317", "#fe7d37", "#e05d44" ]

markdownSummaryTemplate = """## JaCoCo Test Coverage Summary
markdownSummaryTemplate = """## {2}
* __Coverage:__ {0:.3%}
* __Branches:__ {1:.3%}
* __Generated by:__ jacoco-badge-generator
Expand Down Expand Up @@ -493,7 +493,7 @@ def set_action_outputs(output_pairs, ghActionsMode) :
for key, value in output_pairs.items() :
print(output_template.format(key, value))

def add_workflow_job_summary(cov, branches) :
def add_workflow_job_summary(cov, branches, heading) :
"""When running as a GitHub Action, adds a job summary, and otherwise
does nothing when running in CLI mode. Note that if the CLI mode is
used within a GitHub Actions workflow, it will be treated the same as
Expand All @@ -502,10 +502,13 @@ def add_workflow_job_summary(cov, branches) :
Keyword arguments:
cov - Coverage percentage
branches - Branches coverage percentage
heading - the heading for the GitHub workflow job summary
"""
if "GITHUB_STEP_SUMMARY" in os.environ :
with open(os.environ["GITHUB_STEP_SUMMARY"], "a") as f :
print(markdownSummaryTemplate.format(cov, branches), file=f)
print(
markdownSummaryTemplate.format(cov, branches, heading),
file=f)

def main(jacocoCsvFile,
badgesDirectory,
Expand All @@ -529,7 +532,8 @@ def main(jacocoCsvFile,
appendWorkflowSummary,
coverageLabel,
branchesLabel,
ghActionsMode) :
ghActionsMode,
workflowJobSummaryHeading) :
"""Main function.
Keyword arguments:
Expand Down Expand Up @@ -572,6 +576,8 @@ def main(jacocoCsvFile,
coverageLabel - Text for the left-side of the coverage badge.
branchesLabel - Text for the left-side of the branches coverage badge.
ghActionsMode - True if running in GitHub Actions mode, or False otherwise.
workflowJobSummaryHeading - the heading for the GitHub workflow job summary
(ignored when run in CLI mode).
"""
if onMissingReport not in {"fail", "quiet", "badges"} :
print("ERROR: Invalid value for on-missing-report.")
Expand Down Expand Up @@ -654,5 +660,5 @@ def main(jacocoCsvFile,
)

if appendWorkflowSummary :
add_workflow_job_summary(cov, branches)
add_workflow_job_summary(cov, branches, workflowJobSummaryHeading)

0 comments on commit 59b9b07

Please sign in to comment.