|
| 1 | +version: 2.1 |
| 2 | + |
| 3 | +orbs: |
| 4 | + codecov: codecov/[email protected] |
| 5 | + |
| 6 | +commands: |
| 7 | + create-typeorm-config: |
| 8 | + parameters: |
| 9 | + databases: |
| 10 | + type: string |
| 11 | + default: "" |
| 12 | + steps: |
| 13 | + - when: |
| 14 | + condition: |
| 15 | + equal: [<< parameters.databases >>, ""] |
| 16 | + steps: |
| 17 | + - run: |
| 18 | + name: "Enabling Databases in ORM config" |
| 19 | + command: cp ormconfig.circleci-common.json ./ormconfig.json |
| 20 | + - unless: |
| 21 | + condition: |
| 22 | + equal: [<< parameters.databases >>, ""] |
| 23 | + steps: |
| 24 | + - run: |
| 25 | + name: "Enabling Databases in ORM config" |
| 26 | + command: > |
| 27 | + cat ormconfig.circleci-common.json \ |
| 28 | + | jq 'map(.skip = if (.name | IN($ARGS.positional[])) then false else true end)' --args << parameters.databases >> \ |
| 29 | + > ormconfig.json |
| 30 | + - run: |
| 31 | + name: Check ORMConfig |
| 32 | + command: cat ormconfig.json |
| 33 | + |
| 34 | + install-packages: |
| 35 | + parameters: |
| 36 | + cache-key: |
| 37 | + type: string |
| 38 | + default: "" |
| 39 | + steps: |
| 40 | + - restore_cache: |
| 41 | + name: Restore node_modules cache |
| 42 | + key: node_modules-<< parameters.cache-key >>-{{ checksum "package-lock.json" }} |
| 43 | + # removed this item because lock-verify is deprecated |
| 44 | + # - run: |
| 45 | + # name: Verify `package.json` and `package-lock.json` are in sync |
| 46 | + # command: npx lock-verify |
| 47 | + - run: |
| 48 | + # This uses `npm install` instead of `npm ci` |
| 49 | + # because of https://github.com/npm/cli/issues/558 |
| 50 | + name: Install Node Packages |
| 51 | + command: | |
| 52 | + if [ ! -d node_modules ]; then |
| 53 | + npm install |
| 54 | + npm install oracledb |
| 55 | + fi |
| 56 | + - run: |
| 57 | + # This is pretty terrible but OracleDB requires you to grab the binaries OOB |
| 58 | + # from the normal installation, place them in the LD Path |
| 59 | + # also - not super well documented - grab `libaio` as well |
| 60 | + # Because this is technically the same image as the runner we'll snag |
| 61 | + # the libaio1 and place them in the same instantclient directory. |
| 62 | + name: Download Required OracleDB Binaries |
| 63 | + command: | |
| 64 | + if [ ! -d node_modules/oracledb/instantclient_19_8 ]; then |
| 65 | + curl -sf -o node_modules/oracledb/instantclient.zip $BLOB_URL |
| 66 | + unzip -qqo node_modules/oracledb/instantclient.zip -d node_modules/oracledb/ |
| 67 | + rm node_modules/oracledb/instantclient.zip |
| 68 | +
|
| 69 | + sudo apt-get update -qq && sudo apt-get -qq -y install libaio1 |
| 70 | + (cp /lib/*/libaio.so.* node_modules/oracledb/instantclient_19_8/ || |
| 71 | + cp /usr/lib/*/libaio.so.* node_modules/oracledb/instantclient_19_8/) |
| 72 | + fi |
| 73 | + environment: |
| 74 | + BLOB_URL: https://download.oracle.com/otn_software/linux/instantclient/19800/instantclient-basiclite-linux.x64-19.8.0.0.0dbru.zip |
| 75 | + DEBIAN_FRONTEND: noninteractive |
| 76 | + - save_cache: |
| 77 | + name: Save node_modules cache |
| 78 | + key: node_modules-{{ checksum "package-lock.json" }} |
| 79 | + paths: |
| 80 | + - node_modules |
| 81 | + |
| 82 | +jobs: |
| 83 | + lint: |
| 84 | + working_directory: ~/typeorm |
| 85 | + docker: |
| 86 | + - image: cimg/node:16.20.0 |
| 87 | + steps: |
| 88 | + - checkout |
| 89 | + - install-packages: |
| 90 | + cache-key: node16 |
| 91 | + - run: npm run lint |
| 92 | + |
| 93 | + build: |
| 94 | + working_directory: ~/typeorm |
| 95 | + docker: |
| 96 | + - image: cimg/node:16.20.0 |
| 97 | + steps: |
| 98 | + - checkout |
| 99 | + - install-packages: |
| 100 | + cache-key: node16 |
| 101 | + - run: npm run compile |
| 102 | + - persist_to_workspace: |
| 103 | + root: ~/typeorm |
| 104 | + paths: |
| 105 | + - build/ |
| 106 | + |
| 107 | + test: |
| 108 | + parameters: |
| 109 | + databases: |
| 110 | + type: string |
| 111 | + default: "" |
| 112 | + node-version: |
| 113 | + type: string |
| 114 | + default: "16" |
| 115 | + working_directory: ~/typeorm |
| 116 | + docker: |
| 117 | + - image: cimg/node:<< parameters.node-version >> |
| 118 | + steps: |
| 119 | + - checkout |
| 120 | + - setup_remote_docker |
| 121 | + - attach_workspace: |
| 122 | + at: ~/typeorm |
| 123 | + - create-typeorm-config: |
| 124 | + databases: << parameters.databases >> |
| 125 | + - run: |
| 126 | + name: Start all Relevant Services |
| 127 | + command: | |
| 128 | + SERVICES=$( |
| 129 | + npx js-yaml ./docker-compose.yml \ |
| 130 | + | jq -r '.services | keys | map(select(. | IN($ARGS.positional[]))) | join(" ")' --args << parameters.databases >> |
| 131 | + ) |
| 132 | +
|
| 133 | + docker-compose --project-name typeorm --no-ansi up --detach $SERVICES |
| 134 | + - install-packages: |
| 135 | + cache-key: node<< parameters.node-version >> |
| 136 | + - run: |
| 137 | + name: Set up TypeORM Test Runner |
| 138 | + command: | |
| 139 | + docker run \ |
| 140 | + --volume /typeorm \ |
| 141 | + --name typeorm-code \ |
| 142 | + --workdir /typeorm \ |
| 143 | + cimg/node:<< parameters.node-version >> \ |
| 144 | + /bin/bash -c "sudo chmod 777 /typeorm && sudo chown circleci /typeorm" |
| 145 | + docker cp ./ typeorm-code:/typeorm |
| 146 | + - run: |
| 147 | + name: Wait for Services to be Available |
| 148 | + command: | |
| 149 | + COMMANDS=$( |
| 150 | + cat ormconfig.json \ |
| 151 | + | jq -r ' |
| 152 | + map(select(.skip == false) |
| 153 | + | select(.host) |
| 154 | + | select(.port) |
| 155 | + | "nc -z " + .host + " " + (.port|tostring) + " && echo " + .host + " " + (.port|tostring) + " is up" |
| 156 | + ) |
| 157 | + | join(" && ") |
| 158 | + ' |
| 159 | + ) |
| 160 | + echo "Running '$COMMANDS'" |
| 161 | +
|
| 162 | + docker run \ |
| 163 | + --network typeorm_default \ |
| 164 | + --tty \ |
| 165 | + ubuntu:trusty \ |
| 166 | + timeout 60 sh -c "until ($COMMANDS); do echo \"Waiting for Services to be Available ...\"; sleep 5; done" |
| 167 | + - run: |
| 168 | + name: "Wait for OracleDB to be Available" |
| 169 | + command: | |
| 170 | + COMMANDS=$( |
| 171 | + cat ormconfig.json \ |
| 172 | + | jq -r ' |
| 173 | + map(select(.skip == false) |
| 174 | + | select(.name == "oracle") |
| 175 | + | "sleep 60" |
| 176 | + ) |
| 177 | + | join(" && ") |
| 178 | + ' |
| 179 | + ) |
| 180 | + if [ ! -z "$COMMANDS" ]; then |
| 181 | + echo "$COMMANDS seconds to wait for oracledb"; |
| 182 | + $COMMANDS |
| 183 | + fi |
| 184 | +
|
| 185 | + # Download and cache dependencies |
| 186 | + - run: |
| 187 | + name: "Run Tests with Coverage" |
| 188 | + |
| 189 | + command: | |
| 190 | + docker run \ |
| 191 | + --env npm_config_yes='true' \ |
| 192 | + --env LD_LIBRARY_PATH='/typeorm/node_modules/oracledb/instantclient_19_8/:$LD_LIBRARY_PATH' \ |
| 193 | + --volumes-from typeorm-code \ |
| 194 | + --network typeorm_default \ |
| 195 | + --tty \ |
| 196 | + --workdir /typeorm \ |
| 197 | + --name typeorm-testrunner \ |
| 198 | + cimg/node:<< parameters.node-version >> \ |
| 199 | + npx nyc npm run test-fast |
| 200 | +
|
| 201 | + docker cp typeorm-testrunner:/typeorm/coverage/ ./ |
| 202 | + - run: |
| 203 | + name: Stop all Relevant Services |
| 204 | + command: docker-compose down |
| 205 | + - store_artifacts: |
| 206 | + path: coverage |
| 207 | + - codecov/upload |
| 208 | + |
| 209 | +workflows: |
| 210 | + version: 2 |
| 211 | + test: |
| 212 | + jobs: |
| 213 | + - lint |
| 214 | + - build |
| 215 | + - test: |
| 216 | + name: test (mysql mariadb postgres mssql mongodb sqlite better-sqlite3 sqljs) - Node v<< matrix.node-version >> |
| 217 | + requires: |
| 218 | + - lint |
| 219 | + - build |
| 220 | + databases: "mysql mariadb postgres mssql mongodb sqlite better-sqlite3 sqljs" |
| 221 | + matrix: |
| 222 | + parameters: |
| 223 | + node-version: |
| 224 | + - "14.21.3" |
| 225 | + - "16.20.0" |
| 226 | + - test: |
| 227 | + name: test (cockroachdb) - Node v16 |
| 228 | + requires: |
| 229 | + - lint |
| 230 | + - build |
| 231 | + databases: "cockroachdb" |
| 232 | + node-version: "16.20.0" |
| 233 | + - test: |
| 234 | + name: test (oracle) - Node v16 |
| 235 | + requires: |
| 236 | + - lint |
| 237 | + - build |
| 238 | + databases: "oracle" |
| 239 | + node-version: "16.20.0" |
| 240 | + - test: |
| 241 | + name: test (postgres 12) - Node v16 |
| 242 | + requires: |
| 243 | + - lint |
| 244 | + - build |
| 245 | + databases: "postgres-12" |
| 246 | + node-version: "16.20.0" |
0 commit comments