forked from docs/doc-exports
Reviewed-by: Gode, Sebastian <sebastian.gode@t-systems.com> Co-authored-by: Hasko, Vladimir <vladimir.hasko@t-systems.com> Co-committed-by: Hasko, Vladimir <vladimir.hasko@t-systems.com>
124 lines
3.4 KiB
YAML
124 lines
3.4 KiB
YAML
# .gitea/workflows/yaml-lint.yml
|
|
name: YAML Lint
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
pull_request:
|
|
branches:
|
|
- main
|
|
paths:
|
|
- '.gitea/workflows/yaml-lint.yml'
|
|
- 'docs/*/openapi/*.yaml'
|
|
- 'docs/*/openapi/*.yml'
|
|
|
|
jobs:
|
|
yaml-lint:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Dump Gitea env
|
|
run: |
|
|
env | sort | grep GITEA
|
|
|
|
- name: Get base branch name
|
|
id: base
|
|
run: |
|
|
base_ref=$(jq -r '.pull_request.base.ref' "$GITEA_PATH")
|
|
echo "base_ref=$base_ref"
|
|
echo "${{ gitea.base_ref }}"
|
|
BASE_SHA="${{ gitea.event.pull_request.base.sha }}"
|
|
echo "Base SHA: $BASE_SHA"
|
|
|
|
- name: Get changed files other method
|
|
id: changed-files
|
|
run: |
|
|
BASE_SHA="${{ gitea.event.pull_request.base.sha }}"
|
|
echo "Base SHA: $BASE_SHA"
|
|
git fetch origin $BASE_SHA
|
|
echo "changed_files=$(git diff --name-only ${BASE_SHA}...HEAD | grep -E '\.(yml|yaml)$' | xargs)" >> $GITHUB_OUTPUT
|
|
|
|
- name: List changed files
|
|
run: |
|
|
for file in ${{ steps.changed-files.outputs.changed_files }}; do
|
|
echo "$file was changed"
|
|
done
|
|
|
|
- name: Check presence of non-unicode characters
|
|
continue-on-error: true
|
|
run: |
|
|
for file in ${{ steps.changed-files.outputs.changed_files }}; do
|
|
if LC_ALL=C grep --color='auto' -P -n "[^\x00-\x7F]" $file &>/dev/null; then
|
|
echo "$file contains non-unicode characters!"
|
|
LC_ALL=C grep --color='auto' -P -n "[^\x00-\x7F]" $file
|
|
failed_job=true
|
|
fi
|
|
done
|
|
if [ "$failed_job" = true ] ; then
|
|
exit 1
|
|
fi
|
|
|
|
- name: Install yamllint
|
|
run: |
|
|
sudo apt-get update
|
|
sudo apt-get install -y yamllint
|
|
|
|
- name: Run yamllint on changed YAML files
|
|
continue-on-error: true
|
|
run: |
|
|
set -e
|
|
|
|
files="${{ steps.changed-files.outputs.changed_files }}"
|
|
if [ -z "$files" ]; then
|
|
echo "No YAML files changed"
|
|
exit 0
|
|
fi
|
|
|
|
echo "Linting changed files:"
|
|
printf '%s\n' $files
|
|
|
|
for file in $files; do
|
|
echo "$file is being checked for yamllint issues."
|
|
yamllint -f parsable $file || \
|
|
{ failed_check=true ; echo "$file: detected yamllint errors!"; }
|
|
done
|
|
if [ "$failed_check" = true ]; then
|
|
exit 1
|
|
fi
|
|
|
|
- name: Setup Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: 20
|
|
|
|
- name: Install Spectral
|
|
run: npm install -g @stoplight/spectral-cli
|
|
|
|
- name: Run Spectral
|
|
run: |
|
|
set -e
|
|
|
|
files="${{ steps.changed-files.outputs.changed_files }}"
|
|
if [ -z "$files" ]; then
|
|
echo "No YAML files changed"
|
|
exit 0
|
|
fi
|
|
|
|
echo "Spectral check on changed files:"
|
|
printf '%s\n' $files
|
|
|
|
for file in $files; do
|
|
echo "$file is being checked for yamllint issues."
|
|
spectral lint $file --ruleset .spectral.yaml || \
|
|
{ failed_check=true ; echo "$file: detected spectral errors!"; }
|
|
done
|
|
if [ "$failed_check" = true ]; then
|
|
exit 1
|
|
fi
|