Skip to content

Commit c773ac5

Browse files
committed
[rocprofiler-sdk][CI] format config.yaml
1 parent 823c61c commit c773ac5

File tree

3 files changed

+66
-1
lines changed

3 files changed

+66
-1
lines changed

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11

22
name: rocprofiler-sdk Formatting
33

4+
permissions:
5+
contents: read
6+
47
on:
58
workflow_dispatch:
69
pull_request:
@@ -175,3 +178,35 @@ jobs:
175178
cat ${OUTFILE}
176179
exit 1
177180
fi
181+
182+
config_yaml:
183+
runs-on: ubuntu-22.04
184+
185+
steps:
186+
- uses: actions/checkout@v4
187+
with:
188+
sparse-checkout: projects/rocprofiler-sdk
189+
190+
- name: Set up Python
191+
uses: actions/setup-python@v5
192+
with:
193+
python-version: '3.10'
194+
195+
- name: Install dependencies
196+
run: |
197+
python -m pip install --upgrade pip
198+
python -m pip install ruamel.yaml
199+
200+
- name: Ensure config.yaml is formatted
201+
working-directory: projects/rocprofiler-sdk
202+
run: |
203+
python source/scripts/format-deps.py --counter-defs
204+
if [ $(git diff -- source/share/rocprofiler-sdk/config.yaml | wc -l) -ne 0 ]; then
205+
echo ""
206+
echo "::error::YAML file is not properly formatted. Run the following command to fix:"
207+
echo ""
208+
echo " cd projects/rocprofiler-sdk && python source/scripts/format-deps.py --counter-defs"
209+
echo ""
210+
git diff -- source/share/rocprofiler-sdk/config.yaml
211+
exit 1
212+
fi

projects/rocprofiler-sdk/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ pycobertura
1414
pytest
1515
pyyaml
1616
reportlab
17+
ruamel.yaml

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

Lines changed: 30 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+
config = (
78+
Path(os.path.dirname(__file__))
79+
/ "../../source/share/rocprofiler-sdk/config.yaml"
80+
).resolve()
81+
data = yaml.load(config.read_text())
82+
stream = io.StringIO()
83+
yaml.dump(data, stream)
84+
config.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,13 @@ 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+
"-cc", "--counter-config", nargs=0, help="format config.yaml", action=FormatYAML
144+
)
145+
parser.add_argument(
146+
"-a",
147+
"--all",
148+
nargs=0,
149+
help="format cmake, source, python, and yaml files",
150+
action=FormatAll,
122151
)
123152
parser.parse_args()

0 commit comments

Comments
 (0)