Skip to content

Commit 8c5aa21

Browse files
committed
pre-commit: ensure regressionfiles.yaml is sorted
1 parent 16fb62f commit 8c5aa21

5 files changed

Lines changed: 77 additions & 26 deletions

File tree

.github/workflows/ci.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
name: ci
3+
4+
# yamllint disable-line rule:truthy
5+
on:
6+
push:
7+
pull_request:
8+
9+
concurrency:
10+
group: ci-${{github.ref}}-${{github.event.pull_request.number || github.run_number}}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
prechecks:
15+
uses: ./.github/workflows/pre-commit.yml
16+
all-prechecks:
17+
needs: [prechecks]
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Success
21+
run: "true"

.github/workflows/pre-commit.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
name: pre-commit
3+
4+
# yamllint disable-line rule:truthy
5+
on:
6+
workflow_call:
7+
8+
concurrency:
9+
group: style-${{github.ref}}-${{github.event.pull_request.number || github.run_number}}
10+
cancel-in-progress: true
11+
12+
jobs:
13+
pre-commit:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
- uses: actions/setup-python@v5
18+
- uses: pre-commit/action@v3.0.1
19+
- run: |
20+
python -m pip install 'ruamel.yaml'
21+
python sort_regressionfiles_yaml.py

.pre-commit-config.yaml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,3 @@ repos:
99
rev: "v5.0.0"
1010
hooks:
1111
- id: check-yaml
12-
- repo: local
13-
hooks:
14-
- id: sort-regressionfiles-yaml
15-
name: Sort regressionfiles.yaml
16-
entry: ./sort_regressionfiles_yaml.sh
17-
language: script
18-
files: ^regressionfiles\.yaml$

sort_regressionfiles_yaml.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env python
2+
3+
4+
if __name__ == "__main__":
5+
import sys
6+
import subprocess as sp
7+
8+
from ruamel.yaml import YAML
9+
10+
yaml = YAML(pure=True, typ="safe")
11+
yaml.default_flow_style = False
12+
yaml.indent(mapping=2, sequence=4, offset=2)
13+
14+
with open("regressionfiles.yaml", encoding="utf-8") as handle:
15+
contents = yaml.load(handle)
16+
17+
contents_sorted = {"regressions": sorted(contents["regressions"], key=lambda x: x["loc_entry"])}
18+
19+
with open("regressionfiles_nocomments.yaml", "w", encoding="utf-8") as handle:
20+
yaml.dump(contents, handle)
21+
22+
with open("regressionfiles_sorted.yaml", "w", encoding="utf-8") as handle:
23+
yaml.dump(contents_sorted, handle)
24+
25+
result = sp.run(
26+
[
27+
"git",
28+
"diff",
29+
"--no-index",
30+
"regressionfiles_nocomments.yaml",
31+
"regressionfiles_sorted.yaml",
32+
]
33+
)
34+
if result.returncode:
35+
sys.exit(result.returncode)

sort_regressionfiles_yaml.sh

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)