-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change coverage badge generation (#465)
* test(api) change api workflow * test(api) change api and cli workflow * test(api) test cli * test(api) test cli * test(api) test cli * test(api) test cli * test(api) create coverage github actions * test(api) create coverage github actions * test(api) create coverage github actions * test(api) create coverage github actions * test(api) create coverage github actions * test(api) create coverage github actions * test(api) create coverage github actions * test(api) create coverage github actions * test(api) create coverage github actions * test(api) create coverage github actions * test(api) create coverage github actions * test(api) use coverage github actions in cli * test(api) use coverage github actions in cli * test(api) use coverage github actions in cli * test(api) add Readme to badge generator script
- Loading branch information
Showing
7 changed files
with
335 additions
and
64 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
name: Coverage Badge Generation | ||
description: Generates a coverage badge and uploades it to an artifact | ||
|
||
inputs: | ||
BADGE_ARTIFACT_NAME: | ||
description: "Name of the Badge artifact" | ||
required: true | ||
COVERAGE_REPORT_ARTIFACT: | ||
description: "Name of the XML coverage report artifact" | ||
required: true | ||
COVERAGE_REPORT_NAME: | ||
description: "Name of the XML coverage report file" | ||
required: true | ||
LABEL: | ||
description: "Badge label" | ||
required: true | ||
OUTPUT_FILE: | ||
description: "Name of the output file" | ||
required: true | ||
RED_LIMIT: | ||
description: "Percentage of the red/orange limit" | ||
default: "50" | ||
required: false | ||
GREEN_LIMIT: | ||
description: "Percentage of the orange/green limit" | ||
default: "65" | ||
required: false | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.8' | ||
|
||
- name: Install requests | ||
shell: bash | ||
run: pip install requests | ||
|
||
- name: Install pycobertura | ||
shell: bash | ||
run: pip install pycobertura | ||
|
||
- name: Download line coverage reports | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: ${{ inputs.COVERAGE_REPORT_ARTIFACT }} | ||
|
||
- name: Generate badge | ||
shell: bash | ||
run: python assets/badge_generator/generate_badge.py --label "${{ inputs.LABEL }}" --output "${{ inputs.OUTPUT_FILE }}" --input-report "${{ inputs.COVERAGE_REPORT_NAME }}" --red-limit "${{ inputs.RED_LIMIT }}" --green-limit "${{ inputs.GREEN_LIMIT }}" | ||
|
||
- uses: actions/upload-artifact@v4 | ||
with: | ||
name: ${{ inputs.BADGE_ARTIFACT_NAME }} | ||
path: ${{ inputs.OUTPUT_FILE }} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
name: Upload Badge | ||
description: Uploads the generated badge to an specific branch | ||
|
||
inputs: | ||
BADGE_ARTIFACT_NAME: | ||
description: "Name of the Badge artifact" | ||
required: true | ||
BADGE_FILE_NAME: | ||
description: "Name of the Badge file" | ||
required: true | ||
BRANCH_NAME: | ||
description: "Name of the branch where you want to add the badge" | ||
required: true | ||
github_token: | ||
description: "Github token" | ||
required: true | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
ref: ${{ inputs.BRANCH_NAME }} | ||
|
||
- name: Download coverage badge | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: ${{ inputs.BADGE_ARTIFACT_NAME }} | ||
|
||
- name: Verify Changed files | ||
uses: tj-actions/verify-changed-files@v16 | ||
id: verify-changed-files | ||
with: | ||
files: ${{ inputs.BADGE_FILE_NAME }} | ||
|
||
- name: Commit badge | ||
if: steps.verify-changed-files.outputs.files_changed == 'true' | ||
shell: bash | ||
run: | | ||
git config --local user.email "<>" | ||
git config --local user.name "GitHubActions" | ||
git add ${{ inputs.BADGE_FILE_NAME }} | ||
git commit -m "Add/Update badge" | ||
- name: Push badge commit | ||
if: steps.verify-changed-files.outputs.files_changed == 'true' | ||
uses: ad-m/github-push-action@master | ||
with: | ||
github_token: ${{ inputs.github_token }} | ||
branch: ${{ inputs.BRANCH_NAME }} # Dedicated branch to store coverage badges | ||
|
||
- uses: actions/checkout@v4 # we checkout to main so we have access the actions folder and we can execute the Post Upload | ||
with: | ||
fetch-depth: "0" |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Badge Generator | ||
Script that generates a coverage badge. You can customize the following parameters: | ||
|
||
- The left label that will appear in the badge | ||
- The color range limits. By default, the badge will be red between 0-50%, orange between 50-65% and green if higher than 65 | ||
- The output file name | ||
|
||
The coverage percentage be passed in two different ways: | ||
|
||
- By giving the desired value using the flag `--coverage` | ||
- By indicating the path to the XML coverage report using the flag `--input-report` | ||
|
||
Installation | ||
------------ | ||
```bash | ||
# Generate python virtual environment and activate it | ||
python3 -m venv venv | ||
source venv/bin/activate | ||
|
||
# Install requirements | ||
pip install -r requirements.txt | ||
``` | ||
|
||
Examples | ||
------------ | ||
|
||
```bash | ||
# Run help | ||
python generate_badge.py --help | ||
|
||
# Generate badge with default values and indicating the coverage percentage | ||
python generate_badge.py --coverage 75 | ||
|
||
# Generate with xml report file | ||
python generate_badge.py --input-report coverage.xml | ||
|
||
# Generate badge with multiple parameters | ||
python generate_badge.py --label "API coverage" --input-report coverage.xml --output coverage_api.svg --red-limit 55 --green-limit 70 | ||
``` |
Oops, something went wrong.