Skip to content

Commit e882b9a

Browse files
committed
[rocprofiler-sdk][CI] Add formatting for counter_defs.yaml file
1 parent e9fbc3f commit e882b9a

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

.github/workflows/rocprofiler-sdk-formatting.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,35 @@ jobs:
175175
cat ${OUTFILE}
176176
exit 1
177177
fi
178+
179+
counter_defs:
180+
runs-on: ubuntu-22.04
181+
182+
steps:
183+
- uses: actions/checkout@v4
184+
with:
185+
sparse-checkout: projects/rocprofiler-sdk
186+
187+
- name: Set up Python
188+
uses: actions/setup-python@v5
189+
with:
190+
python-version: '3.10'
191+
192+
- name: Install dependencies
193+
run: |
194+
python -m pip install --upgrade pip
195+
python -m pip install ruamel.yaml
196+
197+
- name: Ensure counter_defs.yaml is formatted
198+
working-directory: projects/rocprofiler-sdk
199+
run: |
200+
python source/scripts/format-deps.py --counter-defs
201+
if [ $(git diff -- source/share/rocprofiler-sdk/counter_defs.yaml | wc -l) -ne 0 ]; then
202+
echo ""
203+
echo "::error::YAML file is not properly formatted. Run the following command to fix:"
204+
echo ""
205+
echo " cd projects/rocprofiler-sdk && python source/scripts/format-deps.py --counter-defs"
206+
echo ""
207+
git diff -- source/share/rocprofiler-sdk/counter_defs.yaml
208+
exit 1
209+
fi

projects/rocprofiler-sdk/source/scripts/format-deps.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@
2424

2525

2626
import argparse
27+
import io
2728
import os
2829
import sys
30+
from pathlib import Path
31+
32+
from ruamel.yaml import YAML
2933

3034

3135
class FormatSource(argparse.Action):
@@ -64,6 +68,23 @@ def __call__(self, parser, namespace, values, option_string=None):
6468
exit(0)
6569

6670

71+
class FormatYAML(argparse.Action):
72+
def __call__(self, parser, namespace, values, option_string=None):
73+
yaml = YAML()
74+
yaml.preserve_quotes = True
75+
yaml.width = 120
76+
yaml.indent(mapping=2, sequence=4, offset=2)
77+
counter_defs = (
78+
Path(os.path.dirname(__file__))
79+
/ "../../source/share/rocprofiler-sdk/counter_defs.yaml"
80+
).resolve()
81+
data = yaml.load(counter_defs.read_text())
82+
stream = io.StringIO()
83+
yaml.dump(data, stream)
84+
counter_defs.write_text(stream.getvalue())
85+
exit(0)
86+
87+
6788
class FormatAll(argparse.Action):
6889
def __call__(self, parser, namespace, values, option_string=None):
6990
os.system(
@@ -87,6 +108,7 @@ def __call__(self, parser, namespace, values, option_string=None):
87108
+ "/../../external/*\" | egrep 'CMakeLists.txt|\.cmake$')"
88109
)
89110
os.system("black " + os.path.dirname(__file__) + "/../..")
111+
FormatYAML.__call__(FormatYAML, parser, namespace, values, option_string)
90112
exit(0)
91113

92114

@@ -118,6 +140,9 @@ def __call__(self, parser, namespace, values, option_string=None):
118140
"-p", "--python", nargs=0, help="format python files", action=FormatPython
119141
)
120142
parser.add_argument(
121-
"-a", "--all", nargs=0, help="format cmake, source and python files", action=FormatAll
143+
"-cd", "--counter-defs", nargs=0, help="format counter_defs.yaml", action=FormatYAML
144+
)
145+
parser.add_argument(
146+
"-a", "--all", nargs=0, help="format cmake, source, python, and yaml files", action=FormatAll
122147
)
123148
parser.parse_args()

0 commit comments

Comments
 (0)