-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
166 lines (143 loc) · 5.51 KB
/
e2e-test.yml
File metadata and controls
166 lines (143 loc) · 5.51 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
name: E2E Test
on:
push:
branches:
- next
paths-ignore:
- '**/*.md'
pull_request:
branches:
- next
paths-ignore:
- '**/*.md'
concurrency:
group: ${{ github.workflow }}-#${{ github.event.pull_request.number || github.head_ref || github.ref }}
cancel-in-progress: true
defaults:
run:
shell: bash
jobs:
e2e-test:
name: ${{ matrix.project.name }} E2E test
permissions:
contents: read
packages: read
runs-on: ubuntu-latest
services:
mysql:
image: mysql:5.7
env:
MYSQL_ALLOW_EMPTY_PASSWORD: true
MYSQL_DATABASE: cnpmcore
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=5
redis:
image: redis
ports:
- 6379:6379
strategy:
fail-fast: false
matrix:
project:
- name: cnpmcore
node-version: 24
command: |
npm install
npm run lint -- --quiet
npm run typecheck
npm run build
npm run prepublishOnly
# Clean build artifacts to avoid double-loading (src + dist)
npm run clean
# Run the full test suite
echo "Preparing databases..."
mysql -h 127.0.0.1 -u root -e "CREATE DATABASE IF NOT EXISTS cnpmcore_unittest"
CNPMCORE_DATABASE_NAME=cnpmcore_unittest bash ./prepare-database-mysql.sh
CNPMCORE_DATABASE_NAME=cnpmcore bash ./prepare-database-mysql.sh
npm run test:local
# Deployment test: start the app and verify it boots correctly
npm run clean
npm run tsc:prod
# Overlay compiled .js onto source locations so both egg loader
# and tegg module scanner find .js files at the expected paths
cp -r dist/* .
rm -rf dist
echo "Preparing database for deployment test..."
mysql -h 127.0.0.1 -u root -e "CREATE DATABASE IF NOT EXISTS cnpmcore_unittest"
CNPMCORE_DATABASE_NAME=cnpmcore_unittest bash ./prepare-database-mysql.sh
CNPMCORE_DATABASE_NAME=cnpmcore bash ./prepare-database-mysql.sh
EGG_TS_ENABLE=false npx eggctl start --port=7001 --env=unittest --daemon
HEALTH_URL="http://127.0.0.1:7001/"
START_TIME=$(date +%s)
TIMEOUT=120
STATUS=""
READY=0
echo "Waiting for application to become healthy at ${HEALTH_URL} (timeout: ${TIMEOUT}s)..."
while true; do
# Capture response body and status code
STATUS=$(curl -s -o /tmp/cnpmcore-health-response -w "%{http_code}" "${HEALTH_URL}" || echo "000")
echo "Health check attempt at $(date): status=${STATUS}"
if [ "${STATUS}" = "200" ]; then
echo "Health check succeeded with status 200"
READY=1
break
fi
NOW=$(date +%s)
ELAPSED=$((NOW - START_TIME))
if [ "${ELAPSED}" -ge "${TIMEOUT}" ]; then
echo "Health check timed out after ${ELAPSED}s with last status ${STATUS}"
break
fi
sleep 5
done
npx eggctl stop
if [ "${READY}" != "1" ]; then
echo "Health check failed; last HTTP status: ${STATUS}"
echo "Last health endpoint response body (if any):"
cat /tmp/cnpmcore-health-response 2>/dev/null || echo "<no response body captured>"
echo "Recent error logs (if any):"
cat logs/cnpmcore/common-error.log 2>/dev/null || true
exit 1
fi
- name: examples
node-version: 24
command: |
# examples/helloworld https://github.com/eggjs/examples/blob/master/helloworld/package.json
cd helloworld
npm install
npm run lint
npm run test
npm run prepublishOnly
cd ..
# examples/hello-tegg https://github.com/eggjs/examples/blob/master/hello-tegg/package.json
cd hello-tegg
npm install
npm run lint
npm run test
npm run prepublishOnly
steps:
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
- uses: ./.github/actions/clone
with:
ecosystem-ci-project: ${{ matrix.project.name }}
- name: Setup utoo
uses: utooland/setup-utoo@3a51006d0b66afcc32d1b9177a4b200b74f4a8cb # main
- name: Set up Node.js
uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6
with:
node-version: ${{ matrix.project.node-version }}
- name: Install dependencies
run: ut install --from pnpm
- name: Build all packages
run: ut run build
- name: Pack packages into tgz
run: |
node ecosystem-ci/pack-all.mjs
- name: Override dependencies from tgz in ${{ matrix.project.name }}
working-directory: ecosystem-ci/${{ matrix.project.name }}
run: |
node ../patch-project.ts ${{ matrix.project.name }}
- name: Run e2e test commands in ${{ matrix.project.name }}
working-directory: ecosystem-ci/${{ matrix.project.name }}
run: ${{ matrix.project.command }}