forked from docs/doc-exports
110 lines
3.5 KiB
YAML
110 lines
3.5 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
|
|
# fetch-depth: ${{ github.event_name == 'pull_request' && 2 || 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"
|
|
# >> $GITHUB_OUTPUT
|
|
- 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: Get changed files
|
|
# id: changed-files
|
|
# run: |
|
|
# if ${{ github.event_name == 'pull_request' }}; then
|
|
# echo "changed_files=$(git diff --name-only -r HEAD^1 HEAD | xargs)" >> $GITHUB_OUTPUT
|
|
# else
|
|
# echo "changed_files=$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }} | xargs)" >> $GITHUB_OUTPUT
|
|
# fi
|
|
- 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
|
|
run: |
|
|
set -e
|
|
|
|
# BASE_SHA="${{ gitea.event.pull_request.base.sha }}"
|
|
|
|
# echo "Base SHA: $BASE_SHA"
|
|
|
|
# # Fetch base branch so git diff works in PRs
|
|
# git fetch origin "$BASE_SHA"
|
|
# # git fetch origin "${{ gitea.base_ref }}"
|
|
|
|
# # Get changed YAML files
|
|
# files=$(git diff --name-only "$BASE_SHA"...HEAD \
|
|
# | grep -E '\.(yml|yaml)$' || true)
|
|
|
|
files="${{ steps.changed-files.outputs.changed_files }}"
|
|
if [ -z "$files" ]; then
|
|
echo "No YAML files changed"
|
|
exit 0
|
|
fi
|
|
|
|
echo "Linting changed files:"
|
|
echo "$files"
|
|
|
|
# for file in ${{ steps.changed-files.outputs.changed_files }}; do
|
|
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
|