-
Notifications
You must be signed in to change notification settings - Fork 18
197 lines (162 loc) · 7.36 KB
/
test.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
name: Build and Test
on:
workflow_dispatch:
pull_request:
types:
- opened
- reopened
- synchronize
jobs:
authorize:
environment: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository && 'external' || 'internal' }}
runs-on: ubuntu-latest
steps:
- run: true
build-test:
needs: authorize
uses: liquibase/build-logic/.github/workflows/os-extension-test.yml@main
secrets: inherit
with:
extraMavenArgs: -Dtest="RedshiftDatabaseTest"
prepare-database:
name: Clean and initialize database
needs: build-test
runs-on: ubuntu-latest
env:
LPM_VERSION: 0.2.3
strategy:
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download Artifacts
uses: actions/download-artifact@v4
with:
name: liquibase-redshift-artifacts
- name: Extract Liquibase Redshift Artifacts version
run: |
version=$(ls liquibase-redshift*.pom | cut -d '-' -f3)
echo "Liquibase Redshift Artifacts version: $version"
echo "lb_redshift_jar=liquibase-redshift-$version-SNAPSHOT.jar" >> $GITHUB_ENV
- name: Install liquibase
run: |
wget -O- https://repo.liquibase.com/liquibase.asc | gpg --dearmor > liquibase-keyring.gpg && \
cat liquibase-keyring.gpg | sudo tee /usr/share/keyrings/liquibase-keyring.gpg > /dev/null && \
echo 'deb [arch=amd64 signed-by=/usr/share/keyrings/liquibase-keyring.gpg] https://repo.liquibase.com stable main' | sudo tee /etc/apt/sources.list.d/liquibase.list
sudo apt-get update
sudo apt-get install liquibase
# FIXME the redshift jar version should come from the pom.xml file
- name: Download AWS Redshift driver
run: wget https://s3.amazonaws.com/redshift-downloads/drivers/jdbc/2.1.0.14/redshift-jdbc42-2.1.0.14.jar
- name: Add Redshift extension and driver to liquibase classpath
run: |
cp redshift-jdbc42-2.1.0.14.jar src/test/resources/
cp ${{ env.lb_redshift_jar }} src/test/resources/
- name: Setup Python
uses: actions/[email protected]
with:
python-version: '3.11.5'
- name: Set up Docker Buildx
uses: docker/setup-docker-action@v4
- name: Start & Configure LocalStack
env:
LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }}
GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
TH_REDSHIFT_PASSWORD: ${{ secrets.TH_REDSHIFT_PASSWORD }}
run: |
# Install LocalStack and supporting tools
pip install localstack awscli-local
# Pull the required LocalStack Pro image
docker pull localstack/localstack-pro
# Start LocalStack with custom Redshift support
DOCKER_FLAGS='-e LOCALSTACK_API_KEY=${{ secrets.LOCALSTACK_API_KEY }}' localstack start -d
# Wait for LocalStack to fully start
echo "Waiting for LocalStack startup..."
localstack wait -t 30
echo "Startup complete"
# Configure environment variables for Redshift
echo "TH_REDSHIFT_CLUSTER=test-redshift-cluster" >> $GITHUB_ENV
echo "TH_REDSHIFT_DB=test_db" >> $GITHUB_ENV
echo "TH_REDSHIFT_USER=admin" >> $GITHUB_ENV
echo "TH_REDSHIFT_PASSWORD=${{ secrets.TH_REDSHIFT_PASSWORD }}" >> $GITHUB_ENV
echo "TH_REDSHIFT_PORT=4510" >> $GITHUB_ENV
echo "TH_REDSHIFT_REGION=us-east-1" >> $GITHUB_ENV
- name: Setup Redshift Cluster
run: |
# Set up Redshift cluster in LocalStack
echo "Creating Redshift cluster in LocalStack..."
awslocal redshift create-cluster \
--cluster-identifier ${{ env.TH_REDSHIFT_CLUSTER }} \
--db-name ${{ env.TH_REDSHIFT_DB }} \
--master-username ${{ env.TH_REDSHIFT_USER }} \
--master-user-password ${{ env.TH_REDSHIFT_PASSWORD }} \
--node-type dc2.large \
--number-of-nodes 2
# Fetch Redshift cluster endpoint
echo "Fetching Redshift cluster endpoint..."
REDSHIFT_ENDPOINT=$(awslocal redshift describe-clusters \
--cluster-identifier ${{ env.TH_REDSHIFT_CLUSTER }} \
--query "Clusters[0].Endpoint.Address" \
--output text)
# Construct Redshift URL
REDSHIFT_URL="jdbc:redshift://${REDSHIFT_ENDPOINT}:${{ env.TH_REDSHIFT_PORT }}/${TH_REDSHIFT_DB}"
echo "REDSHIFT_URL=${REDSHIFT_URL}" >> $GITHUB_ENV
echo "Redshift cluster setup complete."
echo "Redshift URL: $REDSHIFT_URL"
- name: Veirfy Redshift
run: |
awslocal redshift list-clusters
aws redshift describe-clusters --endpoint-url=${REDSHIFT_ENDPOINT}
- name: Clean AWS Redshift Database
run: |
liquibase --logLevel=DEBUG --username="${{ env.TH_REDSHIFT_USER }}" \
--classpath="src/test/resources/${{ env.lb_redshift_jar }}:src/test/resources/redshift-jdbc42-2.1.0.14.jar" \
--driver=com.amazon.redshift.jdbc42.Driver \
--password="${{ env.TH_REDSHIFT_PASSWORD }}" \
--url="${{ env.REDSHIFT_URL }}" dropAll
- name: Init Database
run: |
liquibase --classpath="src/test/resources/${{ env.lb_redshift_jar }}:src/test/resources/redshift-jdbc42-2.1.0.14.jar" \
--changeLogFile="harness.initScript.sql" \
--username="${{ env.TH_REDSHIFT_USER }}" \
--password="${{ env.TH_REDSHIFT_PASSWORD }}" \
--url="${{ env.REDSHIFT_URL }}" update
# integration-test:
# name: Test Harness for Redshift ${{ matrix.redshift }}
# needs: prepare-database
# runs-on: ubuntu-latest
# strategy:
# fail-fast: false
# matrix:
# redshift: [ "" ]
# steps:
# - uses: actions/checkout@v2
# - name: Set up JDK
# uses: actions/setup-java@v3
# with:
# java-version: 11
# distribution: 'temurin'
# cache: 'maven'
# - name: Build Cache
# uses: actions/[email protected]
# with:
# key: build-${{ github.run_number }}-${{ github.run_attempt }}
# path: |
# **/target/**
# ~/.m2/repository/org/liquibase/
# - name: Harness Test Run
# run: mvn -Dtest="LiquibaseHarnessSuiteIT" -DdbName=redshift -DdbUsername=${{secrets.TH_DB_ADMIN}} -DdbPassword=${{secrets.TH_DB_PASSWD}} -DdbUrl=${{secrets.TH_REDSHIFTURL}} test
# - name: Foundational Harness Test Run
# run: mvn -Dtest="LiquibaseHarnessFoundationalSuiteTest" -DdbName=redshift -DdbUsername=${{secrets.TH_DB_ADMIN}} -DdbPassword=${{secrets.TH_DB_PASSWD}} -DdbUrl=${{secrets.TH_REDSHIFTURL}} test
# - name: Advanced Harness Test Run
# run: mvn -Dtest="LiquibaseHarnessAdvancedSuiteTest" -DdbName=redshift -DdbUsername=${{secrets.TH_DB_ADMIN}} -DdbPassword=${{secrets.TH_DB_PASSWD}} -DdbUrl=${{secrets.TH_REDSHIFTURL}} test
# - name: Archive Redshift Test Results
# if: ${{ always() }}
# uses: actions/upload-artifact@v3
# with:
# name: redshift-test-results
# path: build/spock-reports
# dependabot-automerge:
# needs: build-test
# uses: liquibase/build-logic/.github/workflows/dependabot-automerge.yml@main
# secrets: inherit