-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
yamllint.sh.j2
102 lines (83 loc) · 2.21 KB
/
yamllint.sh.j2
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
#!/usr/bin/env bash
# {{ ansible_managed }}
set -e -o pipefail
if [ -z "$1" ]
then
echo 'Arguments:'
echo ' 1: repository name'
echo ' 2: badge status only (optional)'
exit 1
fi
PATH_TEST='{{ tester.path.test }}/{{ test }}'
PATH_BADGE='{{ tester.path.web }}'
PATH_VENV='{{ tester.path.venv }}'
LABEL='YamlLint'
status='RUNNING'
GALAXY_NAMESPACE='ansibleguy'
EXIT_CODE_FAILED='{{ tester.rc.soft_fail }}'
exit_code=0
LOG_FILE="${PATH_LOG}/yamllint_${ROLE}.log"
declare -A BADGE_COLORS
BADGE_COLORS[UNKNOWN]='#{{ tester.colors.wait }}'
BADGE_COLORS[RUNNING]='#{{ tester.colors.run }}'
BADGE_COLORS[PASSED]='#{{ tester.colors.ok }}'
BADGE_COLORS[FAILED]='#{{ tester.colors.bad }}'
BADGE_COLORS[FAILED-ENVIRONMENT]='#{{ tester.colors.bad }}'
ROLE="$1"
function update_badge {
cd "$PATH_BADGE"
if [[ "$collection" == "1" ]]
then
KEY_BADGE="collection_${ROLE}"
else
KEY_BADGE="$ROLE"
fi
rm -f "${KEY_BADGE}.{{ test }}.svg"
anybadge --label="$LABEL" --value="${status} | $(date '+%Y-%m-%d %H:%M') GMT+2" --file="${KEY_BADGE}.{{ test }}" --color="${BADGE_COLORS[$status]}"
}
function update_logs {
journalctl -u "ansible-test-yamllint-${ROLE}.service" -n 1000 --no-pager --full | grep -Ev 'download|ansibleguy.|galaxy' > "$LOG_FILE"
}
function set_error {
status="$1"
exit_code="$EXIT_CODE_FAILED"
}
source "${PATH_VENV}/bin/activate"
collection=0
if echo "$ROLE" | grep -q 'collection'
then
ROLE=$(echo "$ROLE" | cut -d '_' -f2)
collection=1
PATH_TEST_FULL="${PATH_TEST}/collections/ansible_collections/${GALAXY_NAMESPACE}/${ROLE}"
else
PATH_TEST_FULL="${PATH_TEST}/${GALAXY_NAMESPACE}.${ROLE}"
fi
if [ -n "$2" ]
then
status="$2"
update_badge
rm -rf "$PATH_TEST_FULL"
exit 0
fi
update_badge
# preparations for tests
rm -rf "$PATH_TEST_FULL"
if [[ "$collection" == "1" ]]
then
ansible-galaxy collection install "git+https://github.com/${GALAXY_NAMESPACE}/collection_${ROLE}" -p "${PATH_TEST}/collections"
else
ansible-galaxy install --roles-path "$PATH_TEST" "${GALAXY_NAMESPACE}.${ROLE}"
fi
cd "$PATH_TEST_FULL"
set +e # soft-handling of failures
if ! yamllint .
then
set_error 'FAILED'
else
status='PASSED'
fi
update_logs
update_badge
cd /tmp
rm -rf "$PATH_TEST_FULL"
exit "$exit_code"