Skip to content

Commit daa42cd

Browse files
ci: introduce yamllint check for controls and profiles
This workflow will detect files changed by the PR and in case controls or profiles files are included in the list, it will execute yamllint using the .yamllint configuration file located in .github directory. Signed-off-by: Marcus Burghardt <maburgha@redhat.com>
1 parent c37488c commit daa42cd

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

.github/.yamllint

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
extends: default
3+
4+
# https://yamllint.readthedocs.io/en/stable/rules.html
5+
rules:
6+
comments: disable
7+
comments-indentation: disable
8+
document-start: disable
9+
empty-lines:
10+
level: warning
11+
indentation:
12+
spaces: consistent
13+
line-length: disable

.github/workflows/ci_lint.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: CI Lint
2+
on:
3+
pull_request:
4+
branches: [master, 'stabilization*']
5+
permissions:
6+
contents: read
7+
jobs:
8+
yamllint:
9+
name: Run yamllint on changed controls and profiles
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Install Git
13+
run: sudo apt-get update && sudo apt-get install -y git
14+
15+
- name: Checkout CaC repo
16+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
17+
with:
18+
repository: ${{ github.repository }}
19+
fetch-depth: 0
20+
21+
- name: Detect files changed by PR
22+
id: changed_files
23+
run: |
24+
repo=${{ github.repository }}
25+
pr_number=${{ github.event.pull_request.number }}
26+
# Fetch all pages of the files for the pull request
27+
url="repos/$repo/pulls/$pr_number/files"
28+
response=$(gh api "$url" --paginate)
29+
echo "$response" | jq -r '.[].filename' > filenames.txt
30+
cat filenames.txt
31+
32+
if grep "controls/" filenames.txt; then
33+
echo "CONTROLS_CHANGES=true" >> $GITHUB_ENV
34+
else
35+
echo "CONTROLS_CHANGES=false" >> $GITHUB_ENV
36+
fi
37+
if grep "\.profile" filenames.txt; then
38+
echo "PROFILES_CHANGES=true" >> $GITHUB_ENV
39+
else
40+
echo "PROFILES_CHANGES=false" >> $GITHUB_ENV
41+
fi
42+
env:
43+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44+
45+
- name: Install yamllint
46+
if : ${{ env.CONTROLS_CHANGES == 'true' || env.PROFILES_CHANGES == 'true' }}
47+
run: pip install yamllint
48+
49+
- name: Run yamllint in control files modified by PR
50+
if: ${{ env.CONTROLS_CHANGES == 'true' }}
51+
run: |
52+
for control_file in $(cat filenames.txt | grep "controls/"); do
53+
echo "Running yamllint on $control_file..."
54+
yamllint --no-warnings "$control_file"
55+
done
56+
57+
- name: Run yamllint in profile files modified by PR
58+
if: ${{ env.PROFILES_CHANGES == 'true' }}
59+
run: |
60+
for profile_file in $(cat filenames.txt | grep "\.profile"); do
61+
echo "Running yamllint on $profile_file..."
62+
yamllint --no-warnings "$profile_file"
63+
done

0 commit comments

Comments
 (0)