-
Notifications
You must be signed in to change notification settings - Fork 0
133 lines (114 loc) · 4.13 KB
/
validate-gh-workflows.yaml
File metadata and controls
133 lines (114 loc) · 4.13 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
name: Validate GitHub Workflows
on:
workflow_call:
inputs:
auto_doc:
description: If auto-doc should be run.
type: boolean
required: false
default: false
auto_doc_script:
description: The script to run auto-doc.
type: string
required: false
markdownlint:
description: If markdownlint should be run.
type: boolean
required: false
default: false
shellcheck:
description: If shellcheck should be run.
type: boolean
required: false
default: false
yamlfmt:
description: If yamlfmt should be run.
type: boolean
required: false
default: false
jobs:
validate:
name: Validate
runs-on: ubuntu-latest
permissions:
contents: read
defaults:
run:
shell: bash
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
- name: Install actionlint
uses: action-stars/install-tool-from-github-release@1fa61c3bea52eca3bcdb1f5c961a3b113fe7fa54 # v0.2.6
with:
github_token: ${{ github.token }}
owner: rhysd
repository: actionlint
check_command: actionlint -version
version: latest
- name: Run actionlint
run: actionlint -shellcheck=shellcheck
- name: Install auto-doc
uses: action-stars/install-tool-from-github-release@1fa61c3bea52eca3bcdb1f5c961a3b113fe7fa54 # v0.2.6
if: inputs.auto_doc
with:
github_token: ${{ github.token }}
owner: tj-actions
repository: auto-doc
arch_amd64: x86_64
os_linux: Linux
check_command: auto-doc --help
version: latest
- name: Run auto-doc check
if: inputs.auto_doc
run: |
set -euo pipefail
auto_doc_script="${{ inputs.auto_doc_script }}"
if [[ -n "${auto_doc_script}" ]]; then
${auto_doc_script}
else
find ./.github/workflows -maxdepth 1 -name '*.yaml' ! -name '_*' -print0 | while read -r -d $'\0' file; do
name="$(basename "${file}" .yaml)"
tmp_readme="$(mktemp)"
printf '## Inputs\n## Outputs' >"${tmp_readme}"
auto-doc --colMaxWords 100 --repository ${{ github.repository }} --reusable --reusableOutputColumns "Output" --reusableOutputColumns "Description" --filename "${file}" --output "${tmp_readme}"
sed -i 's/## /### /g' "${tmp_readme}"
sed -i 's/||/\\|\\|/g' "${tmp_readme}"
sed -i 's/"\\|"/\\|/g' "${tmp_readme}"
sed -i -e "/MERGE:START:${name}/,/MERGE:END:${name}/c\<!-- MERGE:START:${name} - Do not remove or modify this section -->\n\n<!-- MERGE:END:${name} - Do not remove or modify this section -->" ./README.md
sed -i "/MERGE:START:${name}/r ${tmp_readme}" ./README.md
rm -f "${tmp_readme}"
done
fi
if [[ -n "$(git status --porcelain --untracked-files=no)" ]]
then
echo "Documentation not up to date; please run auto-doc and commit changes!" >&2
exit 1
fi
- name: Install yamlfmt
uses: action-stars/install-tool-from-github-release@1fa61c3bea52eca3bcdb1f5c961a3b113fe7fa54 # v0.2.6
if: inputs.yamlfmt
with:
github_token: ${{ github.token }}
owner: google
repository: yamlfmt
arch_amd64: x86_64
os_linux: Linux
check_command: yamlfmt -version
version: latest
- name: Run yamlfmt check
if: inputs.yamlfmt
run: |
set -euo pipefail
yamlfmt -lint .
- name: Run shellcheck
if: inputs.shellcheck
run: |
set -euo pipefail
# shellcheck disable=SC2038
find . -type f -name "*.sh" | xargs --no-run-if-empty -n1 shellcheck
- name: Run markdownlint check
uses: DavidAnson/markdownlint-cli2-action@07035fd053f7be764496c0f8d8f9f41f98305101 # v22.0.0
if: inputs.markdownlint