-
Notifications
You must be signed in to change notification settings - Fork 594
161 lines (155 loc) · 5.46 KB
/
integration-tests.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
name: Integration tests
on:
push:
branches:
- master
- it/**
jobs:
start:
name: Start
outputs:
go_version: ${{ steps.go_version.outputs.go_version }}
sha: ${{ steps.sha.outputs.sha }}
runs-on: ubuntu-latest
steps:
- uses: styfle/[email protected]
- uses: actions/checkout@v4
- name: Get GO version
id: go_version
run: |
echo "go_version=$(cat go.mod | grep go | head -1 | awk '{print $2}')" >> "$GITHUB_OUTPUT"
- name: Get commit SHA
id: sha
run: |
echo "sha=$(git log --format=%H -n 1)" >> "$GITHUB_OUTPUT"
- name: Update status
run: |
curl \
--location \
--request POST 'https://api.github.com/repos/SAP/jenkins-library/statuses/${{ steps.sha.outputs.sha }}' \
-H 'Content-Type: application/json' \
--data '{"state": "pending",
"context": "Go / integration-tests",
"target_url": "https://github.com/SAP/jenkins-library/actions/runs/${{ github.run_id }}"}' \
-H 'Authorization: token ${{secrets.INTEGRATION_TEST_VOTING_TOKEN}}'
build_piper:
name: Build Piper
needs:
- start
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
with:
ref: ${{ needs.start.outputs.sha }}
- uses: actions/setup-go@v5
with:
go-version: ${{ needs.start.outputs.go_version }}
- name: Build
# with `-tags release` we ensure that shared test utilities won't end up in the binary
run: CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o piper -tags release
- name: Upload Piper binary
if: success()
uses: actions/upload-artifact@v3
with:
name: piper
path: piper
build_integration_tests:
name: Build integration tests
outputs:
matrix: ${{ steps.matrix.outputs.matrix }}
needs:
- start
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
with:
ref: ${{ needs.start.outputs.sha }}
- uses: actions/setup-go@v5
with:
go-version: ${{ needs.start.outputs.go_version }}
- name: Build
run: CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go test -c -o integration_tests -tags integration ./integration/...
- name: Form integration tests run matrix
if: success()
id: matrix
run: |
echo "matrix=$(go run .github/workflows/parse_integration_test_list.go -file ./integration/github_actions_integration_test_list.yml)" >> "$GITHUB_OUTPUT"
- name: Upload integration tests binary
if: success()
uses: actions/upload-artifact@v3
with:
name: integration_tests
path: integration_tests
run_integration_tests:
name: Run integration tests
needs:
- build_piper
- build_integration_tests
- start
strategy:
fail-fast: true
matrix: ${{ fromJson(needs.build_integration_tests.outputs.matrix) }}
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
with:
ref: ${{ needs.start.outputs.sha }}
- uses: actions/setup-go@v5
with:
go-version: ${{ needs.start.outputs.go_version }}
- name: Download Piper binary
uses: actions/download-artifact@v3
with:
name: piper
- name: Download integration tests binary
uses: actions/download-artifact@v3
with:
name: integration_tests
path: ./integration/
- name: Run test
env:
PIPER_INTEGRATION_GITHUB_TOKEN: ${{secrets.PIPER_INTEGRATION_GITHUB_TOKEN}}
PIPER_INTEGRATION_SONAR_TOKEN: ${{secrets.PIPER_INTEGRATION_SONAR_TOKEN}}
PIPER_tmsServiceKey: ${{secrets.PIPER_TMSSERVICEKEY}}
run: |
chmod +x piper
cd ./integration
chmod +x integration_tests
./integration_tests -test.v -test.run ${{ matrix.run }}
finish:
name: Finish
if: always() && needs.start.result == 'success'
needs:
- start
- build_piper
- build_integration_tests
- run_integration_tests
runs-on: ubuntu-latest
steps:
- name: Update status
run: |
if [[ "${{ needs.run_integration_tests.result }}" == "success" ]]
then
curl \
--location \
--request POST 'https://api.github.com/repos/SAP/jenkins-library/statuses/${{ needs.start.outputs.sha }}' \
-H 'Content-Type: application/json' \
--data '{"state": "success",
"context": "Go / integration-tests",
"target_url": "https://github.com/SAP/jenkins-library/actions/runs/${{ github.run_id }}"}' \
-H 'Authorization: token ${{secrets.INTEGRATION_TEST_VOTING_TOKEN}}' && \
exit 0
else
curl \
--location \
--request POST 'https://api.github.com/repos/SAP/jenkins-library/statuses/${{ needs.start.outputs.sha }}' \
-H 'Content-Type: application/json' \
--data '{"state": "failure",
"context": "Go / integration-tests",
"target_url": "https://github.com/SAP/jenkins-library/actions/runs/${{ github.run_id }}"}' \
-H 'Authorization: token ${{secrets.INTEGRATION_TEST_VOTING_TOKEN}}' && \
exit 1
fi