-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathstep.sh
executable file
·86 lines (68 loc) · 1.97 KB
/
step.sh
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
#!/bin/bash
set -o pipefail
if [ -z "${linting_path}" ] ; then
echo " [!] Missing required input: linting_path"
exit 1
fi
FLAGS=''
if [ -s "${lint_config_file}" ] ; then
FLAGS=$FLAGS' --config '"${lint_config_file}"
fi
if [ "${strict}" = "yes" ] ; then
echo "Running strict mode"
FLAGS=$FLAGS' --strict'
fi
if [ "${quiet}" = "yes" ] ; then
echo "Running quiet mode"
FLAGS=$FLAGS' --quiet'
fi
cd "${linting_path}"
filename="swiftlint_report"
case $reporter in
xcode|emoji)
filename="${filename}.txt"
;;
markdown)
filename="${filename}.md"
;;
csv|html)
filename="${filename}.${reporter}"
;;
checkstyle|junit)
filename="${filename}.xml"
;;
json|sonarqube)
filename="${filename}.json"
;;
esac
report_path="${BITRISE_DEPLOY_DIR}/${filename}"
case $lint_range in
"changed")
echo "Linting diff only"
files=$(git diff HEAD^ --name-only --diff-filter=d -- '*.swift')
echo $files
for swift_file in $(git diff HEAD^ --name-only --diff-filter=d -- '*.swift')
do
swiftlint_output+=$"$(swiftlint lint --path "$swift_file" --reporter ${reporter} ${FLAGS})"
lint_code=$?
if [[ lint_code -ne 0 ]]; then
swiftlint_exit_code=${lint_code}
fi
done
;;
"all")
echo "Linting all files"
swiftlint_output="$(swiftlint lint --reporter ${reporter} ${FLAGS})"
swiftlint_exit_code=$?
;;
esac
# This will set the `swiftlint_output` in `SWIFTLINT_REPORT` env variable.
# so it can be used to send in Slack etc.
envman add --key "SWIFTLINT_REPORT" --value "${swiftlint_output}"
echo "Saved swiftlint output in SWIFTLINT_REPORT"
# This will print the `swiftlint_output` into a file and set the envvariable
# so it can be used in other tasks
echo "${swiftlint_output}" > $report_path
envman add --key "SWIFTLINT_REPORT_PATH" --value "${report_path}"
echo "Saved swiftlint output in file at path SWIFTLINT_REPORT_PATH"
exit ${swiftlint_exit_code}