-
Notifications
You must be signed in to change notification settings - Fork 4
249 lines (219 loc) · 8.51 KB
/
continuous-delivery.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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
name: continuous-delivery
on:
workflow_dispatch:
schedule:
- cron: '0 1 * * *'
# set up environment variables to be used across all the jobs
env:
GOLANG_VERSION: "1.20.x"
KIND_VERSION: "v0.20.0"
REGISTRY: "ghcr.io/cloudnative-pg/postgresql-trunk"
POSTGRES_VERSION: "16-devel"
defaults:
run:
# default failure handling for shell scripts in 'run' steps
shell: 'bash -Eeuo pipefail -x {0}'
jobs:
build-pg:
name: Build the Trunk of PostgreSQL
runs-on: ubuntu-22.04
permissions:
contents: read
packages: write
outputs:
POSTGRES_IMG: ${{ steps.set-env.outputs.POSTGRES_IMG }}
E2E_PRE_ROLLING_UPDATE_IMG: ${{ steps.set-env.outputs.E2E_PRE_ROLLING_UPDATE_IMG }}
steps:
- name: Set Global Env Vars
id: set-env
run: |
postgres_img="${{ env.REGISTRY }}:${{ env.POSTGRES_VERSION }}"
# The version of operator to upgrade FROM, in the rolling upgrade E2E test
e2e_pre_rolling_update_image="${postgres_img}-1"
echo "POSTGRES_IMG=${postgres_img}" >> $GITHUB_OUTPUT
echo "E2E_PRE_ROLLING_UPDATE_IMG=${e2e_pre_rolling_update_image}" >> $GITHUB_OUTPUT
- name: Checkout Code
uses: actions/checkout@v3
- name: Log in to the GitHub Container registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and load
uses: docker/build-push-action@v4
with:
context: .
push: true
load: false
tags: |
${{ steps.set-env.outputs.POSTGRES_IMG }}
${{ steps.set-env.outputs.E2E_PRE_ROLLING_UPDATE_IMG }}
e2e-local:
name: Run E2E on local executors
needs:
- build-pg
runs-on: ubuntu-22.04
env:
TEST_DEPTH: 4
K8S_VERSION: "v1.27.3"
ID: "local"
POSTGRES_KIND: "PostgreSQL"
DOCKER_SERVER: ghcr.io
DOCKER_USERNAME: ${{ github.actor }}
DOCKER_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
TEST_UPGRADE_TO_V1: false
BRANCH_NAME: main
POSTGRES_IMG: ${{ needs.build-pg.outputs.POSTGRES_IMG }}
E2E_PRE_ROLLING_UPDATE_IMG: ${{ needs.build-pg.outputs.E2E_PRE_ROLLING_UPDATE_IMG }}
DEBUG: "true"
BUILD_IMAGE: "true"
E2E_DEFAULT_STORAGE_CLASS: standard
E2E_CSI_STORAGE_CLASS: csi-hostpath-sc
E2E_DEFAULT_VOLUMESNAPSHOT_CLASS: csi-hostpath-snapclass
LOG_DIR: ${{ github.workspace }}/kind-logs/
DOCKER_REGISTRY_MIRROR: https://mirror.gcr.io
TEST_CLOUD_VENDOR: "local"
steps:
- name: Cleanup Disk
uses: jlumbroso/free-disk-space@main
with:
android: true
dotnet: true
haskell: true
large-packages: false
swap-storage: true
- name: Cleanup docker cache
run: |
echo "-------------Disk info before cleanup----------------"
df -h
echo "-----------------------------------------------------"
docker system prune -a -f
echo "-------------Disk info after cleanup----------------"
df -h
echo "-----------------------------------------------------"
- name: Checkout
uses: actions/checkout@v3
with:
repository: cloudnative-pg/cloudnative-pg
ref: main
fetch-depth: 0
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: ${{ env.GOLANG_VERSION }}
- name: Set GoReleaser environment
run: |
echo GOPATH=$(go env GOPATH) >> $GITHUB_ENV
echo PWD=$(pwd) >> $GITHUB_ENV
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Prepare the environment
uses: nick-fields/retry@v2
with:
timeout_seconds: 120
max_attempts: 3
on_retry_command: |
# Clear-ups before retries
rm -rf /usr/local/bin/kind /usr/local/bin/kubectl
command: |
sudo apt-get update
sudo apt-get install -y gettext-base
sudo hack/setup-cluster.sh prepare /usr/local/bin
- name: Run Kind End-to-End tests
run: make e2e-test-kind
# Summarize the failed E2E test cases if there are any
- name: Report failed E2E tests
if: failure()
run: |
set +x
chmod +x .github/report-failed-test.sh
./.github/report-failed-test.sh
# Create an individual artifact for each E2E test, which will be used to
# generate E2E test summary in the follow-up job 'summarize-e2e-tests'
- name: Create individual artifact for each E2E test
if: (always() && !cancelled())
run: |
set +x
echo '{"runner": "local", "postgres": "${{env.POSTGRES_VERSION}}", "postgres_kind": "${{env.POSTGRES_KIND}}", "kubernetes": "${{env.K8S_VERSION}}", "runid": ${{ github.run_id }}, "id": "local-PostgreSQL"-${{ env.POSTGRES_VERSION }}", "repo": "${{github.repository}}", "branch": "${GITHUB_REF#refs/heads/}", "refname": "${{github.ref_name}}" }'
python .github/generate-test-artifacts.py \
-o testartifacts-${{ env.ID }} \
-f tests/e2e/out/report.json \
-m '{"runner": "local", "postgres": "${{env.POSTGRES_VERSION}}", "postgres_kind": "${{env.POSTGRES_KIND}}", "kubernetes": "${{env.K8S_VERSION}}", "runid": ${{ github.run_id }}, "id": "${{ env.ID }}", "repo": "${{github.repository}}", "branch": "${GITHUB_REF#refs/heads/}", "refname": "${{github.ref_name}}" }'
if [ -f tests/e2e/out/upgrade_report.json ]; then
python .github/generate-test-artifacts.py \
-o testartifacts-${{ env.ID }} \
-f tests/e2e/out/upgrade_report.json \
-m '{"runner": "local", "postgres": "${{env.POSTGRES_VERSION}}", "postgres_kind": "${{env.POSTGRES_KIND}}", "kubernetes": "${{env.K8S_VERSION}}", "runid": ${{ github.run_id }}, "id": "${{ env.ID }}", "repo": "${{github.repository}}", "branch": "${GITHUB_REF#refs/heads/}", "refname": "${{github.ref_name}}" }'
fi
- name: Archive test artifacts
if: (always() && !cancelled())
uses: actions/upload-artifact@v3
with:
name: testartifacts-local
path: testartifacts-${{ env.ID }}/
retention-days: 7
- name: Cleanup test artifacts
if: always()
run:
rm -rf testartifacts-${{ env.ID }}/
# Delete report.json after the analysis. File should always exist.
# Delete upgrade_report.json. It may not exist depending on test level.
- name: Cleanup ginkgo JSON report
if: always()
run: |
if [ -f tests/e2e/out/upgrade_report.json ]; then
rm tests/e2e/out/upgrade_report.json
fi
rm tests/e2e/out/report.json
# Archive logs for failed test cases if there are any
- name: Archive Kind logs
if: failure()
uses: actions/upload-artifact@v3
with:
name: kind-logs-${{ env.ID }}
path: kind-logs/
retention-days: 7
- name: Archive e2e failure contexts
if: failure()
uses: actions/upload-artifact@v3
with:
name: test-failure-contexts-${{ env.ID }}
path: |
tests/*/out/
retention-days: 7
if-no-files-found: ignore
# Summarize E2E test results, display in the GitHub 'summary' view
summarize-e2e-tests:
name: E2E test suite
needs:
- e2e-local
if: |
always() && !cancelled() &&
(
needs.e2e-local.result == 'success' ||
needs.e2e-local.result == 'failure'
)
runs-on: ubuntu-22.04
steps:
- name: Create a directory for the artifacts
run: mkdir test-artifacts
- name: Download all artifacts to the directory
uses: actions/download-artifact@v3
with:
path: test-artifacts
- name: Flatten all artifacts onto directory
# The download-artifact action, since we did not give it a name,
# downloads all artifacts and creates a new folder for each.
# In this step we bring all the JSONs to a single folder
run: |
mkdir test-artifacts/data
mv test-artifacts/*/*.json test-artifacts/data
- name: Display the structure of the artifact folder
run: ls -R test-artifacts/data
- name: Compute the E2E test summary
uses: cloudnative-pg/[email protected]
with:
artifact_directory: test-artifacts/data
- name: Delete the downloaded files
run: rm -rf test-artifacts