Repository navigation
268 lines (229 loc) · 9.28 KB
/
Copy pathmain.yaml
File metadata and controls
268 lines (229 loc) · 9.28 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
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
name: Main CI/CD Pipeline
on:
push:
branches:
- develop-graphdb
- master-graphdb
pull_request:
env:
REGISTRY: ghcr.io
# Docker registry names must be lowercase
IMAGE_PREFIX: ghcr.io/swissfederalarchives/lindas-cube-creator
jobs:
# Step 1: Linting
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: "yarn"
- name: Install dependencies
run: yarn install --immutable
- name: Run lint
run: |
yarn lint
yarn workspace @cube-creator/ui lint
# Step 2: Unit Tests
unit-tests:
name: Unit Tests
runs-on: ubuntu-22.04
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: "yarn"
- name: Install dependencies
run: yarn install --immutable
- name: Run unit tests
run: yarn test
- name: Upload coverage
if: always()
uses: codecov/codecov-action@v4
continue-on-error: true
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage/**/*.lcov
# Step 3: Build, Smoke Tests, and E2E Tests
integration-tests:
name: Smoke & E2E Tests
runs-on: ubuntu-22.04
needs: [lint, unit-tests]
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: "yarn"
- name: Install dependencies
run: yarn install --immutable
- name: Build Docker images
run: docker compose -f docker-compose.e2e.yml build --parallel
- name: Start services
run: docker compose -f docker-compose.e2e.yml up -d
- name: Wait for services to be healthy
run: |
echo "⏳ Waiting for all services to be healthy (max 5 minutes)..."
timeout 300 sh -c 'until [ $(docker compose -f docker-compose.e2e.yml ps --format json | grep -c "\"Health\":\"healthy\"") -ge 4 ]; do
echo "⏳ Waiting... ($(docker compose -f docker-compose.e2e.yml ps --format json | grep -c "\"Health\":\"healthy\"") / 4 services healthy)";
sleep 5;
done'
echo "✅ All services are healthy!"
- name: Run smoke tests
run: |
cd smoke-test
chmod +x smoke-tests.sh
./smoke-tests.sh
- name: Run API E2E tests
run: yarn test:e2e
- name: Run UI Smoke Tests
run: cd ui && npx cypress run --spec "tests/e2e/specs/ui-smoke.spec.ts"
# Full UI E2E tests require OIDC authentication - run locally with: cd ui && yarn test:e2e
- name: Show logs on failure
if: failure()
run: docker compose -f docker-compose.e2e.yml logs
- name: Cleanup
if: always()
run: docker compose -f docker-compose.e2e.yml down -v
# Step 4: Build and Publish Docker Images
build-and-publish:
name: Build & Publish Docker Images
runs-on: ubuntu-latest
needs: [integration-tests]
if: github.ref == 'refs/heads/develop-graphdb' && github.event_name == 'push'
timeout-minutes: 45
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix:
component: [app, api, cli]
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get component version
id: version
run: |
case "${{ matrix.component }}" in
app) VERSION=$(node -p "require('./ui/package.json').version") ;;
api) VERSION=$(node -p "require('./apis/core/package.json').version") ;;
cli) VERSION=$(node -p "require('./cli/package.json').version") ;;
esac
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Determine environment and tags
id: tags
run: |
COMPONENT="${{ matrix.component }}"
VERSION="${{ steps.version.outputs.version }}"
IMAGE="${{ env.IMAGE_PREFIX }}-${COMPONENT}"
TIMESTAMP=$(date -u +%Y%m%d%H%M%S)
if [[ "${{ github.ref }}" == "refs/heads/develop-graphdb" ]]; then
TAGS="${IMAGE}:graphdb-test-${VERSION},${IMAGE}:graphdb-test-latest,${IMAGE}:graphdb-test-${TIMESTAMP}"
ENV="test"
elif [[ "${{ github.ref }}" == "refs/heads/master-graphdb" ]]; then
VERSION_MAJOR=$(echo $VERSION | cut -d. -f1)
VERSION_MINOR=$(echo $VERSION | cut -d. -f1-2)
TAGS="${IMAGE}:graphdb-prod-${VERSION},${IMAGE}:graphdb-v${VERSION},${IMAGE}:graphdb-${VERSION},${IMAGE}:graphdb-${VERSION_MINOR},${IMAGE}:graphdb-${VERSION_MAJOR},${IMAGE}:graphdb-latest"
ENV="production"
fi
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
echo "environment=${ENV}" >> $GITHUB_OUTPUT
- name: Build and push Docker image - app
if: matrix.component == 'app'
uses: docker/build-push-action@v6
with:
file: ./app.Dockerfile
context: .
push: true
tags: ${{ steps.tags.outputs.tags }}
build-args: |
COMMIT=${{ github.sha }}
PUBLIC_PATH=/app/
cache-from: type=gha,scope=${{ matrix.component }}
cache-to: type=gha,mode=max,scope=${{ matrix.component }}
labels: |
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.version=${{ steps.version.outputs.version }}
environment=${{ steps.tags.outputs.environment }}
- name: Build and push Docker image - api/cli
if: matrix.component != 'app'
uses: docker/build-push-action@v6
with:
file: ./${{ matrix.component }}.Dockerfile
context: .
push: true
tags: ${{ steps.tags.outputs.tags }}
build-args: |
COMMIT=${{ github.sha }}
cache-from: type=gha,scope=${{ matrix.component }}
cache-to: type=gha,mode=max,scope=${{ matrix.component }}
labels: |
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.version=${{ steps.version.outputs.version }}
environment=${{ steps.tags.outputs.environment }}
- name: Create Sentry release
if: steps.tags.outputs.environment == 'production'
uses: getsentry/action-release@v1
continue-on-error: true
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_ORG: zazuko
SENTRY_PROJECT: lindas-cube-creator-${{ matrix.component }}
with:
version_prefix: lindas-cube-creator-${{ matrix.component }}@
version: ${{ steps.version.outputs.version }}
ignore_empty: true
- name: Output build summary
run: |
echo "## Docker Image Built" >> $GITHUB_STEP_SUMMARY
echo "**Component:** ${{ matrix.component }}" >> $GITHUB_STEP_SUMMARY
echo "**Version:** ${{ steps.version.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "**Environment:** ${{ steps.tags.outputs.environment }}" >> $GITHUB_STEP_SUMMARY
echo "**Tags:** \`${{ steps.tags.outputs.tags }}\`" >> $GITHUB_STEP_SUMMARY
# Final Status Report
status:
name: Pipeline Status
runs-on: ubuntu-latest
needs: [lint, unit-tests, integration-tests, build-and-publish]
if: always()
steps:
- name: Report Status
run: |
echo "# CI/CD Pipeline Results" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Stage | Status |" >> $GITHUB_STEP_SUMMARY
echo "|-------|--------|" >> $GITHUB_STEP_SUMMARY
echo "| Lint | **${{ needs.lint.result }}** |" >> $GITHUB_STEP_SUMMARY
echo "| Unit Tests | **${{ needs.unit-tests.result }}** |" >> $GITHUB_STEP_SUMMARY
echo "| Integration Tests | **${{ needs.integration-tests.result }}** |" >> $GITHUB_STEP_SUMMARY
echo "| Build & Publish | **${{ needs.build-and-publish.result }}** |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [[ "${{ needs.lint.result }}" == "success" ]] && \
[[ "${{ needs.unit-tests.result }}" == "success" ]] && \
[[ "${{ needs.integration-tests.result }}" == "success" ]]; then
echo "✅ **Pipeline Successful** - All tests passed!" >> $GITHUB_STEP_SUMMARY
if [[ "${{ github.ref }}" == "refs/heads/develop-graphdb" ]] && [[ "${{ needs.build-and-publish.result }}" == "success" ]]; then
echo "🚀 **Docker images published to GHCR**" >> $GITHUB_STEP_SUMMARY
fi
else
echo "❌ **Pipeline Failed** - Please check the failed stages above" >> $GITHUB_STEP_SUMMARY
fi