-
Notifications
You must be signed in to change notification settings - Fork 2
/
action.yaml
127 lines (113 loc) · 4.21 KB
/
action.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
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
name: 'Traefik Hub'
description: 'Static Analysis on Traefik Hub CRD'
branding:
icon: 'shield'
color: 'gray-dark'
inputs:
version:
description: 'Version of hub-static-analyzer to use. E.g. "v0.1.0". Default: "latest"'
required: false
default: 'latest'
path:
description: 'Path to the manifests within a Git repository'
required: false
default: "./"
exclude:
description: 'Exclude the matching manifests'
required: false
default: ''
# Lint options.
lint:
description: 'Lint manifests. . Default: "false"'
required: false
default: "false"
lint-output-file:
description: 'Filename to store lint output. File will be overwritten if it exists. Default: "traefik-hub-static-analyzer-lint.out"'
required: false
default: 'traefik-hub-static-analyzer-lint.out'
lint-format:
description: 'Format, one of: unix, json, checkstyle'
required: false
default: 'unix'
lint-disabled-rules:
description: 'Comma-separated list of Rules to disable'
required: false
default: ''
# Diff options.
diff:
description: 'Generate a diff report. Default: "false"'
required: false
default: "false"
diff-range:
description: 'Range of commits on which to run the diff. E.g. 12345d...12345b, HEAD~3'
required: false
diff-output-file:
description: 'Filename to store diff output. File will be overwritten if it exists. Default: "traefik-hub-static-analyzer-diff.out"'
required: false
default: 'traefik-hub-static-analyzer-diff.out'
runs:
using: "composite"
steps:
- name: download hub-static-analyzer
shell: bash
run: |
# Download hub-static-analyzer
set -u
if [ ${{ runner.arch }} = "ARM64" ]; then
RELEASE_ARCH="arm64"
elif [ ${{ runner.arch }} = "X64" ]; then
RELEASE_ARCH="amd64"
else
RELEASE_ARCH="amd64"
fi
if [ ${{ runner.os }} = "macOS" ]; then
RELEASE_OS="darwin"
elif [ ${{ runner.os }} = "Linux" ]; then
RELEASE_OS="linux"
else
RELEASE_OS="linux"
fi
PATTERN="static-analyzer-*-${RELEASE_OS}-${RELEASE_ARCH}*"
REPOSITORY='traefik/hub'
TARGET="hub-static-analyzer.tar.gz"
if [[ "${{ inputs.version }}" == "latest" ]]; then
gh release download --repo "${REPOSITORY}" --pattern "${PATTERN}" --output "${TARGET}" "static-analyzer-v1.3.0" > /dev/null
else
gh release download --repo "${REPOSITORY}" --pattern "${PATTERN}" --output "${TARGET}" "static-analyzer-${{ inputs.version }}" > /dev/null
fi
tar -xf "$TARGET" --strip-components 1
- name: run static analysis
shell: bash
run: |
# hub-static-analyzer
set -u
set +e
if [ "${{ inputs.lint }}" = "true" ]; then
rules="${{ inputs.lint-disabled-rules }}"
disabledRules=(${rules//,/ })
cliRules=""
for r in "${disabledRules[@]}"; do
cliRules+="--rule.${r}=false "
done
echo \$ hub-static-analyzer lint $cliRules --path "${{ inputs.path }}" --format "${{ inputs.lint-format }}" --exclude "${{ inputs.exclude }}"
(./hub-static-analyzer lint $cliRules --path "${{ inputs.path }}" --format "${{ inputs.lint-format }}" --exclude "${{ inputs.exclude }}" > "${{ inputs.lint-output-file }}")&
pids+=($!)
fi
if [ ${{ inputs.diff }} = "true" ]; then
echo \$ hub-static-analyzer diff --path "${{ inputs.path }}" --format "${{ inputs.lint-format }}" --exclude "${{ inputs.exclude }}"
(./hub-static-analyzer diff --path "${{ inputs.path }}" ${{ inputs.diff-range }} --exclude "${{ inputs.exclude }}" | tee "${{ inputs.diff-output-file }}")&
pids+=($!)
fi
for pid in ${pids[@]}; do
wait ${pid}
statuses+=($?)
done
[ -s ${{ inputs.lint-output-file }} ] || rm -f ${{ inputs.lint-output-file }}
[ -s ${{ inputs.diff-output-file }} ] || rm -f ${{ inputs.diff-output-file }}
# echo "Statuses ${statuses}"
for st in ${statuses[@]}; do
if [[ ${st} -ne 0 ]]; then
echo "Found errors in this PR"
exit 1
fi
done