forked from keyshade-xyz/keyshade
-
Notifications
You must be signed in to change notification settings - Fork 0
142 lines (115 loc) · 3.83 KB
/
Copy pathvalidate-api.yaml
File metadata and controls
142 lines (115 loc) · 3.83 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
name: Validate API
on:
push:
branches:
- '!develop'
- '!main'
paths: ['apps/api/**', '.github/workflows/validate-api.yaml']
pull_request:
paths: ['apps/api/**', '.github/workflows/validate-api.yaml']
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
validate-node-build:
runs-on: ubuntu-latest
timeout-minutes: 30
name: Validate API (Node)
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 9.2.0
run_install: false
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v4
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install packages
run: |
pnpm i
- name: Lint
run: |
pnpm run lint:api
- name: Build deps
run: |
pnpm run db:generate-types
pnpm run build:schema
- name: Unit tests
run: |
pnpm run db:generate-types
pnpm run unit:api
- name: E2E tests
env:
REDIS_URL: redis://localhost:6379
JWT_SECRET: secret
run: pnpm run e2e:api
- name: Upload e2e test coverage reports to Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
version: 'v0.1.15'
with:
flags: api-e2e-tests
files: /coverage/apps/api/coverage-final.json
validate-docker-build:
runs-on: ubuntu-latest
timeout-minutes: 15
name: Validate API (Docker)
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build API image
env:
GITHUB_SHA: ${{ github.sha }}
run: |
docker build -t keyshade/api:ci-${GITHUB_SHA} -f apps/api/Dockerfile .
- name: Verify API image
run: docker image inspect keyshade/api:ci-${{ github.sha }}
- name: Start API and dependencies
env:
GITHUB_SHA: ${{ github.sha }}
run: |
# Start db, redis, and api-ci services
docker compose -f docker-compose-test.yml --profile ci-api up -d
# Wait for API to be healthy (Docker Compose will wait for dependencies)
echo "Waiting for API to be healthy..."
timeout 60s bash -c 'until docker inspect --format="{{.State.Health.Status}}" api-ci 2>/dev/null | grep -q "healthy"; do sleep 2; echo "Waiting..."; done'
echo "API is healthy"
- name: API health check
run: |
curl -fsSL "http://127.0.0.1:4200/api/health" || {
echo "Health check failed"
docker compose -f docker-compose-test.yml logs api-ci
exit 1
}
echo "Health check passed"
- name: Cleanup
if: always()
env:
GITHUB_SHA: ${{ github.sha }}
run: |
set -euo pipefail
if [ "${{ job.status }}" != 'success' ]; then
echo "=== Docker Compose Logs ==="
docker compose -f docker-compose-test.yml --profile ci-api logs
fi
docker compose -f docker-compose-test.yml --profile ci-api down -v --remove-orphans || true
docker image rm -f keyshade/api:ci-${GITHUB_SHA} || true