Skip to content

Commit 8e6c242

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 8e6c242

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

.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: Yaml Lint on Changed Controls and Profiles Files
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 Repository
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 "$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 "$profile_file"
63+
done

0 commit comments

Comments
 (0)