forked from wso2/product-is
-
Notifications
You must be signed in to change notification settings - Fork 0
367 lines (340 loc) · 19.8 KB
/
MainMigrationWorkflow.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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
name: Migration Tester
on:
workflow_dispatch:
inputs:
currentVersion:
description: "Specify the version of WSO2 IS that is presently installed in your environment."
default: "5.11.0"
type: choice
options:
- "5.9.0"
- "5.10.0"
- "5.11.0"
- "6.0.0"
- "6.1.0"
- "6.2.0"
migratingVersion:
description: "Specify the version of WSO2 IS that you want to migrate."
default: "6.0.0"
type: choice
options:
- "5.10.0"
- "5.11.0"
- "6.0.0"
- "6.1.0"
- "6.2.0"
database:
description: "Select the database."
default: "mysql"
type: choice
options:
- "mysql"
- "mssql"
- "postgres"
os:
description: "Select the OS."
default: "ubuntu-latest"
type: choice
options:
- "ubuntu-latest"
- "macos-latest"
- "windows-latest"
urlOld:
description: "Provide the URL to download the old version of WSO2 IS."
default: https://github.com/wso2/product-is/releases/download/v5.11.0/wso2is-5.11.0.zip
required: true
urlNew:
description: "Provide the URL to download the version you want to upgrade WSO2 IS."
default: https://github.com/wso2/product-is/releases/download/v6.0.0-rc2/wso2is-6.0.0-rc2.zip
required: true
jobs:
ubuntu-postgres-migration:
if: ${{ github.event.inputs.database == 'postgres' && github.event.inputs.os == 'ubuntu-latest' }}
runs-on: ${{ github.event.inputs.os }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup Docker environment
run: |
# Get the ID of the workflow from the GitHub API using curl and jq
WORKFLOW_ID=$(curl -s -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/wso2/product-is/actions/workflows | jq -r '.workflows[] | select(.name == "Migration Tester") | .id')
echo "Workflow ID: $WORKFLOW_ID"
# Update and upgrade packages, and install necessary dependencies
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common
# Add Docker GPG key and add the Docker repository
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
# Update the packages again and install Docker CE
sudo apt-get update
sudo apt-get install -y docker-ce
- name: Run Docker command
run: |
# Create the PostgreSQL container if it doesn't already exist
if ! docker ps -a | grep postgres; then
echo "Creating the PostgreSQL container..."
docker run -d -p 5432:5432 --name postgres -e POSTGRES_PASSWORD=postgres postgres
sleep 20
echo "PostgreSQL container created successfully."
fi
# Start the PostgreSQL server if it's not running
if ! docker ps | grep postgres; then
echo "Starting the PostgreSQL server..."
docker start postgres
sleep 20
echo "PostgreSQL server started successfully."
fi
# Create a new database 'testdb'
docker exec -i postgres psql -U postgres -c "CREATE DATABASE testdb;"
echo "Database created successfully!"
# Grant all privileges to postgres user
docker exec -i postgres psql -U postgres -c "GRANT ALL PRIVILEGES ON DATABASE testdb TO postgres;"
echo "Database privileges granted successfully!"
# Change the password for role postgres
docker exec -i postgres psql -U postgres -c "ALTER USER postgres WITH PASSWORD 'postgres';"
echo "Password for role 'postgres' changed successfully!"
- name: Copy SQL file to PostgreSQL container
run: |
docker cp ./.github/migration-tester/utils/db-scripts/IS-5.11/postgresone.sql postgres:/
docker exec -i postgres sh -c 'exec psql -U postgres -d testdb < /postgresone.sql'
echo "Postgre database created successfully!"
docker cp ./.github/migration-tester/utils/db-scripts/IS-5.11/identity/postgrestwo.sql postgres:/
docker exec -i postgres sh -c 'exec psql -U postgres -d testdb < /postgrestwo.sql '
echo "Script1 executed successfully!"
docker cp ./.github/migration-tester/utils/db-scripts/IS-5.11/identity/uma/postgresthree.sql postgres:/
docker exec -i postgres sh -c 'exec psql -U postgres -d testdb < /postgresthree.sql'
echo "Script2 executed successfully!"
docker cp ./.github/migration-tester/utils/db-scripts/IS-5.11/consent/postgresfour.sql postgres:/
docker exec -i postgres sh -c 'exec psql -U postgres -d testdb < /postgresfour.sql'
echo "Script3 executed successfully!"
docker cp ./.github/migration-tester/utils/db-scripts/IS-5.11/metrics/postgresfive.sql postgres:/
docker exec -i postgres sh -c 'exec psql -U postgres -d testdb < /postgresfive.sql'
echo "All postgre scripts executed successfully!"
- name: Execute Migration Automation Script Ubuntu
run: |
chmod +x ./.github/migration-tester/migration-automation/ubuntu-os/migration-script-ubuntu.sh
sh ./.github/migration-tester/migration-automation/ubuntu-os/migration-script-ubuntu.sh "${{ github.event.inputs.urlOld }}" "${{ github.event.inputs.urlNew }}" "${{ github.event.inputs.currentVersion }}" "${{ github.event.inputs.migratingVersion }}" "${{ github.event.inputs.database }}" "${{ github.event.inputs.os }}" "${{ secrets.MIGRATION_EMAIL }}" "${{ secrets.MIGRATION_PASSWORD }}" "${{ secrets.MIGRATION_PAT }}" | tee "./.github/migration-tester/migration-automation/logs.txt"
continue-on-error: true
- name: Persist Logs
run: |
mkdir -p ./.github/migration-tester/migration-automation/artifacts
cp ./.github/migration-tester/migration-automation/logs.txt migration-automation/artifacts/
if: ${{ always() }}
- name: Upload Artifacts
uses: actions/upload-artifact@v2
if: always()
with:
name: "logs-${{ github.event.inputs.currentVersion }}-${{ github.event.inputs.migratingVersion }}-${{ github.event.inputs.database }}-${{ github.event.inputs.os }}"
path: ./.github/migration-tester/migration-automation/artifacts
ubuntu-mysql-migration:
if: ${{ github.event.inputs.database == 'mysql' && github.event.inputs.os == 'ubuntu-latest' }}
runs-on: ${{ github.event.inputs.os }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Execute Migration Automation Script Ubuntu
run: |
chmod +x ./.github/migration-tester/migration-automation/ubuntu-os/migration-script-ubuntu.sh
sh ./.github/migration-tester/migration-automation/ubuntu-os/migration-script-ubuntu.sh "${{ github.event.inputs.urlOld }}" "${{ github.event.inputs.urlNew }}" "${{ github.event.inputs.currentVersion }}" "${{ github.event.inputs.migratingVersion }}" "${{ github.event.inputs.database }}" "${{ github.event.inputs.os }}" "${{ secrets.MIGRATION_EMAIL }}" "${{ secrets.MIGRATION_PASSWORD }}" "${{ secrets.MIGRATION_PAT }}" | tee "./.github/migration-tester/migration-automation/logs.txt"
continue-on-error: true
- name: Persist Logs
run: |
mkdir -p ./.github/migration-tester/migration-automation/artifacts
cp ./.github/migration-tester/migration-automation/logs.txt migration-automation/artifacts/
if: ${{ always() }}
- name: Upload Artifacts
uses: actions/upload-artifact@v2
if: always()
with:
name: "logs-${{ github.event.inputs.currentVersion }}-${{ github.event.inputs.migratingVersion }}-${{ github.event.inputs.database }}-${{ github.event.inputs.os }}"
path: ./.github/migration-tester/migration-automation/artifacts
ubuntu-mssql-migration:
if: ${{ github.event.inputs.database == 'mssql' && github.event.inputs.os == 'ubuntu-latest' }}
runs-on: ${{ github.event.inputs.os }}
services:
mssql:
image: mcr.microsoft.com/mssql/server:2019-latest
env:
SA_PASSWORD: YourStrongPassw0rd
ACCEPT_EULA: Y
MSSQL_PID: Developer
ports:
- 1433:1433
options: --name=sqlserver-test --health-cmd="/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'YourStrongPassw0rd' -Q 'SELECT 1'" --health-interval=10s --health-timeout=5s --health-retries=3
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Create MS SQL Database
run: |
sudo apt-get update && sudo apt-get install -y mssql-tools
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'YourStrongPassw0rd' -Q 'CREATE DATABASE testdb'
- name: Copy SQL files to MSSQL container
run: |
docker cp ./.github/migration-tester/utils/db-scripts/IS-5.11/mssql.sql sqlserver-test:/mssql.sql
docker exec sqlserver-test /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'YourStrongPassw0rd' -d testdb -i /mssql.sql
docker cp ./.github/migration-tester/utils/db-scripts/IS-5.11/identity/mssql.sql sqlserver-test:/identity-mssql.sql
docker exec sqlserver-test /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'YourStrongPassw0rd' -d testdb -i /identity-mssql.sql
docker cp ./.github/migration-tester/utils/db-scripts/IS-5.11/identity/uma/mssql.sql sqlserver-test:/identity-uma-mssql.sql
docker exec sqlserver-test /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'YourStrongPassw0rd' -d testdb -i /identity-uma-mssql.sql
docker cp ./.github/migration-tester/utils/db-scripts/IS-5.11/consent/mssql.sql sqlserver-test:/consent-mssql.sql
docker exec sqlserver-test /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'YourStrongPassw0rd' -d testdb -i /consent-mssql.sql
docker cp ./.github/migration-tester/utils/db-scripts/IS-5.11/metrics/mssql.sql sqlserver-test:/metrics-mssql.sql
docker exec sqlserver-test /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'YourStrongPassw0rd' -d testdb -i /metrics-mssql.sql
echo "Copied mssql scripts to docker container"
- name: Execute Migration Automation Script Ubuntu
run: |
chmod +x ./.github/migration-tester/migration-automation/ubuntu-os/migration-script-ubuntu.sh
sh ./.github/migration-tester/migration-automation/ubuntu-os/migration-script-ubuntu.sh "${{ github.event.inputs.urlOld }}" "${{ github.event.inputs.urlNew }}" "${{ github.event.inputs.currentVersion }}" "${{ github.event.inputs.migratingVersion }}" "${{ github.event.inputs.database }}" "${{ github.event.inputs.os }}" "${{ secrets.MIGRATION_EMAIL }}" "${{ secrets.MIGRATION_PASSWORD }}" "${{ secrets.MIGRATION_PAT }}" | tee "./.github/migration-tester/migration-automation/logs.txt"
continue-on-error: true
- name: Persist Logs
run: |
mkdir -p ./.github/migration-tester/migration-automation/artifacts
cp ./.github/migration-tester/migration-automation/logs.txt migration-automation/artifacts/
if: ${{ always() }}
- name: Upload Artifacts
uses: actions/upload-artifact@v2
if: always()
with:
name: "logs-${{ github.event.inputs.currentVersion }}-${{ github.event.inputs.migratingVersion }}-${{ github.event.inputs.database }}-${{ github.event.inputs.os }}"
path: ./.github/migration-tester/migration-automation/artifacts
macos-mysql-migration:
if: ${{ github.event.inputs.database == 'mysql' && github.event.inputs.os == 'macos-latest' }}
runs-on: ${{ github.event.inputs.os }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Execute Migration Automation Script Mac
run: |
chmod +x ./.github/migration-tester/migration-automation/mac-os/migration-script-mac.sh
sh ./.github/migration-tester/migration-automation/mac-os/migration-script-mac.sh "${{ github.event.inputs.urlOld }}" "${{ github.event.inputs.urlNew }}" "${{ github.event.inputs.currentVersion }}" "${{ github.event.inputs.migratingVersion }}" "${{ github.event.inputs.database }}" "${{ github.event.inputs.os }}" "${{ secrets.MIGRATION_EMAIL }}" "${{ secrets.MIGRATION_PASSWORD }}" "${{ secrets.MIGRATION_PAT }}" | tee "./.github/migration-tester/migration-automation/logs.txt"
continue-on-error: true
- name: Persist Logs
run: |
mkdir -p ./.github/migration-tester/migration-automation/artifacts
cp ./.github/migration-tester/migration-automation/logs.txt migration-automation/artifacts/
if: ${{ always() }}
- name: Upload Artifacts
uses: actions/upload-artifact@v2
if: always()
with:
name: "logs-${{ github.event.inputs.currentVersion }}-${{ github.event.inputs.migratingVersion }}-${{ github.event.inputs.database }}-${{ github.event.inputs.os }}"
path: ./.github/migration-tester/migration-automation/artifacts
macos-postgres-migration:
runs-on: ${{ github.event.inputs.os }}
if: ${{ github.event.inputs.database == 'postgres' && github.event.inputs.os == 'macos-latest' }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up PostgreSQL
env:
PGDATA: /usr/local/var/postgres
PGDATABASE: testdb
run: |
brew update
brew install postgresql
initdb $PGDATA
pg_ctl -D $PGDATA start
createuser -s postgres
createdb $PGDATABASE
psql -c "GRANT ALL PRIVILEGES ON DATABASE $PGDATABASE TO postgres;"
- name: Execute Postgres SQL scripts
run: |
psql -d testdb -f "./.github/migration-tester/utils/db-scripts/IS-5.11/postgresone.sql"
psql -d testdb -f "./.github/migration-tester/utils/db-scripts/IS-5.11/consent/postgresfour.sql"
psql -d testdb -f "./.github/migration-tester/utils/db-scripts/IS-5.11/identity/postgrestwo.sql"
psql -d testdb -f "./.github/migration-tester/utils/db-scripts/IS-5.11/identity/uma/postgresthree.sql"
psql -d testdb -f "./.github/migration-tester/utils/db-scripts/IS-5.11/metrics/postgresfive.sql"
- name: Verify script execution
run: psql -d testdb -c 'SHOW server_version'
shell: bash
- name: Execute Migration Automation Script Mac
run: |
chmod +x ./.github/migration-tester/migration-automation/mac-os/migration-script-mac.sh
sh ./.github/migration-tester/migration-automation/mac-os/migration-script-mac.sh "${{ github.event.inputs.urlOld }}" "${{ github.event.inputs.urlNew }}" "${{ github.event.inputs.currentVersion }}" "${{ github.event.inputs.migratingVersion }}" "${{ github.event.inputs.database }}" "${{ github.event.inputs.os }}" "${{ secrets.MIGRATION_EMAIL }}" "${{ secrets.MIGRATION_PASSWORD }}" "${{ secrets.MIGRATION_PAT }}" | tee "./.github/migration-tester/migration-automation/logs.txt"
continue-on-error: true
- name: Persist Logs
run: |
mkdir -p ./.github/migration-tester/migration-automation/artifacts
cp ./.github/migration-tester/migration-automation/logs.txt migration-automation/artifacts/
if: ${{ always() }}
- name: Upload Artifacts
uses: actions/upload-artifact@v2
if: always()
with:
name: "logs-${{ github.event.inputs.currentVersion }}-${{ github.event.inputs.migratingVersion }}-${{ github.event.inputs.database }}-${{ github.event.inputs.os }}"
path: ./.github/migration-tester/migration-automation/artifacts
macos-mssql-migration:
if: ${{ github.event.inputs.database == 'mssql' && github.event.inputs.os == 'macos-latest' }}
runs-on: ${{ github.event.inputs.os }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- uses: potatoqualitee/mssqlsuite@v1.7
with:
install: sqlengine, sqlclient, sqlpackage, localdb
version: 2019
SA-password: YourStrongPassw0rd
- name: Create MS SQL Database
run: sqlcmd -U SA -P 'YourStrongPassw0rd' -Q 'CREATE DATABASE testdb'
- name: Run query
run: sqlcmd -U SA -P 'YourStrongPassw0rd' -d testdb -Q 'SELECT @@VERSION'
- name: Execute MSSQL Scripts Mac
run: |
sqlcmd -U SA -P 'YourStrongPassw0rd' -Q 'CREATE DATABASE testdb'
sqlcmd -U SA -P 'YourStrongPassw0rd' -d testdb -Q 'SELECT @@VERSION'
sqlcmd -U SA -P 'YourStrongPassw0rd' -d testdb -i ./.github/migration-tester/utils/db-scripts/IS-5.11/mssql.sql
sqlcmd -U SA -P 'YourStrongPassw0rd' -d testdb -i ./.github/migration-tester/utils/db-scripts/IS-5.11/identity/mssql.sql
sqlcmd -U SA -P 'YourStrongPassw0rd' -d testdb -i ./.github/migration-tester/utils/db-scripts/IS-5.11/identity/uma/mssql.sql
sqlcmd -U SA -P 'YourStrongPassw0rd' -d testdb -i ./.github/migration-tester/utils/db-scripts/IS-5.11/consent/mssql.sql
sqlcmd -U SA -P 'YourStrongPassw0rd' -d testdb -i ./.github/migration-tester/utils/db-scripts/IS-5.11/metrics/mssql.sql
- name: Verify script execution
run: sqlcmd -U SA -P 'YourStrongPassw0rd' -d testdb -Q 'SELECT @@VERSION'
- name: Execute Migration Automation Script Mac
run: |
chmod +x ./.github/migration-tester/migration-automation/mac-os/migration-script-mac.sh
sh ./.github/migration-tester/migration-automation/mac-os/migration-script-mac.sh "${{ github.event.inputs.urlOld }}" "${{ github.event.inputs.urlNew }}" "${{ github.event.inputs.currentVersion }}" "${{ github.event.inputs.migratingVersion }}" "${{ github.event.inputs.database }}" "${{ github.event.inputs.os }}" "${{ secrets.MIGRATION_EMAIL }}" "${{ secrets.MIGRATION_PASSWORD }}" "${{ secrets.MIGRATION_PAT }}" | tee "./.github/migration-tester/migration-automation/logs.txt"
continue-on-error: true
- name: Persist Logs
run: |
mkdir -p ./.github/migration-tester/migration-automation/artifacts
cp ./.github/migration-tester/migration-automation/logs.txt migration-automation/artifacts/
if: ${{ always() }}
- name: Upload Artifacts
uses: actions/upload-artifact@v2
if: always()
with:
name: "logs-${{ github.event.inputs.currentVersion }}-${{ github.event.inputs.migratingVersion }}-${{ github.event.inputs.database }}-${{ github.event.inputs.os }}"
path: ./.github/migration-tester/migration-automation/artifacts
validate-migration:
needs:
[
ubuntu-postgres-migration,
ubuntu-mssql-migration,
macos-mssql-migration,
macos-postgres-migration,
ubuntu-mysql-migration,
macos-mysql-migration,
]
if: always()
runs-on: ${{ github.event.inputs.os }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Download Artifacts
uses: actions/download-artifact@v2
if: always()
with:
name: "logs-${{ github.event.inputs.currentVersion }}-${{ github.event.inputs.migratingVersion }}-${{ github.event.inputs.database }}-${{ github.event.inputs.os }}"
path: ./.github/migration-tester/migration-automation/artifacts
retention-days: 7
- name: Post Migration Testing
run: |
# Access logs from the downloaded artifacts folder
while IFS= read -r line; do
if echo "$line" | grep -i -q "ERROR\|error\|Error"; then
echo -e "\e[91m$line\e[0m"
else
echo "$line"
fi
done < ./.github/migration-tester/migration-automation/artifacts/logs.txt