Skip to content

Commit

Permalink
Run yamllint on files which is chnaged in PR only
Browse files Browse the repository at this point in the history
Signed-off-by: hansinikarunarathne <[email protected]>
  • Loading branch information
hansinikarunarathne committed Jul 1, 2024
1 parent 1e5c367 commit f497203
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
21 changes: 7 additions & 14 deletions .github/workflows/yaml_formatter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,22 @@ jobs:
line-length:
max: 400
"
# - name: Lint YAML files
# run: yamllint .
- name: Fetch main branch
- name: Fetch master branch
run: git fetch origin master

- name: Set up changed files
run: |
git diff --name-only origin/main...HEAD | grep -E '^common/.*\.ya?ml$|^example/.*\.ya?ml$' > changed_files.txt || true
git diff --name-only origin/main...HEAD | grep -E '^common/.*\.ya?ml$|^example/.*\.ya?ml$' > changed_files_in_PR.txt || true
- name: Display changed files
run: cat changed_files.txt
run: cat changed_files_in_PR.txt

- name: Run yamllint on changed files
run: |
if [ -s changed_files.txt ]; then
while IFS= read -r file; do
echo "Running yamllint on $file"
yamllint "$file"
done < changed_files.txt
else
echo "No YAML files changed."
fi
chmod +x ./run_yamllint.sh
./run_yamllint.sh
shell: bash



10 changes: 10 additions & 0 deletions run_yamllint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

if [ -s changed_files_in_PR.txt ]; then
while IFS= read -r file; do
echo "Running yamllint on $file"
yamllint "$file"
done < changed_files_in_PR.txt
else
echo "No YAML files changed in this PR."
fi

0 comments on commit f497203

Please sign in to comment.