-
Notifications
You must be signed in to change notification settings - Fork 1
178 lines (155 loc) · 6.03 KB
/
end2end.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
name: end to end tests
on:
push:
tags:
- '[0-9]+.[0-9]+.[0-9]+'
branches:
- main
pull_request:
concurrency:
# Cancel previous workflows on branch push
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
e2e:
services:
postgres:
image: postgres:16.0
env:
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
runs-on: ubuntu-latest
env:
LOG_LEVEL: DEBUG
NO_COLOR: true
ORCHESTRATOR_DATABASE_URL: postgresql://postgres:postgres@localhost:5432/postgres?sslmode=disable
ORCHESTRATOR_MIGRATION_DIR: file://./server/standalone/migration/
ORCHESTRATOR_TLS_ENABLED: false
ORCHESTRATOR_VERIFY_CLIENT_MSP_ID: false
ORCHESTRATOR_TX_RETRY_BUDGET: 500ms
DB_DUMPS_BUCKET_NAME: substra-orchestrator-dumps
steps:
- name: Check out repository code
uses: actions/checkout@v4
with:
fetch-depth: '0'
- name: Get changed migration files
id: changed_migrations
uses: tj-actions/[email protected]
with:
files: server/standalone/migration/*.sql
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: 1.21.x
- name: Cache Go modules
uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: build-${{ hashFiles('**/go.sum') }}
- name: Install protobuf codegen tool
run: |
curl -LO https://github.com/protocolbuffers/protobuf/releases/download/v3.18.1/protoc-3.18.1-linux-x86_64.zip
unzip protoc-3.18.1-linux-x86_64.zip -d $HOME/.local
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Install go tools
run: |
cd /tmp
go install google.golang.org/protobuf/cmd/[email protected]
go install google.golang.org/grpc/cmd/[email protected]
go install github.com/go-bindata/go-bindata/[email protected]
- name: Install db migration tool
run: |
wget -qO- https://github.com/golang-migrate/migrate/releases/download/v4.15.2/migrate.linux-amd64.tar.gz | tar xzf - -C $HOME/.local/bin
- name: Build orchestrator
run: make orchestrator
- name: Authenticate to Google Cloud
if: steps.changed_migrations.outputs.any_changed == 'true' || github.ref_type == 'tag'
uses: google-github-actions/auth@v1
with:
credentials_json: '${{ secrets.GCP_BUCKET_SECRET }}'
- name: Set up Google Cloud CLI
if: steps.changed_migrations.outputs.any_changed == 'true' || github.ref_type == 'tag'
uses: google-github-actions/setup-gcloud@v1
- name: Install psql
if: steps.changed_migrations.outputs.any_changed == 'true' || github.ref_type == 'tag'
run: |
sudo apt-get update
sudo apt-get install --yes --no-install-recommends postgresql-client
- name: Wait for postgres
run: |
while ! $(nc localhost 5432 -z); do
sleep 2
done
timeout-minutes: 1
- name: Restore db dump from previous release
id: restore_db
if: steps.changed_migrations.outputs.any_changed == 'true'
run: |
LATEST_RELEASE_TAG=$(git tag -l | grep -E "^[0-9]+\.[0-9]+\.[0-9]+$" | sort -V | tail -n 1)
gsutil cp gs://${DB_DUMPS_BUCKET_NAME}/${LATEST_RELEASE_TAG} dump.sql
psql $ORCHESTRATOR_DATABASE_URL < dump.sql
INITIAL_MIGRATION_VERSION=$(migrate -source "${ORCHESTRATOR_MIGRATION_DIR}" -database "${ORCHESTRATOR_DATABASE_URL}" version 2>&1 > /dev/null)
echo "::set-output name=initial_migration_version::$INITIAL_MIGRATION_VERSION"
- name: Migrate db up from previous release data
if: steps.changed_migrations.outputs.any_changed == 'true'
run: |
migrate -source "${ORCHESTRATOR_MIGRATION_DIR}" -database "${ORCHESTRATOR_DATABASE_URL}" up
- name: Setup channel configuration
run: |
cat << EOF > ${{runner.temp}}/config.yaml
---
channels:
mychannel:
- MyOrg1MSP
- MyOrg2MSP
yourchannel:
- MyOrg1MSP
- MyOrg2MSP
EOF
- name: Run e2e tests on previous release data
if: steps.changed_migrations.outputs.any_changed == 'true'
env:
ORCHESTRATOR_CHANNEL_CONFIG: ${{runner.temp}}/config.yaml
run: |
./bin/orchestrator > server.prepopulated.run.log 2>&1 &
go test -tags=e2e ./e2e -v -short --failfast -server_addr localhost:9000
- name: Migrate db down to previous release migration version
if: steps.changed_migrations.outputs.any_changed == 'true'
run: >
migrate
-source "${ORCHESTRATOR_MIGRATION_DIR}"
-database "${ORCHESTRATOR_DATABASE_URL}"
goto ${{ steps.restore_db.outputs.initial_migration_version }}
- name: Reset db
if: steps.changed_migrations.outputs.any_changed == 'true'
run: |
psql "$ORCHESTRATOR_DATABASE_URL" << EOF
DROP SCHEMA public CASCADE;
CREATE SCHEMA public;
EOF
- name: Migrate db up
run: |
migrate -source "${ORCHESTRATOR_MIGRATION_DIR}/" -database "${ORCHESTRATOR_DATABASE_URL}" up
- name: Run e2e tests
env:
ORCHESTRATOR_CHANNEL_CONFIG: ${{runner.temp}}/config.yaml
run: |
./bin/orchestrator > server.log 2>&1 &
go test -tags=e2e ./e2e -v -short --failfast -server_addr localhost:9000
- name: Save db dump in GCS bucket
if: github.ref_type == 'tag'
run: |
pg_dump "$ORCHESTRATOR_DATABASE_URL" | gsutil cp - gs://${DB_DUMPS_BUCKET_NAME}/${GITHUB_REF_NAME}
- name: Archive server log
if: always()
uses: actions/upload-artifact@v3
with:
name: server-log
path: server*.log