/
config.yml
215 lines (204 loc) · 6.88 KB
/
config.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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
version: 2.1
orbs:
codecov: codecov/codecov@1.1.1
commands:
create-typeorm-config:
parameters:
databases:
type: string
default: ""
steps:
- when:
condition:
equal: [ << parameters.databases >>, "" ]
steps:
- run:
name: "Enabling Databases in ORM config"
command: cp ormconfig.circleci-common.json ./ormconfig.json
- unless:
condition:
equal: [ << parameters.databases >>, "" ]
steps:
- run:
name: "Enabling Databases in ORM config"
command: >
cat ormconfig.circleci-common.json \
| jq 'map(.skip = if (.name | IN($ARGS.positional[])) then false else true end)' --args << parameters.databases >> \
> ormconfig.json
- run:
name: Check ORMConfig
command: cat ormconfig.json
install-packages:
parameters:
cache-key:
type: string
default: ""
steps:
- restore_cache:
name: Restore node_modules cache
key: node_modules-<< parameters.cache-key >>-{{ checksum "package-lock.json" }}
- run:
name: Verify `package.json` and `package-lock.json` are in sync
command: npx lock-verify
- run:
# This uses `npm install` instead of `npm ci`
# because of https://github.com/npm/cli/issues/558
name: Install Node Packages
command: |
if [ ! -d node_modules ]; then
npm install
fi
- run:
# This is pretty terrible but OracleDB requires you to grab the binaries OOB
# from the normal installation, place them in the LD Path
# also - not super well documented - grab `libaio` as well
# Because this is technically the same image as the runner we'll snag
# the libaio1 and place them in the same instantclient directory.
name: Download Required OracleDB Binaries
command: |
if [ ! -d node_modules/oracledb/instantclient_19_8 ]; then
curl -sf -o node_modules/oracledb/instantclient.zip $BLOB_URL
unzip -qqo node_modules/oracledb/instantclient.zip -d node_modules/oracledb/
rm node_modules/oracledb/instantclient.zip
DEBIAN_FRONTEND=noninteractive sudo apt-get -qq -y install libaio1
cp /lib/*/libaio.so.* node_modules/oracledb/instantclient_19_8/
fi
environment:
BLOB_URL: https://download.oracle.com/otn_software/linux/instantclient/19800/instantclient-basiclite-linux.x64-19.8.0.0.0dbru.zip
- save_cache:
name: Save node_modules cache
key: node_modules-{{ checksum "package-lock.json" }}
paths:
- node_modules
jobs:
lint:
working_directory: ~/typeorm
docker:
- image: circleci/node:12
steps:
- checkout
- install-packages:
cache-key: node12
- run: npm run lint
build:
working_directory: ~/typeorm
docker:
- image: circleci/node:12
steps:
- checkout
- install-packages:
cache-key: node12
- run: npm run compile
- persist_to_workspace:
root: ~/typeorm
paths:
- build/
test:
parameters:
databases:
type: string
default: ""
node-version:
type: string
default: "10"
working_directory: ~/typeorm
docker:
- image: circleci/node:<< parameters.node-version >>
steps:
- checkout
- setup_remote_docker
- attach_workspace:
at: ~/typeorm
- create-typeorm-config:
databases: << parameters.databases >>
- run:
name: Start all Relevant Services
command: |
SERVICES=$(
npx js-yaml ./docker-compose.yml \
| jq -r '.services | keys | map(select(. | IN($ARGS.positional[]))) | join(" ")' --args << parameters.databases >>
)
docker-compose --project-name typeorm --no-ansi up --detach $SERVICES
- install-packages:
cache-key: node<< parameters.node-version >>
- run:
name: Set up TypeORM Test Runner
command: |
docker run \
--volume /typeorm \
--name typeorm-code \
--workdir /typeorm \
circleci/node:<< parameters.node-version >> \
/bin/bash -c "sudo chmod 777 /typeorm && sudo chown circleci /typeorm"
docker cp ./ typeorm-code:/typeorm
- run:
name: Wait for Services to be Available
command: |
COMMANDS=$(
cat ormconfig.json \
| jq -r '
map(select(.skip == false)
| select(.host)
| select(.port)
| "nc -z " + .host + " " + (.port|tostring) + " && echo " + .host + " " + (.port|tostring) + " is up")
| join(" && ")
'
)
echo "Running '$COMMANDS'"
docker run \
--network typeorm_default \
--tty \
ubuntu:trusty \
timeout 60 sh -c "until ($COMMANDS); do echo \"Waiting for Services to be Available ...\"; sleep 5; done"
# Download and cache dependencies
- run:
name: "Run Tests with Coverage"
command: |
docker run \
--env LD_LIBRARY_PATH='/typeorm/node_modules/oracledb/instantclient_19_8/:$LD_LIBRARY_PATH' \
--volumes-from typeorm-code \
--network typeorm_default \
--tty \
--workdir /typeorm \
--name typeorm-testrunner \
circleci/node:<< parameters.node-version >> \
npx nyc npm run test-fast
docker cp typeorm-testrunner:/typeorm/coverage/ ./
- run:
name: Stop all Relevant Services
command: docker-compose down
- store_artifacts:
path: coverage
- codecov/upload
workflows:
version: 2
test:
jobs:
- lint
- build
- test:
name: test (mysql mariadb postgres mssql mongodb sqlite better-sqlite3 sqljs) - Node v<< matrix.node-version >>
requires:
- lint
- build
databases: "mysql mariadb postgres mssql mongodb sqlite better-sqlite3 sqljs"
matrix:
parameters:
node-version:
- "10"
- "12"
- "13"
- test:
name: test (cockroachdb) - Node v12
requires:
- lint
- build
databases: "cockroachdb"
node-version: "12"
- test:
name: test (oracle) - Node v12
requires:
- lint
- build
databases: "oracle"
node-version: "12"