forked from asgardeo/thunder
-
Notifications
You must be signed in to change notification settings - Fork 0
231 lines (204 loc) · 7.71 KB
/
postgres-tests.yml
File metadata and controls
231 lines (204 loc) · 7.71 KB
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
# This workflow runs PostgreSQL integration tests
# Triggers:
# - On demand (workflow_dispatch)
# - Daily at 12 AM Local Time(SL)
# - During release (when release workflow completes)
name: 🐘 PostgreSQL Integration Tests
on:
workflow_dispatch:
inputs:
distribution-url:
description: 'URL to download Distribution (optional, will build if not provided)'
required: false
type: string
version:
description: 'Version to test (optional, defaults to latest)'
required: false
type: string
schedule:
# Run daily at 12 AM Local Time(SL)
- cron: '30 18 * * *'
workflow_run:
workflows: ["🚀 Release Builder"]
types: [completed]
branches: [main]
env:
GOFLAGS: "-mod=readonly"
PRODUCT_NAME: "Thunder"
PRODUCT_NAME_LOWER: "thunder"
jobs:
dependency-guard:
name: 🛡️ Dependency Guard
uses: ./.github/workflows/dependency-guard.yml
with:
detection-mode: commit
build-if-needed:
name: 🔨 Build Distribution (if needed)
needs: dependency-guard
runs-on: ubuntu-latest
if: ${{ always() && (needs.dependency-guard.result == 'success' || needs.dependency-guard.result == 'skipped') && (github.event.inputs.distribution-url == '' || github.event.inputs.distribution-url == null) }}
outputs:
distribution-path: ${{ steps.build.outputs.distribution-path }}
steps:
- name: 📥 Checkout Code
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
with:
fetch-depth: 0
- name: ⚙️ Set up Go Environment
uses: ./.github/actions/setup-go
- name: 🗄️ Cache Go Modules
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4
id: cache-go-modules
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-modules-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-modules-
- name: 📦 Install Dependencies
run: |
cd backend
go mod download
cd ../tests/integration
go mod download
- name: 🏷️ Set Version (if provided)
if: ${{ github.event.inputs.version != '' && github.event.inputs.version != null }}
run: |
VERSION="${{ github.event.inputs.version }}"
echo "$VERSION" > version.txt
echo "Set version to: $VERSION"
- name: 🧹 Clean Previous Builds
run: make clean
- name: 🔨 Build Product with Coverage
id: build
run: |
set -e
make build_with_coverage_only OS=$(go env GOOS) ARCH=$(go env GOARCH)
# Find the built distribution
DIST_PATH=$(find target/dist -name "$PRODUCT_NAME_LOWER-*.zip" | head -1)
echo "distribution-path=$DIST_PATH" >> $GITHUB_OUTPUT
echo "Built distribution: $DIST_PATH"
- name: 📦 Upload Built Distribution
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
with:
name: product-distribution
path: target/dist/*.zip
if-no-files-found: error
download-distribution:
name: 📥 Download Distribution
runs-on: ubuntu-latest
if: ${{ github.event.inputs.distribution-url != '' && github.event.inputs.distribution-url != null }}
outputs:
distribution-path: ${{ steps.download.outputs.distribution-path }}
steps:
- name: 📥 Download Distribution
id: download
run: |
DIST_URL="${{ github.event.inputs.distribution-url }}"
DIST_FILENAME="product-distribution.zip"
echo "Downloading distribution from: $DIST_URL"
curl -L -o "$DIST_FILENAME" "$DIST_URL"
# Verify the download
if [ ! -f "$DIST_FILENAME" ]; then
echo "❌ Failed to download distribution"
exit 1
fi
echo "✅ Distribution downloaded successfully"
echo "distribution-path=$DIST_FILENAME" >> $GITHUB_OUTPUT
test-postgres:
name: 🧪 PostgreSQL Integration Tests
runs-on: ubuntu-latest
needs: [dependency-guard, build-if-needed, download-distribution]
if: always() && (needs.dependency-guard.result == 'success' || needs.dependency-guard.result == 'skipped') && (needs.build-if-needed.result == 'success' || needs.download-distribution.result == 'success')
services:
postgres:
image: postgres:latest
env:
POSTGRES_USER: asgthunder
POSTGRES_PASSWORD: asgthunder
POSTGRES_DB: thunderdb
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: 📥 Checkout Code
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- name: ⚙️ Set up Go Environment
uses: ./.github/actions/setup-go
- name: 🗄️ Cache Go Modules
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4
id: cache-go-modules
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-modules-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-modules-
- name: 📥 Download Built Distribution
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
with:
name: product-distribution
path: target/dist/
- name: 📦 Install Dependencies
run: |
cd backend
go mod download
cd ../tests/integration
go mod download
- name: 📝 Configure Test Database
run: |
chmod +x tests/integration/resources/scripts/setup-test-config.sh
./tests/integration/resources/scripts/setup-test-config.sh
env:
DB_TYPE: postgres
- name: 🧪 Run PostgreSQL Integration Tests
uses: ./.github/actions/run-integration-tests
with:
database-type: postgres
coverage-enabled: true
- name: 📊 Upload Coverage Report
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
if: always()
with:
name: postgres-coverage-report
path: |
target/coverage_integration_postgres.out
target/coverage_integration_postgres.html
if-no-files-found: ignore
notify-results:
name: 📢 Notify Test Results
runs-on: ubuntu-latest
needs: [test-postgres]
if: always()
steps:
- name: 📢 Notify Success
if: needs.test-postgres.result == 'success'
run: |
echo "✅ PostgreSQL integration tests completed successfully!"
echo "Triggered by: ${{ github.event_name }}"
if [ "${{ github.event_name }}" == "schedule" ]; then
echo "📅 Daily PostgreSQL test run completed"
elif [ "${{ github.event_name }}" == "workflow_run" ]; then
echo "🚀 PostgreSQL tests completed after release"
else
echo "🔧 Manual PostgreSQL test run completed"
fi
- name: 📢 Notify Failure
if: needs.test-postgres.result == 'failure'
run: |
echo "❌ PostgreSQL integration tests failed!"
echo "Triggered by: ${{ github.event_name }}"
if [ "${{ github.event_name }}" == "schedule" ]; then
echo "📅 Daily PostgreSQL test run failed"
elif [ "${{ github.event_name }}" == "workflow_run" ]; then
echo "🚀 PostgreSQL tests failed after release"
else
echo "🔧 Manual PostgreSQL test run failed"
fi
exit 1