forked from EVerest/EVerest
-
Notifications
You must be signed in to change notification settings - Fork 0
92 lines (90 loc) · 3.56 KB
/
Copy pathjob_create-coverage-badge.yml
File metadata and controls
92 lines (90 loc) · 3.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
name: Create Coverage Badge
on:
workflow_call:
inputs:
runner:
description: 'Which runner to use'
required: false
default: 'ubuntu-24.04'
type: string
ref_everest_ci:
description: 'The ref of the everest-ci repository to checkout'
required: true
type: string
is_fork:
description: 'Whether the current repository is a fork'
required: true
type: string
artifact_deploy_target_repo:
description: 'Repository to deploy artifacts to'
required: true
type: string
coverage_report_artifact_name:
description: 'The name of the coverage report artifact to download'
required: true
type: string
coverage_xml_artifact_name:
description: 'The name of the coverage xml artifact to download'
required: true
type: string
secrets:
coverage_deploy_token:
description: 'The token to use to deploy the coverage report'
required: true
jobs:
create-coverage-badge:
name: Create Coverage Badge
runs-on: ${{ inputs.runner }}
steps:
- name: Checkout local github actions
uses: actions/checkout@v4
with:
repository: ${{ github.repository_owner }}/everest-ci
ref: ${{ inputs.ref_everest_ci }}
path: everest-ci
- name: Download xml coverage report
uses: actions/download-artifact@v5.0.0
with:
if-no-files-found: error
name: ${{ inputs.coverage_xml_artifact_name }}
path: coverage-xml
- name: Parse coverage report
id: parse_coverage_report
shell: python3 {0}
run: |
import xml.etree.ElementTree
import os
tree = xml.etree.ElementTree.parse("${{ github.workspace }}/coverage-xml/gcovr-coverage-xml.xml")
line_coverage = tree.getroot().get("line-rate")
with open(os.environ["GITHUB_OUTPUT"], "a") as f:
f.write(f"line_coverage={line_coverage}\n")
f.write(f"line_coverage_percentage={float(line_coverage) * 100}\n")
- name: Generate coverage badge
run: |
pip install anybadge
mkdir -p ${{ github.workspace }}/coverage-badge/
anybadge -o --label Coverage --value ${{ steps.parse_coverage_report.outputs.line_coverage_percentage }} -s "%" --file ${{ github.workspace }}/coverage-badge/coverage-badge.svg 20=red 40=orange 60=yellow 80=yellowgreen 100=green
- name: Deploy coverage badge
uses: ./everest-ci/github-actions/deploy-ci-artifact
if: ${{ inputs.is_fork == 'false' }}
with:
target_repo: ${{ inputs.artifact_deploy_target_repo }}
github_token: ${{ secrets.coverage_deploy_token }}
artifact_name: coverage-badge
artifact_directory: ${{ github.workspace }}/coverage-badge/
deploy_global_artifact: true
- name: Download html coverage report
uses: actions/download-artifact@v5.0.0
with:
if-no-files-found: error
name: ${{ inputs.coverage_report_artifact_name }}
path: coverage-report
- name: Deploy html coverage report
uses: ./everest-ci/github-actions/deploy-ci-artifact
if: ${{ inputs.is_fork == 'false' }}
with:
target_repo: ${{ inputs.artifact_deploy_target_repo }}
github_token: ${{ secrets.coverage_deploy_token }}
artifact_name: ${{ inputs.coverage_report_artifact_name }}
artifact_directory: ${{ github.workspace }}/coverage-report/
deploy_global_artifact: true