Skip to content

Commit 01e224d

Browse files
[PATCH] Refactor for more consistant improvements.
Changes in file .github/workflows/makefile-lint.yml: - improve YAML_ARGS validation logic Changes in file .github/workflows/markdown-lint.yml: - improve error message construction
1 parent 4d6c140 commit 01e224d

File tree

2 files changed

+40
-26
lines changed

2 files changed

+40
-26
lines changed

.github/workflows/makefile-lint.yml

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,28 +38,34 @@ jobs:
3838
- name: Install Apt-Get Dependencies
3939
run: |
4040
sudo apt-get update || exit 1
41-
sudo apt-get install -y yamllint golang-go pandoc || exit 1
42-
ERR_MSG_STUB="Go installation failed."
43-
ERR_DETAILS="file=.github/workflows/makefile-lint.yml,line=25,endLine=30,title=FAILURE"
44-
ERR_MSG_LINE="::error ${ERR_DETAILS}::ERROR ${ERR_MSG_STUB}"
45-
go version || { printf "%s\n" "${ERR_MSG_LINE}"; exit 1; }
41+
sudo apt-get install -y yamllint golang-go pandoc || : # handle error with detail below
42+
print_error() {
43+
local msg="$1"
44+
local file_stub=".github/workflows/makefile-lint.yml"
45+
local line_start="$2"
46+
local line_end="$3"
47+
printf "::error file=%s,line=%s,endLine=%s,title=VALIDATION_ERROR::ERROR %s\n" \
48+
"${file_stub}" "${line_start}" "${line_end}" "${msg}"
49+
}
50+
go version || { print_error "Go installation failed." 40 41 ; exit 126; }
51+
yamllint --version || { print_error "Yamllint installation failed." 40 41 ; exit 126; }
52+
pandoc --version || { print_error "Pandoc installation failed." 40 41 ; exit 126; }
4653
- name: Lint Workflow YAML
4754
if: ${{ success() }}
4855
run: |
4956
YAML_ARGS="${{ vars.YAML_ARGS }}"
50-
case "${YAML_ARGS}" in
51-
*[!a-zA-Z0-9\ \-\.]*)
52-
ERR_MSG_STUB="Invalid YAML_ARGS: contains unauthorized characters"
53-
ERR_DETAILS="file=.github/workflows/makefile-lint.yml,line=35,endLine=41,"
54-
ERR_TITLE="title=VALIDATION_ERROR"
55-
printf "::error %s::ERROR %s\n" "${ERR_DETAILS}${ERR_TITLE}" "${ERR_MSG_STUB}"
57+
if [[ "${YAML_ARGS}" =~ ^*[!a-zA-Z0-9\ \-\.]*$ ]]; then
58+
ERR_MSG_STUB="Invalid YAML_ARGS: contains unauthorized characters!"
59+
ERR_LOC="file=.github/workflows/markdown-lint.yml,line=37,endLine=42,"
60+
printf "::error %s%s\n" "${ERR_LOC}" "title=VALIDATION_ERROR::ERROR ${ERR_MSG_STUB}"
5661
exit 1
57-
;;
58-
*)
59-
printf "Validating workflow with args: %s\n" "${YAML_ARGS}"
60-
yamllint ${YAML_ARGS} .github/workflows/makefile-lint.yml
61-
;;
62-
esac
62+
else
63+
printf "::notice file=.github/workflows/markdown-lint.yml,%s %s\n" \
64+
"line=36,endLine=47,title=Validation::Validating workflow with args:" \
65+
"${YAML_ARGS}"
66+
read -ra ARGS <<< "${YAML_ARGS}"
67+
yamllint "${ARGS[@]}" .github/workflows/markdown-lint.yml
68+
fi
6369
- name: Install checkmake
6470
if: ${{ success() }}
6571
env:

.github/workflows/markdown-lint.yml

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,18 @@ jobs:
2323
persist-credentials: false
2424
- name: Install Apt-Get Dependencies
2525
run: |
26-
sudo apt-get update
27-
sudo apt-get install -y yamllint npm
28-
ERR_MSG_STUB="yamllint installation failed."
29-
ERR_DETAILS="file=.github/workflows/markdown-lint.yml,line=26,endLine=31,title=FAILURE"
30-
ERR_MSG_LINE="::error ${ERR_DETAILS}::ERROR ${ERR_MSG_STUB}"
31-
yamllint --version || { printf "%s\n" "${ERR_MSG_LINE}"; exit 1; }
26+
sudo apt-get update || exit 1
27+
sudo apt-get install -y yamllint npm || : # handle error with detail below
28+
print_error() {
29+
local msg="$1"
30+
local file_stub=".github/workflows/markdown-lint.yml"
31+
local line_start="$2"
32+
local line_end="$3"
33+
printf "::error file=%s,line=%s,endLine=%s,title=VALIDATION_ERROR::ERROR %s\n" \
34+
"${file_stub}" "${line_start}" "${line_end}" "${msg}"
35+
}
36+
command -v npm >/dev/null || { print_error "npm installation failed." 26 27 ; exit 126; }
37+
yamllint --version || { print_error "Yamllint installation failed." 26 27 ; exit 126; }
3238
3339
- name: Lint Workflow YAML
3440
if: ${{ success() }}
@@ -41,7 +47,7 @@ jobs:
4147
exit 1
4248
else
4349
printf "::notice file=.github/workflows/markdown-lint.yml,%s %s\n" \
44-
"line=36,endLine=47,title=Validation::Validating workflow with args:" \
50+
"line=42,endLine=43,title=Validation::Validating workflow with args:" \
4551
"${YAML_ARGS}"
4652
read -ra ARGS <<< "${YAML_ARGS}"
4753
yamllint "${ARGS[@]}" .github/workflows/markdown-lint.yml
@@ -51,7 +57,7 @@ jobs:
5157
run: |
5258
# npm install
5359
ERR_MSG="NPM package installation failed"
54-
ERR_LOC_1="file=.github/workflows/markdown-lint.yml,line=56,endLine=56"
60+
ERR_LOC_1="file=.github/workflows/markdown-lint.yml,line=62,endLine=62"
5561
ERR_LOC_2="file=package.json,line=2,endLine=4"
5662
if ! NPM_ERROR=$(npm install 2>&1); then
5763
for LOC in "${ERR_LOC_1}" "${ERR_LOC_2}"; do
@@ -62,7 +68,9 @@ jobs:
6268
6369
- name: Lint YAML config for markdown
6470
run: |
65-
yamllint -f github --no-warnings .markdownlint.yaml
71+
YAML_ARGS="${{ vars.YAML_ARGS }}"
72+
read -ra ARGS <<< "${YAML_ARGS}"
73+
yamllint ${{ vars.YAML_ARGS }} .markdownlint.yaml
6674
6775
- name: Lint Markdown Files with YAML config
6876
if: ${{ !cancelled() }}

0 commit comments

Comments
 (0)