Skip to content

Proper message display when no Yaml files chnaged and styled in the PR #36

Proper message display when no Yaml files chnaged and styled in the PR

Proper message display when no Yaml files chnaged and styled in the PR #36

name: Proper Formatting on YAML files
on: [push, pull_request]
jobs:
format_YAML_files:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install yamllint
run: pip install yamllint
- name: YAML Formatting Guidelines
run: |
echo "### YAML Formatting Guidelines ###
If there is a formatting error in your YAML file, you will see errors like the one below:
'Error: 6:4 [indentation] wrong indentation: expected 2 but found 3'
To fix these errors, refer to the YAML formatting rules at:
https://yamllint.readthedocs.io/en/stable/rules.html#
Search for the keyword inside the brackets [] in the error message. In this example, it's 'indentation'.
Note: Some rules have been customized in the '.yamllint.yaml' file. Below is the content of that file:
extends: default
rules:
document-start:
present: false
document-end:
present: false
indentation:
indent-sequences: false
line-length:
max: 400
"
- name: Fetch master branch
run: git fetch origin master
- name: Set up changed files
run: |
git diff --name-only origin/master...HEAD | grep -E '^common/.*\.ya?ml$|^example/.*\.ya?ml$' > changed_files_in_PR.txt || true
if [ ! -s changed_files_in_PR.txt ]; then
echo "No YAML files have changed in this PR." > changed_files_in_PR.txt
fi
- name: Display changed files
run: cat changed_files_in_PR.txt
- name: Run yamllint on changed files
run: |
if [ -s changed_files_in_PR.txt ]; then
cat changed_files_in_PR.txt | xargs yamllint
if [ $? -eq 0 ]; then
echo "No YAML style errors found in the changed files."
else
echo "YAML style errors were found."
fi
else
echo "No YAML files have changed in this PR."
fi
shell: bash