Skip to content

Commit e2bdbd4

Browse files
committed
Better reporting workflow (#3)
* enhance PDK workflow with validation results annotation * switch to inline command for run property in pdk_tests.yaml * replacing shell script by python script to parse xml formatted result of `pdk validate` * setting up pdk manually, rather than having to install python in container * piping the output of `pdk validate` to pdk-validate annotation script * using job environment variable to define directory targeted by scan
1 parent af8c9af commit e2bdbd4

File tree

2 files changed

+65
-9
lines changed

2 files changed

+65
-9
lines changed

.github/scripts/pdk_validate

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env python3
2+
3+
import xml.etree.ElementTree as et
4+
import sys
5+
6+
PUPPET_MODULE=""
7+
8+
def parse_pdk_validate_results() -> et.ElementTree:
9+
"""
10+
Parse the xml file and return the tree
11+
12+
Returns:
13+
et.ElementTree: The parsed tree
14+
"""
15+
tree = et.parse(sys.stdin)
16+
return tree
17+
18+
def add_annotation(testcase:et.Element):
19+
"""
20+
Writes Github commands to stdout to add annotations to the Github Actions
21+
22+
Args:
23+
testcase (et.Element): The testcase to add the annotation for
24+
"""
25+
check=testcase[0].get("classname")
26+
file,line,column=testcase[0].get("name").split(":")
27+
kind="error" if testcase[1].get("type")=="error" else "warning"
28+
message=testcase[1].get("message")
29+
print(f"::{kind} file={PUPPET_MODULE}/{file},line={line},col={column},title={check}::{message}")
30+
31+
def scan_testcases(only_errors:bool):
32+
"""
33+
Scan the test cases
34+
35+
Args:
36+
only_errors (bool): Only scan for errors
37+
"""
38+
root = parse_pdk_validate_results().getroot()
39+
40+
for testcase in root.iter("testcase"):
41+
failure = testcase.find("failure")
42+
if failure is None:
43+
continue
44+
if only_errors and failure.get("type")!="error":
45+
continue
46+
add_annotation([testcase, failure])
47+
48+
def main(only_errors):
49+
scan_testcases(only_errors)
50+
51+
if __name__ == "__main__":
52+
if "--module" in sys.argv:
53+
PUPPET_MODULE=sys.argv[sys.argv.index("--module")+1]
54+
main(sys.argv[1]=="--only-errors")

.github/workflows/pdk_tests.yaml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,25 @@ jobs:
66
run-pdk-tests:
77
name: Run PDK tests
88
runs-on: ubuntu-latest
9-
container:
10-
image: puppet/pdk:latest
9+
env:
10+
PUPPET_MODULE: site/profile
1111

1212
steps:
1313
- name: Checkout code
1414
uses: actions/checkout@v4
1515

16-
- name: Run PDK version
17-
run: pdk --version
18-
continue-on-error: false
16+
- name: Setup PDK
17+
run: |
18+
wget https://apt.puppet.com/puppet-tools-release-jammy.deb
19+
sudo dpkg -i puppet-tools-release-jammy.deb
20+
sudo apt-get update
21+
sudo apt-get install pdk
1922
2023
- name: Run PDK validate
21-
run: pdk validate
22-
working-directory: site/profile
23-
continue-on-error: true
24+
run: pdk validate --format=junit | "${{github.workspace}}/.github/scripts/pdk_validate" --only-errors --module ${{env.PUPPET_MODULE}}
25+
working-directory: "${{env.PUPPET_MODULE}}"
2426

2527
- name: Run PDK unit test
2628
run: pdk test unit
27-
working-directory: site/profile
2829
continue-on-error: true
30+
working-directory: "${{env.PUPPET_MODULE}}"

0 commit comments

Comments
 (0)