-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathaction.yml
89 lines (78 loc) · 3.13 KB
/
action.yml
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
name: Rhysd actionlint
description: Check your workflows for common errors, like not declaring outputs before using them, bash script errors, and more!
branding:
icon: tag
color: gray-dark
inputs:
fail-on-errors:
description: "Fail the action if errors are found"
required: false
default: "true"
shellcheck_opts:
description: "Custom SHELLCHECK_OPTS"
required: false
default: ""
outputs:
results-file:
description: "Path to the json results of the linter"
value: ${{ steps.run.outputs.resultsfile }}
runs:
using: composite
steps:
- name: Get current rhysd/actionlint version
shell: bash
id: getversion
run: |
# get actionlintversion from the settings.json file
actionLintVersion=$(jq -r '.actionlintversion' $GITHUB_ACTION_PATH/settings.json)
actionlintversiontag=$(jq -r '.actionlintversiontag' $GITHUB_ACTION_PATH/settings.json)
echo "actionLintVersion=$actionLintVersion">>$GITHUB_OUTPUT
echo "Found the version of rhysd/actionlint to use [$actionlintversiontag], with SHA [$actionLintVersion]"
- name: Docker run rhysd/actionlint
shell: bash
id: run
env:
FAILONERRORS: ${{ inputs.fail-on-errors }}
SHELLCHECK_OPTS: ${{ inputs.shellcheck_opts }}
run: |
# execute rhysd/actionlint as a docker container
# disable pipefail -e -o that is set on the shell script from the runner to prevent exiting when the docker run command fails
set +e +o pipefail;
# matcher needed to annotate the PR with comments
echo "::add-matcher::$GITHUB_ACTION_PATH/actionlint-matcher.json"
version=${{ steps.getversion.outputs.actionLintVersion }}
actionLintContainer=$version
# check if version has a value
if [[ -z "$version" ]]; then
echo "ActionLint version to use is empty, cannot continue"
exit 1
fi
# run again to get a json result
result=$(docker run -v $GITHUB_WORKSPACE:/repo --workdir /repo -e SHELLCHECK_OPTS="${SHELLCHECK_OPTS}" $actionLintContainer -color -format "{{json .}}")
status=$?
if jq -e . >/dev/null 2>&1 <<<"$result"; then
echo "Parsed JSON result successfully"
else
echo "Failed to parse JSON, or got false/null"
if [[ $result -ne 'no project was found in any parent directories of ".". check workflows directory is put correctly in your Git repository' ]]; then
echo "Showing the resulting messages:"
echo $result
echo "-------------------------------"
fi
fi
echo $result>"actionlint-errors.json"
echo "resultsfile=actionlint-errors.json">>$GITHUB_OUTPUT
if [[ $status == 0 ]];
then
echo "Actionlint had no errors"
else
echo "Actionlint found errors"
if [[ $FAILONERRORS == "true" ]]; then
echo "Running the docker container directly to show the errors"
docker run -v $GITHUB_WORKSPACE:/repo --workdir /repo -e SHELLCHECK_OPTS="${SHELLCHECK_OPTS}" $actionLintContainer -color
fi
fi
if [[ $FAILONERRORS == "true" ]];
then
exit $status
fi