From 468ebc9726f4a4c0dce76d80a5babc4b96eafa3f Mon Sep 17 00:00:00 2001 From: Matt Bretl Date: Thu, 1 Dec 2022 08:20:46 -0800 Subject: [PATCH] chore(ci): replace CircleCI with Github Actions workflow (#187) - Add a GitHub Actions config for running tests, typechecking and linting - Test against all supported versions of Postgres (11-15) and Node.js (14-18) - Remove the CircleCI config - Format with prettier --- .circleci/config.yml | 118 ------------------ .github/workflows/ci.yml | 89 +++++++++++++ .../docker-entrypoint-initdb.d/010-setup.sh | 4 + .prettierrc.json | 2 +- .vscode/launch.json | 32 ++--- __tests__/integration/schema/core.ts | 32 ++--- package.json | 5 +- 7 files changed, 133 insertions(+), 149 deletions(-) delete mode 100644 .circleci/config.yml create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/ci/docker-entrypoint-initdb.d/010-setup.sh diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index ff0c42b..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,118 +0,0 @@ -version: 2 -jobs: - node12_pg10: - docker: - - image: circleci/node:12 - - image: circleci/postgres:10 - environment: - POSTGRES_HOST_AUTH_METHOD: trust - POSTGRES_USER: circleci - POSTGRES_DB: circle_test - LC_COLLATE: C - steps: - - checkout - - run: sudo apt update - - run: sudo apt install -y postgresql-client - - restore_cache: - keys: - - yarn-packages-{{ checksum "yarn.lock" }} - - run: - command: yarn install --frozen-lockfile - - save_cache: - key: yarn-packages-{{ checksum "yarn.lock" }} - paths: - - ~/.cache/yarn - - run: yarn lint - - run: - command: yarn test - environment: - TEST_DATABASE_URL: postgres://circleci@localhost:5432/circle_test - node12_pg11: - docker: - - image: circleci/node:12 - - image: circleci/postgres:11 - environment: - POSTGRES_HOST_AUTH_METHOD: trust - POSTGRES_USER: circleci - POSTGRES_DB: circle_test - LC_COLLATE: C - steps: - - checkout - - run: sudo apt update - - run: sudo apt install -y postgresql-client - - restore_cache: - keys: - - yarn-packages-{{ checksum "yarn.lock" }} - - run: - command: yarn install --frozen-lockfile - - save_cache: - key: yarn-packages-{{ checksum "yarn.lock" }} - paths: - - ~/.cache/yarn - - run: yarn lint - - run: - command: yarn test - environment: - TEST_DATABASE_URL: postgres://circleci@localhost:5432/circle_test - node14_pg12: - docker: - - image: circleci/node:14 - - image: circleci/postgres:12 - environment: - POSTGRES_HOST_AUTH_METHOD: trust - POSTGRES_USER: circleci - POSTGRES_DB: circle_test - LC_COLLATE: C - steps: - - checkout - - run: sudo apt update - - run: sudo apt install -y postgresql-client - - restore_cache: - keys: - - yarn-packages-{{ checksum "yarn.lock" }} - - run: - command: yarn install --frozen-lockfile - - save_cache: - key: yarn-packages-{{ checksum "yarn.lock" }} - paths: - - ~/.cache/yarn - - run: yarn lint - - run: - command: yarn test - environment: - TEST_DATABASE_URL: postgres://circleci@localhost:5432/circle_test - node16_pg13: - docker: - - image: circleci/node:16 - - image: circleci/postgres:13 - environment: - POSTGRES_HOST_AUTH_METHOD: trust - POSTGRES_USER: circleci - POSTGRES_DB: circle_test - LC_COLLATE: C - steps: - - checkout - - run: sudo apt update - - run: sudo apt install -y postgresql-client - - restore_cache: - keys: - - yarn-packages-{{ checksum "yarn.lock" }} - - run: - command: yarn install --frozen-lockfile - - save_cache: - key: yarn-packages-{{ checksum "yarn.lock" }} - paths: - - ~/.cache/yarn - - run: yarn lint - - run: - command: yarn test - environment: - TEST_DATABASE_URL: postgres://circleci@localhost:5432/circle_test -workflows: - version: 2 - test: - jobs: - - node12_pg10 - - node12_pg11 - - node14_pg12 - - node16_pg13 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..02a7c19 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,89 @@ +name: Node CI + +on: push + +jobs: + lint: + runs-on: ubuntu-latest + + env: + TERM: xterm + FORCE_COLOR: 1 + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Use Node.js 18.x + uses: actions/setup-node@v1 + with: + node-version: 18 + + - name: Install + run: yarn --immutable --ignore-engines + + - name: Check Code Format + run: yarn format:check + + - name: Lint Code + run: yarn lint + + - name: Typecheck + run: yarn typecheck + + test: + runs-on: ubuntu-latest + + env: + CI: true + PGVERSION: ${{ matrix.postgres-version}} + TEST_DATABASE_URL: postgres://postgres:postgres@127.0.0.1:5432/graphile_test_c + TERM: xterm + FORCE_COLOR: 1 + + strategy: + fail-fast: false + matrix: + postgres-version: + - 11 + - 12 + - 13 + - 14 + - 15 + node-version: + - 14.x + - 16.x + - 18.x + + services: + postgres: + image: postgres:${{ matrix.postgres-version }} + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: postgres + ports: + - "0.0.0.0:5432:5432" + # needed because the postgres container does not provide a healthcheck + options: + --health-cmd pg_isready --health-interval 10s --health-timeout 5s + --health-retries 5 --name postgres + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + + - name: Configure PostgreSQL + run: | + cat .github/workflows/ci/docker-entrypoint-initdb.d/010-setup.sh | docker exec -i postgres bash + + - name: Install + run: yarn --immutable --ignore-engines + + - name: Test + run: yarn test diff --git a/.github/workflows/ci/docker-entrypoint-initdb.d/010-setup.sh b/.github/workflows/ci/docker-entrypoint-initdb.d/010-setup.sh new file mode 100644 index 0000000..0be27b3 --- /dev/null +++ b/.github/workflows/ci/docker-entrypoint-initdb.d/010-setup.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +set -e + +createdb graphile_test_c -U postgres --template template0 --lc-collate C diff --git a/.prettierrc.json b/.prettierrc.json index c4be887..757fd64 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -1,3 +1,3 @@ { "trailingComma": "es5" -} \ No newline at end of file +} diff --git a/.vscode/launch.json b/.vscode/launch.json index 3ee8f7a..8e4c5ab 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,16 +1,20 @@ { - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "Debug Jest Tests", - "type": "node", - "request": "launch", - "runtimeArgs": ["--inspect-brk", "${workspaceRoot}/node_modules/.bin/jest", "--runInBand"], - "console": "integratedTerminal", - "internalConsoleOptions": "neverOpen" - } - ] + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Debug Jest Tests", + "type": "node", + "request": "launch", + "runtimeArgs": [ + "--inspect-brk", + "${workspaceRoot}/node_modules/.bin/jest", + "--runInBand" + ], + "console": "integratedTerminal", + "internalConsoleOptions": "neverOpen" + } + ] } diff --git a/__tests__/integration/schema/core.ts b/__tests__/integration/schema/core.ts index 4f04afe..722da4a 100644 --- a/__tests__/integration/schema/core.ts +++ b/__tests__/integration/schema/core.ts @@ -2,19 +2,21 @@ import * as pg from "pg"; import { createPostGraphileSchema } from "postgraphile-core"; import { printSchemaOrdered, withPgClient } from "../../helpers"; -export const test = ( - schemas: string[], - options: Record, - setup?: (client: pg.PoolClient) => void -) => (): Promise => - withPgClient(async (client) => { - if (setup) { - if (typeof setup === "function") { - await setup(client); - } else { - await client.query(setup); +export const test = + ( + schemas: string[], + options: Record, + setup?: (client: pg.PoolClient) => void + ) => + (): Promise => + withPgClient(async (client) => { + if (setup) { + if (typeof setup === "function") { + await setup(client); + } else { + await client.query(setup); + } } - } - const schema = await createPostGraphileSchema(client, schemas, options); - expect(printSchemaOrdered(schema)).toMatchSnapshot(); - }); + const schema = await createPostGraphileSchema(client, schemas, options); + expect(printSchemaOrdered(schema)).toMatchSnapshot(); + }); diff --git a/package.json b/package.json index a9ad399..b5ace37 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,10 @@ "main": "dist/index.js", "scripts": { "build": "tsc", - "format": "prettier --write src/**/*.ts", + "format": "prettier --ignore-path ./.eslintignore", + "format:all": "yarn format '**/*.{json,md,html,js,jsx,ts,tsx}'", + "format:fix": "yarn format:all --write", + "format:check": "yarn format:all --list-different", "lint": "eslint . --ext .js,.jsx,.ts,.tsx", "prepack": "rm -Rf dist && npm run build", "test": "jest -i",