Skip to content

Commit c3974b8

Browse files
committed
update with prod
1 parent 6308c36 commit c3974b8

3 files changed

Lines changed: 88 additions & 1 deletion

File tree

.github/scripts/run_validation.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ fi
3333
echo "Rule file: $RULE_YML"
3434

3535
# ---------------------------------------------------------------------------
36-
# Initialise report
36+
# Initialize report
3737
# ---------------------------------------------------------------------------
3838
{
3939
echo "# Rule Validation Report"
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: Validate YAML Formatting
2+
on:
3+
pull_request:
4+
paths:
5+
- 'Unpublished/**/rule.yml'
6+
- 'Published/**/rule.yml'
7+
types: [opened, synchronize, reopened]
8+
workflow_dispatch: {}
9+
jobs:
10+
check-yaml-format:
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
14+
pull-requests: write
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
- name: Set up Python 3.12
21+
uses: actions/setup-python@v5
22+
with:
23+
python-version: '3.12'
24+
- name: Install pyyaml
25+
run: pip install pyyaml
26+
- name: Detect changed rule.yml files
27+
id: changed-files
28+
run: |
29+
if [ "${{ github.event_name }}" = "pull_request" ]; then
30+
FILES=$(git diff --name-only origin/${{ github.base_ref }}...HEAD \
31+
| grep -E '^(Published|Unpublished)/.*/rule\.yml$' || true)
32+
else
33+
FILES=$(git diff --name-only HEAD~1 HEAD \
34+
| grep -E '^(Published|Unpublished)/.*/rule\.yml$' || true)
35+
fi
36+
if [ -z "$FILES" ]; then
37+
echo "No rule.yml files changed."
38+
echo "has_files=false" >> $GITHUB_OUTPUT
39+
else
40+
echo "has_files=true" >> $GITHUB_OUTPUT
41+
echo "$FILES" > /tmp/changed_rule_files.txt
42+
fi
43+
- name: Check YAML sorting and formatting
44+
id: format-check
45+
if: steps.changed-files.outputs.has_files == 'true'
46+
run: |
47+
FILES=$(cat /tmp/changed_rule_files.txt | tr '\n' ' ')
48+
python scripts/sort_yaml.py --check $FILES
49+
continue-on-error: true
50+
- name: Post format check result to PR
51+
if: always() && github.event_name == 'pull_request' && steps.changed-files.outputs.has_files == 'true'
52+
uses: actions/github-script@v7
53+
with:
54+
github-token: ${{ secrets.GITHUB_TOKEN }}
55+
script: |
56+
const outcome = '${{ steps.format-check.outcome }}';
57+
const marker = '<!-- yaml-format-check -->';
58+
let body = marker + '\n';
59+
if (outcome === 'success') {
60+
body += '## \u2705 YAML Format Check Passed\n\nAll changed `rule.yml` files are correctly sorted and formatted.';
61+
} else {
62+
body += '## \u274c YAML Format Check Failed\n\n';
63+
body += 'One or more `rule.yml` files are not correctly sorted/formatted alphabetically by key.\n\n';
64+
body += 'Run the following command locally to fix them:\n\n```bash\npython scripts/sort_yaml.py\n```\n\nThen commit and push.';
65+
}
66+
const { data: comments } = await github.rest.issues.listComments({
67+
owner: context.repo.owner, repo: context.repo.repo,
68+
issue_number: context.issue.number,
69+
});
70+
const existing = comments.find(c => c.user.type === 'Bot' && c.body.includes(marker));
71+
if (existing) {
72+
await github.rest.issues.updateComment({
73+
owner: context.repo.owner, repo: context.repo.repo,
74+
comment_id: existing.id, body,
75+
});
76+
} else {
77+
await github.rest.issues.createComment({
78+
owner: context.repo.owner, repo: context.repo.repo,
79+
issue_number: context.issue.number, body,
80+
});
81+
}
82+
- name: Fail if format check failed
83+
if: steps.format-check.outcome == 'failure'
84+
run: |
85+
echo "YAML format check failed. Run 'python scripts/sort_yaml.py' to fix."
86+
exit 1

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ Unpublished/
223223
MAC: `./run/bash_run.sh`
224224
- If you haven't run the setup script before, don't worry; it will run automatically when you execute this command.
225225
- You will be prompted to select the rule you wish to run, as well as the test case(s).
226+
- You will also be prompted with what logs you would like to see and if you want them captured in a txt file for each test case (these are useful attachments to issues created for CORE Rules Engine Bug Reports)
226227

227228
**Verify Results.**
228229

0 commit comments

Comments
 (0)