-
Notifications
You must be signed in to change notification settings - Fork 0
199 lines (193 loc) · 9.25 KB
/
report-and-notify.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
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
name: Report and notify about testresults
on:
workflow_call:
inputs:
build-version:
required: false
type: string
description: 'Docker tag (from repository)'
default: 'latest'
fpsak:
required: false
type: string
description: "Resultat av kjøring av test suite (skipped|test-failure|logg-failure|success)"
default: 'skipped'
fptilbake:
required: false
type: string
description: "Fptilbake resultat tester"
default: 'skipped'
fpkalkulus:
required: false
type: string
description: "Fpkalkulus resultat tester"
default: 'skipped'
fplos:
required: false
type: string
description: "Fplos resultat tester"
default: 'skipped'
verdikjede:
required: false
type: string
description: "Verdikjede resultat tester"
default: 'skipped'
jobs:
rapport:
name: Lager og publiserer test rapport
if: "!(inputs.fpsak == 'skipped' && inputs.fptilbake == 'skipped' && inputs.verdikjede == 'skipped')"
runs-on: ubuntu-latest
continue-on-error: true
timeout-minutes: 5
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # ratchet:actions/checkout@v4
with:
repository: 'navikt/fp-autotest'
- name: Henter testresultat for fpsak
if: ${{ !contains(inputs.fpsak, 'skipped') }}
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # ratchet:actions/download-artifact@v4
with:
name: fpsak-testresultat
path: .
- name: Henter testresultat for fptilbake
if: ${{ !contains(inputs.fptilbake, 'skipped') }}
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # ratchet:actions/download-artifact@v4
with:
name: fptilbake-testresultat
path: .
- name: Henter testresultat for kalkulus
if: ${{ !contains(inputs.fpkalkulus, 'skipped') }}
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # ratchet:actions/download-artifact@v4
with:
name: fpkalkulus-testresultat
path: .
- name: Henter testresultat for verdikjede
if: ${{ !contains(inputs.verdikjede, 'skipped') }}
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # ratchet:actions/download-artifact@v4
with:
name: verdikjede-testresultat
path: .
- name: Pakk ut testresultat
if: success()
run: |
if [ -f "fpsak.tar.gz" ]; then echo "Testresultat fpsak funnet" && mkdir fpsak && tar -xzf fpsak.tar.gz --directory fpsak; fi
if [ -f "fptilbake.tar.gz" ]; then echo "Testresultat fptilbake funnet" && mkdir fptilbake && tar -xzf fptilbake.tar.gz --directory fptilbake; fi
if [ -f "fpkalkulus.tar.gz" ]; then echo "Testresultat fpkalkulus funnet" && mkdir fpkalkulus && tar -xzf fpkalkulus.tar.gz --directory fpkalkulus; fi
if [ -f "verdikjede.tar.gz" ]; then echo "Testresultat verdikjede funnet" && mkdir verdikjede && tar -xzf verdikjede.tar.gz --directory verdikjede; fi
- name: Hent eksistrende testrapport og overskriv med nytt test resultat
if: success()
id: ghpages
run: |
git fetch origin gh-pages
mkdir gh-pages
git --work-tree=gh-pages checkout origin/gh-pages
if [ -d "fpsak" ]; then echo "Oppdatere testresultat for fpsak" && rm -rf gh-pages/fpsak && cp -r fpsak gh-pages; fi
if [ -d "fptilbake" ]; then echo "Oppdatere testresultat for fptilbake" && rm -rf gh-pages/fptilbake && cp -r fptilbake gh-pages; fi
if [ -d "fpkalkulus" ]; then echo "Oppdatere testresultat for fpkalkulus" && rm -rf gh-pages/fpkalkulus && cp -r fpkalkulus gh-pages; fi
if [ -d "verdikjede" ]; then echo "Oppdatere testresultat for verdikjede" && rm -rf gh-pages/verdikjede && cp -r verdikjede gh-pages; fi
- name: Deploy testrapport
if: success()
uses: crazy-max/ghaction-github-pages@fbf0a4fa4e00f45accd6cf3232368436ec06ed59 # ratchet:crazy-max/[email protected]
with:
repo: 'navikt/fp-autotest'
target_branch: gh-pages
build_dir: gh-pages
env:
GH_PAT: ${{ secrets.PAT_AUTOTEST }}
notify-slack:
name: Notify slack om testresultat
runs-on: ubuntu-latest
continue-on-error: true
timeout-minutes: 2
steps:
- name: Henter ut historie til trigger
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # ratchet:actions/checkout@v4
with:
repository: ${{ github.repository }}
path: ${{ github.repository }}
fetch-depth: 5
- name: Hent ut versjon fra forrige issue
run: |
CURRENT_HASH=$(echo "${{ inputs.build-version }}" | awk -F'-' '{print $3}')
cd "${{ github.repository }}"
git remote -v
git fetch
echo "DIFFERANSE=$(git log --pretty=format:"%s; author: %an" -n 1 ${CURRENT_HASH})" >> $GITHUB_ENV
- name: Bygger opp slack melding
run: |
function statusJobb() {
if [[ "$1" == *"skipped"* ]]; then
echo "skipped"
elif [[ "$1" == *"test-failure"* || -z "$1" ]]; then
echo "test-feil"
elif [[ "$1" == *"test-success"* && "$2" == *"logg-failure"* ]]; then
echo "logg-feil"
else
echo "success"
fi
}
function echoStatus() {
if [[ "$2" == 'skipped' ]]; then
echo ":heavy_minus_sign: $1"
elif [[ "$2" == 'success' ]]; then
echo ":heavy_check_mark: $1"
else
echo ":x: $1 -> se $3"
fi
}
fpsakStatus="$(statusJobb ${{inputs.fpsak}})"
fptilbakeStatus="$(statusJobb ${{inputs.fptilbake}})"
fpkalkulustestStatus="$(statusJobb ${{inputs.fpkalkulus}})"
fplosStatus="$(statusJobb ${{inputs.fplos}})"
verdikjedetestStatus="$(statusJobb ${{inputs.verdikjede}})"
echo 'SLACK_MESSAGE<<\n' >> $GITHUB_ENV
echo >> $GITHUB_ENV
echoStatus Fpsak $fpsakStatus "<https://navikt.github.io/fp-autotest/fpsak|rapport>" >> $GITHUB_ENV
echoStatus Fptilbake $fptilbakeStatus "<https://navikt.github.io/fp-autotest/fptilbake|rapport>" >> $GITHUB_ENV
echoStatus Kalkulus $fpkalkulustestStatus >> $GITHUB_ENV
echoStatus Fplos $fplosStatus >> $GITHUB_ENV
echoStatus Verdikjedetester $verdikjedetestStatus "<https://navikt.github.io/fp-autotest/verdikjede|rapport>" >> $GITHUB_ENV
echo >> $GITHUB_ENV
echo '*Trigger*: ${{ github.repository }}:${{ inputs.build-version }}' >> $GITHUB_ENV
echo '*Endringer*: ${{ env.DIFFERANSE }}' >> $GITHUB_ENV
echo '*Action URL*: <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|Github Action Url>' >> $GITHUB_ENV
echo '\n' >> $GITHUB_ENV
if [[ $fpsakStatus == 'test-feil' || $fptilbakeStatus == 'test-feil' || $verdikjedetestStatus == 'test-feil' || $fpkalkulustestStatus == 'test-feil' || $fplosStatus == 'test-feil' ]]; then
echo "Test failure!"
echo "SLACK_TITLE=Verdikjeden er brukket :boom:" >> $GITHUB_ENV
echo "SLACK_COLOR=#df1515" >> $GITHUB_ENV
elif [[ $fpsakStatus == 'logg-feil'|| $fptilbakeStatus == 'logg-feil' || $verdikjedetestStatus == 'logg-feil' || $fpkalkulustestStatus == 'logg-feil' || $fplosStatus == 'logg-feil' ]]; then
echo "Feil i loggen, men testene kjørte OK!"
echo "SLACK_TITLE=Testene gikk grønne, men fant feil i loggen :bug:" >> $GITHUB_ENV
echo "SLACK_COLOR=#ffff00" >> $GITHUB_ENV
else
echo "Test success!"
echo "SLACK_TITLE=Verdikjeden er kjørt UTEN feil :rocket:" >> $GITHUB_ENV
echo "SLACK_COLOR=#37df1d" >> $GITHUB_ENV
fi
- name: Slack Notification
if: success()
uses: rtCamp/action-slack-notify@c33737706dea87cd7784c687dadc9adf1be59990 # ratchet:rtCamp/[email protected]
env:
SLACK_CHANNEL: vtp-autotest-resultat
SLACK_COLOR: ${{ env.SLACK_COLOR }}
SLACK_ICON: https://github.com/github.png?size=48
SLACK_TITLE: ${{ env.SLACK_TITLE }}
SLACK_MESSAGE: ${{ env.SLACK_MESSAGE }}
SLACK_USERNAME: Github Action
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_FOOTER: ''
MSG_MINIMAL: true
- name: Slack Notification
if: failure()
uses: rtCamp/action-slack-notify@c33737706dea87cd7784c687dadc9adf1be59990 # ratchet:rtCamp/[email protected]
env:
SLACK_CHANNEL: vtp-autotest-resultat
SLACK_COLOR: #df1515
SLACK_ICON: https://github.com/github.png?size=48
SLACK_TITLE: 'Klarte ikke generere slack-melding!'
SLACK_MESSAGE: 'Sjekk hva som skjedde på Github -> *Action URL*: <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|Github Action Url>'
SLACK_USERNAME: Github Action
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_FOOTER: ''
MSG_MINIMAL: true