-
Notifications
You must be signed in to change notification settings - Fork 1
93 lines (86 loc) · 3.22 KB
/
lint-yaml.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
name: Auto Yaml Lint
on:
push:
branches:
- main
paths:
- '**.yml'
- '**.yaml'
pull_request:
branches:
- main
paths:
- '**.yml'
- '**.yaml'
jobs:
linkyaml:
runs-on: ubuntu-latest
name: Yaml Lint
steps:
- name: Checkout
if: ${{ github.event_name == 'workflow_dispatch' }}
uses: actions/checkout@v3
with:
ref: ${{ github.event.inputs.tag }}
- name: Checkout
if: ${{ github.event_name != 'workflow_dispatch' }}
uses: actions/checkout@v3
- name: github yaml format yq
env:
GITHUB_TOKEN: ${{ secrets.WELAN_PAT}}
JSON: ${{ toJSON(github) }}
run: |
echo "=================== install yq"
wget https://github.com/mikefarah/yq/releases/download/v4.30.7/yq_linux_amd64
chmod +x yq_linux_amd64
echo "=================== get pr number"
PR_NUMBER=""
if ${{ github.event_name == 'pull_request' }}; then
echo "trigger by pull_request"
PR_NUMBER=${{ github.event.number }}
[ -n "${PR_NUMBER}" ] || { echo "no PR number, ignore" ; exit 0 ; }
elif ${{ github.event_name == 'push' }}; then
echo "trigger by push"
echo "${JSON}"
grep -Eio "Merge pull request #[0-9]+ " <<< "${JSON}" || true
PR_NUMBER=` grep -Eio "Merge pull request #[0-9]+ " <<< "${JSON}" | grep -Eo "[0-9]+" | uniq ` || true
[ -n "${PR_NUMBER}" ] || { echo "no PR number, ignore" ; exit 0 ; }
else
exit 1
fi
echo "============= get changed chart========"
URL="https://api.github.com/repos/${{ github.repository }}/pulls/${PR_NUMBER}/files"
files_changed_data=$(curl -s --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' -X GET -G "$URL")
echo "files_changed_data: $files_changed_data"
files_changed="$(echo $files_changed_data | jq -r '.[] | .filename')"
echo "files_changed: $files_changed"
echo "============= checking yaml file========"
for FILEPATH in $files_changed ; do
if grep -E "\.github/.*\.yaml" <<< "$FILEPATH" &>/dev/null || grep -E "\.github/.*\.yaml" <<< "$FILEPATH" &>/dev/null ; then
echo "------------ checking ${FILEPATH} "
if ! ./yq_linux_amd64 ${FILEPATH} &>/dev/null ; then
./yq_linux_amd64 ${FILEPATH} || true
echo "!!! error, $FILEPATH is not yaml format"
exit 1
fi
fi
done
echo "--- all done"
- name: yaml-lint
id: yaml-lint
continue-on-error: true
uses: ibiqlik/action-yamllint@v3
with:
file_or_dir: '.'
config_file: '.github/yamllint-conf.yml'
- name: Upload artifact digests
if: ${{ steps.yaml-lint.outcome == 'failure' }}
uses: actions/[email protected]
with:
name: log
path: ${{ steps.yaml-lint.outputs.logfile }}
retention-days: 1
- name: Result
if: ${{ steps.yaml-lint.outcome == 'failure' }}
run: |
exit 1