From f7616f62200ad7f95838101f9580502bbbd4dc81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kevin=20Gr=C3=BCneberg?= Date: Thu, 1 Feb 2024 10:34:25 +0800 Subject: [PATCH 1/3] chore: bump to node 20 --- .github/workflows/ci.yml | 15 +++++------ .github/workflows/docs.yml | 6 ++--- .github/workflows/publish-deps.yml | 8 +++--- .github/workflows/release.yml | 12 ++++----- .nvmrc | 1 + Dockerfile | 6 ++--- package-lock.json | 40 ++++++++++++++++++++++-------- package.json | 6 ++--- src/lib/secrets.ts | 2 +- src/lib/sql/index.ts | 6 ++--- test/lib/secrets.ts | 7 +++--- test/server/ssl.ts | 6 ++--- 12 files changed, 68 insertions(+), 47 deletions(-) create mode 100644 .nvmrc diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d77812a4..a3606924 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,13 +15,14 @@ concurrency: jobs: test: name: Test - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: - node-version: "18" + node-version-file: '.nvmrc' + - run: | npm clean-install @@ -30,9 +31,9 @@ jobs: prettier-check: name: Prettier check - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: actionsx/prettier@v3 with: @@ -40,9 +41,9 @@ jobs: docker: name: Build with docker - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 name: Checkout Repo - uses: docker/setup-buildx-action@v3 diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 39884f9f..57a62885 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -15,13 +15,13 @@ concurrency: jobs: docs: name: Publish docs - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: - node-version: "18" + node-version-file: '.nvmrc' - run: | npm clean-install diff --git a/.github/workflows/publish-deps.yml b/.github/workflows/publish-deps.yml index ae4d6cd1..d40966e6 100644 --- a/.github/workflows/publish-deps.yml +++ b/.github/workflows/publish-deps.yml @@ -5,17 +5,17 @@ on: jobs: publish: - # Must match glibc verison in node:18 + # Must match glibc verison in node:20 runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: repository: 'pyramation/libpg-query-node' - ref: 'v13' + ref: 'v15' - uses: actions/setup-node@v4 with: - node-version: '18' + node-version-file: '.nvmrc' - run: npm i - run: npm run binary:build diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 998a6502..4bcb9350 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,16 +9,16 @@ on: jobs: semantic-release: name: Release - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 outputs: new-release-published: ${{ steps.semantic-release.outputs.new_release_published }} new-release-version: ${{ steps.semantic-release.outputs.new_release_version }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: - node-version: '18' + node-version-file: '.nvmrc' - run: | npm clean-install @@ -37,13 +37,13 @@ jobs: needs: - semantic-release if: needs.semantic-release.outputs.new-release-published == 'true' - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: - node-version: '18' + node-version-file: '.nvmrc' - name: Prepare release run: | diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 00000000..85aee5a5 --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +v20 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 53c9a207..172c30ae 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:18 as build +FROM node:20 as build WORKDIR /usr/src/app # Do `npm ci` separately so we can cache `node_modules` # https://nodejs.org/en/docs/guides/nodejs-docker-webapp/ @@ -7,7 +7,7 @@ RUN npm clean-install COPY . . RUN npm run build && npm prune --omit=dev -FROM node:18-slim +FROM node:20-slim WORKDIR /usr/src/app COPY --from=build /usr/src/app/node_modules node_modules COPY --from=build /usr/src/app/dist dist @@ -16,4 +16,4 @@ ENV PG_META_PORT=8080 CMD ["npm", "run", "start"] EXPOSE 8080 # --start-period defaults to 0s, but can't be set to 0s (to be explicit) by now -HEALTHCHECK --interval=5s --timeout=5s --retries=3 CMD node -e "require('http').get('http://localhost:8080/health', (r) => {if (r.statusCode !== 200) throw new Error(r.statusCode)})" +HEALTHCHECK --interval=5s --timeout=5s --retries=3 CMD node -e "fetch('http://localhost:8080/health').then((r) => {if (r.status !== 200) throw new Error(r.status)})" diff --git a/package-lock.json b/package-lock.json index 4969a065..5b570e72 100644 --- a/package-lock.json +++ b/package-lock.json @@ -28,7 +28,7 @@ }, "devDependencies": { "@types/crypto-js": "^4.1.1", - "@types/node": "^18.17.17", + "@types/node": "^20.11.14", "@types/pg": "^8.6.5", "@types/pg-format": "^1.0.1", "cpy-cli": "^5.0.0", @@ -42,8 +42,8 @@ "vitest": "^1.2.2" }, "engines": { - "node": ">=18", - "npm": ">=8" + "node": ">=20", + "npm": ">=9" } }, "node_modules/@babel/generator": { @@ -1093,10 +1093,13 @@ "dev": true }, "node_modules/@types/node": { - "version": "18.17.17", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.17.17.tgz", - "integrity": "sha512-cOxcXsQ2sxiwkykdJqvyFS+MLQPLvIdwh5l6gNg8qF6s+C7XSkEWOZjK+XhUZd+mYvHV/180g2cnCcIl4l06Pw==", - "dev": true + "version": "20.11.16", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.11.16.tgz", + "integrity": "sha512-gKb0enTmRCzXSSUJDq6/sPcqrfCv2mkkG6Jt/clpn5eiCbKTY+SgZUxo+p8ZKMof5dCp9vHQUAB7wOUTod22wQ==", + "dev": true, + "dependencies": { + "undici-types": "~5.26.4" + } }, "node_modules/@types/pg": { "version": "8.11.0", @@ -6246,6 +6249,12 @@ "integrity": "sha512-WxONCrssBM8TSPRqN5EmsjVrsv4A8X12J4ArBiiayv3DyyG3ZlIg6yysuuSYdZsVz3TKcTg2fd//Ujd4CHV1iA==", "dev": true }, + "node_modules/undici-types": { + "version": "5.26.5", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", + "dev": true + }, "node_modules/unique-filename": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/unique-filename/-/unique-filename-1.1.1.tgz", @@ -7395,10 +7404,13 @@ "dev": true }, "@types/node": { - "version": "18.17.17", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.17.17.tgz", - "integrity": "sha512-cOxcXsQ2sxiwkykdJqvyFS+MLQPLvIdwh5l6gNg8qF6s+C7XSkEWOZjK+XhUZd+mYvHV/180g2cnCcIl4l06Pw==", - "dev": true + "version": "20.11.16", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.11.16.tgz", + "integrity": "sha512-gKb0enTmRCzXSSUJDq6/sPcqrfCv2mkkG6Jt/clpn5eiCbKTY+SgZUxo+p8ZKMof5dCp9vHQUAB7wOUTod22wQ==", + "dev": true, + "requires": { + "undici-types": "~5.26.4" + } }, "@types/pg": { "version": "8.11.0", @@ -11200,6 +11212,12 @@ "integrity": "sha512-WxONCrssBM8TSPRqN5EmsjVrsv4A8X12J4ArBiiayv3DyyG3ZlIg6yysuuSYdZsVz3TKcTg2fd//Ujd4CHV1iA==", "dev": true }, + "undici-types": { + "version": "5.26.5", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", + "dev": true + }, "unique-filename": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/unique-filename/-/unique-filename-1.1.1.tgz", diff --git a/package.json b/package.json index ab6d75d4..573c4ee1 100644 --- a/package.json +++ b/package.json @@ -33,8 +33,8 @@ "test:update": "run-s db:clean db:run && vitest run && run-s db:clean" }, "engines": { - "node": ">=18", - "npm": ">=8" + "node": ">=20", + "npm": ">=9" }, "dependencies": { "@fastify/cors": "^9.0.1", @@ -56,7 +56,7 @@ }, "devDependencies": { "@types/crypto-js": "^4.1.1", - "@types/node": "^18.17.17", + "@types/node": "^20.11.14", "@types/pg": "^8.6.5", "@types/pg-format": "^1.0.1", "cpy-cli": "^5.0.0", diff --git a/src/lib/secrets.ts b/src/lib/secrets.ts index 5cd58e44..03df7639 100644 --- a/src/lib/secrets.ts +++ b/src/lib/secrets.ts @@ -1,5 +1,5 @@ // Use dynamic import to support module mock -const fs = await import('fs/promises') +const fs = await import('node:fs/promises') export const getSecret = async (key: string) => { if (!key) { diff --git a/src/lib/sql/index.ts b/src/lib/sql/index.ts index 9b5e266f..64be3aa8 100644 --- a/src/lib/sql/index.ts +++ b/src/lib/sql/index.ts @@ -1,6 +1,6 @@ -import { readFile } from 'fs/promises' -import { dirname, join } from 'path' -import { fileURLToPath } from 'url' +import { readFile } from 'node:fs/promises' +import { dirname, join } from 'node:path' +import { fileURLToPath } from 'node:url' const __dirname = dirname(fileURLToPath(import.meta.url)) export const columnPrivilegesSql = await readFile(join(__dirname, 'column_privileges.sql'), 'utf-8') diff --git a/test/lib/secrets.ts b/test/lib/secrets.ts index f5aa2166..054298c8 100644 --- a/test/lib/secrets.ts +++ b/test/lib/secrets.ts @@ -1,9 +1,10 @@ -import { readFile } from 'fs/promises' +import { readFile } from 'node:fs/promises' import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest' import { getSecret } from '../../src/lib/secrets' -vi.mock('fs/promises', async (): Promise => { - const originalModule = await vi.importActual('fs/promises') +vi.mock('node:fs/promises', async (): Promise => { + const originalModule = + await vi.importActual('node:fs/promises') const readFile = vi.fn() return { ...originalModule, diff --git a/test/server/ssl.ts b/test/server/ssl.ts index 6e847d55..05944dac 100644 --- a/test/server/ssl.ts +++ b/test/server/ssl.ts @@ -1,7 +1,7 @@ import CryptoJS from 'crypto-js' -import fs from 'fs' -import path from 'path' -import { fileURLToPath } from 'url' +import fs from 'node:fs' +import path from 'node:path' +import { fileURLToPath } from 'node:url' import { expect, test } from 'vitest' import { app } from './utils' import { CRYPTO_KEY, DEFAULT_POOL_CONFIG } from '../../src/server/constants' From b7cfb85fd5163d9d4cf6710d58f29d21f38f58b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kevin=20Gr=C3=BCneberg?= Date: Mon, 5 Feb 2024 13:11:15 +0800 Subject: [PATCH 2/3] try prettier --- .github/workflows/ci.yml | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a3606924..766f7112 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,10 +35,21 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: actionsx/prettier@v3 - with: - args: --check "{src,test}/**/*.ts" - + - name: Setup node + uses: actions/setup-node@v4 + with: + node-version-file: '.nvmrc' + + # Installing all dependencies takes up to three minutes, hacking around to only installing prettier+deps + - name: Download dependencies + run: | + rm package.json + rm package-lock.json + npm i prettier@3 prettier-plugin-sql@0.17.0 + - name: Run prettier + run: |- + npx prettier -c '{src,test}/**/*.ts' + docker: name: Build with docker runs-on: ubuntu-22.04 From c6464b7efe061887dcc8189e658c1220b53f77d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kevin=20Gr=C3=BCneberg?= Date: Mon, 5 Feb 2024 13:12:29 +0800 Subject: [PATCH 3/3] ayml --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 766f7112..1552f61e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,9 +36,9 @@ jobs: - uses: actions/checkout@v4 - name: Setup node - uses: actions/setup-node@v4 - with: - node-version-file: '.nvmrc' + uses: actions/setup-node@v4 + with: + node-version-file: '.nvmrc' # Installing all dependencies takes up to three minutes, hacking around to only installing prettier+deps - name: Download dependencies