From 683a9107588046fec1c2a0d83a2a6f7655c0e7aa Mon Sep 17 00:00:00 2001 From: tianzhou Date: Wed, 13 Mar 2024 19:09:38 +0800 Subject: [PATCH 01/16] feat: add user table --- migrations/1001_init.down.sql | 1 + migrations/1001_init.up.sql | 7 +++++++ 2 files changed, 8 insertions(+) create mode 100644 migrations/1001_init.down.sql create mode 100644 migrations/1001_init.up.sql diff --git a/migrations/1001_init.down.sql b/migrations/1001_init.down.sql new file mode 100644 index 0000000..3f8392b --- /dev/null +++ b/migrations/1001_init.down.sql @@ -0,0 +1 @@ +DROP TABLE "user"; \ No newline at end of file diff --git a/migrations/1001_init.up.sql b/migrations/1001_init.up.sql new file mode 100644 index 0000000..9faaf92 --- /dev/null +++ b/migrations/1001_init.up.sql @@ -0,0 +1,7 @@ +CREATE TABLE "user" ( + "id" SERIAL NOT NULL, + "firstName" character varying NOT NULL, + "lastName" character varying NOT NULL, + "age" integer NOT NULL, + CONSTRAINT "PK_cace4a159ff9f2512dd42373760" PRIMARY KEY ("id") +); \ No newline at end of file From fb35f710cefe6d32f2b9f90303efed7e7403fd5b Mon Sep 17 00:00:00 2001 From: tianzhou Date: Wed, 13 Mar 2024 19:37:21 +0800 Subject: [PATCH 02/16] chore: add violation --- migrations/1001_init.up.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migrations/1001_init.up.sql b/migrations/1001_init.up.sql index 9faaf92..604280c 100644 --- a/migrations/1001_init.up.sql +++ b/migrations/1001_init.up.sql @@ -2,6 +2,6 @@ CREATE TABLE "user" ( "id" SERIAL NOT NULL, "firstName" character varying NOT NULL, "lastName" character varying NOT NULL, - "age" integer NOT NULL, + "age" integer, CONSTRAINT "PK_cace4a159ff9f2512dd42373760" PRIMARY KEY ("id") ); \ No newline at end of file From 56333588248c9e758caf310df2551ec1d52aaf04 Mon Sep 17 00:00:00 2001 From: tianzhou Date: Wed, 13 Mar 2024 19:47:12 +0800 Subject: [PATCH 03/16] chore: add NOT NULL --- migrations/1001_init.up.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migrations/1001_init.up.sql b/migrations/1001_init.up.sql index 604280c..9faaf92 100644 --- a/migrations/1001_init.up.sql +++ b/migrations/1001_init.up.sql @@ -2,6 +2,6 @@ CREATE TABLE "user" ( "id" SERIAL NOT NULL, "firstName" character varying NOT NULL, "lastName" character varying NOT NULL, - "age" integer, + "age" integer NOT NULL, CONSTRAINT "PK_cace4a159ff9f2512dd42373760" PRIMARY KEY ("id") ); \ No newline at end of file From 0db0c82a1e3ad4b4defc24e6ff0132f7c956cfe7 Mon Sep 17 00:00:00 2001 From: tianzhou Date: Thu, 14 Mar 2024 15:17:13 +0800 Subject: [PATCH 04/16] chore: alter user table --- migrations/1002_change.down.sql | 3 +++ migrations/1002_change.up.sql | 3 +++ 2 files changed, 6 insertions(+) create mode 100644 migrations/1002_change.down.sql create mode 100644 migrations/1002_change.up.sql diff --git a/migrations/1002_change.down.sql b/migrations/1002_change.down.sql new file mode 100644 index 0000000..94ff2c7 --- /dev/null +++ b/migrations/1002_change.down.sql @@ -0,0 +1,3 @@ +ALTER TABLE "user" DROP COLUMN "gender"; +ALTER TABLE "user" DROP COLUMN "address"; +ALTER TABLE "user" ADD "age" integer NOT NULL; \ No newline at end of file diff --git a/migrations/1002_change.up.sql b/migrations/1002_change.up.sql new file mode 100644 index 0000000..8224fa5 --- /dev/null +++ b/migrations/1002_change.up.sql @@ -0,0 +1,3 @@ +ALTER TABLE "user" DROP COLUMN "age"; +ALTER TABLE "user" ADD "address" character varying; +ALTER TABLE "user" ADD "gender" character varying NOT NULL; \ No newline at end of file From 04bfc60a5a291282d866233c2f33031c8cfce244 Mon Sep 17 00:00:00 2001 From: tianzhou Date: Thu, 14 Mar 2024 15:28:37 +0800 Subject: [PATCH 05/16] chore: add 1003 --- migrations/1003_change2.down.sql | 1 + migrations/1003_change2.up.sql | 4 ++++ 2 files changed, 5 insertions(+) create mode 100644 migrations/1003_change2.down.sql create mode 100644 migrations/1003_change2.up.sql diff --git a/migrations/1003_change2.down.sql b/migrations/1003_change2.down.sql new file mode 100644 index 0000000..5fe4274 --- /dev/null +++ b/migrations/1003_change2.down.sql @@ -0,0 +1 @@ +DROP TABLE post; \ No newline at end of file diff --git a/migrations/1003_change2.up.sql b/migrations/1003_change2.up.sql new file mode 100644 index 0000000..80c87f0 --- /dev/null +++ b/migrations/1003_change2.up.sql @@ -0,0 +1,4 @@ +CREATE TABLE post ( + "id" SERIAL NOT NULL, + title TEXT +); \ No newline at end of file From 3235eae4063d09a2d4430a785318006a7c871434 Mon Sep 17 00:00:00 2001 From: tianzhou Date: Thu, 14 Mar 2024 15:31:21 +0800 Subject: [PATCH 06/16] chore: delete 1003 --- migrations/1003_change2.down.sql | 1 - migrations/1003_change2.up.sql | 4 ---- 2 files changed, 5 deletions(-) delete mode 100644 migrations/1003_change2.down.sql delete mode 100644 migrations/1003_change2.up.sql diff --git a/migrations/1003_change2.down.sql b/migrations/1003_change2.down.sql deleted file mode 100644 index 5fe4274..0000000 --- a/migrations/1003_change2.down.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE post; \ No newline at end of file diff --git a/migrations/1003_change2.up.sql b/migrations/1003_change2.up.sql deleted file mode 100644 index 80c87f0..0000000 --- a/migrations/1003_change2.up.sql +++ /dev/null @@ -1,4 +0,0 @@ -CREATE TABLE post ( - "id" SERIAL NOT NULL, - title TEXT -); \ No newline at end of file From 678a502064edefccde94e3b4d26b0fdd5f6b46d1 Mon Sep 17 00:00:00 2001 From: tianzhou Date: Thu, 14 Mar 2024 15:35:32 +0800 Subject: [PATCH 07/16] chore: tweak name --- migrations/1001_init.up.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migrations/1001_init.up.sql b/migrations/1001_init.up.sql index 9faaf92..9209767 100644 --- a/migrations/1001_init.up.sql +++ b/migrations/1001_init.up.sql @@ -1,4 +1,4 @@ -CREATE TABLE "user" ( +CREATE TABLE "user1" ( "id" SERIAL NOT NULL, "firstName" character varying NOT NULL, "lastName" character varying NOT NULL, From 0931244e994d508df4d6f639b465271611611d68 Mon Sep 17 00:00:00 2001 From: tianzhou Date: Thu, 14 Mar 2024 15:50:19 +0800 Subject: [PATCH 08/16] chore: update --- migrations/1001_init.up.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migrations/1001_init.up.sql b/migrations/1001_init.up.sql index 9209767..9faaf92 100644 --- a/migrations/1001_init.up.sql +++ b/migrations/1001_init.up.sql @@ -1,4 +1,4 @@ -CREATE TABLE "user1" ( +CREATE TABLE "user" ( "id" SERIAL NOT NULL, "firstName" character varying NOT NULL, "lastName" character varying NOT NULL, From 730d8cc866f05f9ab74338ff0fb19490941e7b9c Mon Sep 17 00:00:00 2001 From: tianzhou Date: Thu, 14 Mar 2024 15:59:06 +0800 Subject: [PATCH 09/16] chore: fix --- migrations/1002_change.up.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/migrations/1002_change.up.sql b/migrations/1002_change.up.sql index 8224fa5..dded889 100644 --- a/migrations/1002_change.up.sql +++ b/migrations/1002_change.up.sql @@ -1,3 +1,3 @@ -ALTER TABLE "user" DROP COLUMN "age"; -ALTER TABLE "user" ADD "address" character varying; -ALTER TABLE "user" ADD "gender" character varying NOT NULL; \ No newline at end of file +ALTER TABLE "user1" DROP COLUMN "age"; +ALTER TABLE "user1" ADD "address" character varying; +ALTER TABLE "user1" ADD "gender" character varying NOT NULL; \ No newline at end of file From 39816105817dd9163a0c7f728597561081248868 Mon Sep 17 00:00:00 2001 From: tianzhou Date: Thu, 14 Mar 2024 16:14:23 +0800 Subject: [PATCH 10/16] chore: tweak --- migrations/1001_init.down.sql | 2 +- migrations/1001_init.up.sql | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/migrations/1001_init.down.sql b/migrations/1001_init.down.sql index 3f8392b..26ec47b 100644 --- a/migrations/1001_init.down.sql +++ b/migrations/1001_init.down.sql @@ -1 +1 @@ -DROP TABLE "user"; \ No newline at end of file +DROP TABLE "user1"; \ No newline at end of file diff --git a/migrations/1001_init.up.sql b/migrations/1001_init.up.sql index 9faaf92..9209767 100644 --- a/migrations/1001_init.up.sql +++ b/migrations/1001_init.up.sql @@ -1,4 +1,4 @@ -CREATE TABLE "user" ( +CREATE TABLE "user1" ( "id" SERIAL NOT NULL, "firstName" character varying NOT NULL, "lastName" character varying NOT NULL, From 02e268fb42e601dd1909a5d10d7c2f97ea1f26b6 Mon Sep 17 00:00:00 2001 From: tianzhou Date: Thu, 14 Mar 2024 16:19:26 +0800 Subject: [PATCH 11/16] chore: remove --- migrations/1001_init.down.sql | 2 +- migrations/1001_init.up.sql | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/migrations/1001_init.down.sql b/migrations/1001_init.down.sql index 26ec47b..3f8392b 100644 --- a/migrations/1001_init.down.sql +++ b/migrations/1001_init.down.sql @@ -1 +1 @@ -DROP TABLE "user1"; \ No newline at end of file +DROP TABLE "user"; \ No newline at end of file diff --git a/migrations/1001_init.up.sql b/migrations/1001_init.up.sql index 9209767..9faaf92 100644 --- a/migrations/1001_init.up.sql +++ b/migrations/1001_init.up.sql @@ -1,4 +1,4 @@ -CREATE TABLE "user1" ( +CREATE TABLE "user" ( "id" SERIAL NOT NULL, "firstName" character varying NOT NULL, "lastName" character varying NOT NULL, From 696f4698d2c2291289aa68b5e8782f32c0a58f81 Mon Sep 17 00:00:00 2001 From: tianzhou Date: Thu, 14 Mar 2024 17:01:55 +0800 Subject: [PATCH 12/16] chore: extra common --- .github/actions/common/utils.ts | 21 +++++++++++++++++++++ .github/actions/upsert-issue/dist/index.js | 20 ++++++++++---------- .github/actions/upsert-issue/index.ts | 21 +-------------------- .github/actions/upsert-issue/tsconfig.json | 2 +- 4 files changed, 33 insertions(+), 31 deletions(-) create mode 100644 .github/actions/common/utils.ts diff --git a/.github/actions/common/utils.ts b/.github/actions/common/utils.ts new file mode 100644 index 0000000..d1bcf6f --- /dev/null +++ b/.github/actions/common/utils.ts @@ -0,0 +1,21 @@ +import * as path from 'path'; + +export interface Change { + // Specify an id so that we can update the change afterwards. + id: string; + database: string; + file: string; + content: string; + // Extract from the filename. If filename is 123_init.sql, then the version is 123. + schemaVersion: string; +} + +// Use a deterministic way to generate the change id and schema version. +// Thus later we can derive the same id when we want to check the change. +export function generateChangeIdAndSchemaVersion(repo: string, pr: string, file: string) : { id: string; version: string} { + // filename should follow yyy/<>_xxxx + const version = path.basename(file).split("_")[0] + // Replace all non-alphanumeric characters with hyphens + return { id: `ch-${repo}-pr${pr}-${version}`.replace(/[^a-zA-Z0-9]/g, '-'), version}; +} + \ No newline at end of file diff --git a/.github/actions/upsert-issue/dist/index.js b/.github/actions/upsert-issue/dist/index.js index 89bbdef..028fea0 100644 --- a/.github/actions/upsert-issue/dist/index.js +++ b/.github/actions/upsert-issue/dist/index.js @@ -43,18 +43,10 @@ const core = __importStar(__nccwpck_require__(9093)); const github = __importStar(__nccwpck_require__(5942)); const fs_1 = __nccwpck_require__(7147); const glob = __importStar(__nccwpck_require__(5177)); -const path = __importStar(__nccwpck_require__(1017)); const diff_1 = __nccwpck_require__(7931); +const utils_1 = __nccwpck_require__(6473); let headers = {}; let projectUrl = ""; -// Use a deterministic way to generate the change id and schema version. -// Thus later we can derive the same id when we want to check the change. -function generateChangeIdAndSchemaVersion(repo, pr, file) { - // filename should follow yyy/<>_xxxx - const version = path.basename(file).split("_")[0]; - // Replace all non-alphanumeric characters with hyphens - return { id: `ch-${repo}-pr${pr}-${version}`.replace(/[^a-zA-Z0-9]/g, '-'), version }; -} function run() { return __awaiter(this, void 0, void 0, function* () { const githubToken = core.getInput('github-token', { required: true }); @@ -131,7 +123,7 @@ function collectChanges(githubToken, database, pattern) { let changes = []; for (const file of sqlFiles) { const content = yield fs_1.promises.readFile(file); - const { id, version } = generateChangeIdAndSchemaVersion(repo, prNumber.toString(), file); + const { id, version } = (0, utils_1.generateChangeIdAndSchemaVersion)(repo, prNumber.toString(), file); changes.push({ id, database, @@ -32525,6 +32517,14 @@ function wrappy (fn, cb) { } +/***/ }), + +/***/ 6473: +/***/ ((module) => { + +module.exports = eval("require")("common/utils"); + + /***/ }), /***/ 9491: diff --git a/.github/actions/upsert-issue/index.ts b/.github/actions/upsert-issue/index.ts index 436b059..7c10d1f 100644 --- a/.github/actions/upsert-issue/index.ts +++ b/.github/actions/upsert-issue/index.ts @@ -2,31 +2,12 @@ import * as core from '@actions/core'; import * as github from '@actions/github'; import { promises as fs } from 'fs'; import * as glob from 'glob'; -import * as path from 'path'; import { createPatch } from 'diff'; +import { Change, generateChangeIdAndSchemaVersion } from '../common/utils'; let headers = {}; let projectUrl = "" -interface Change { - // Specify an id so that we can update the change afterwards. - id: string; - database: string; - file: string; - content: string; - // Extract from the filename. If filename is 123_init.sql, then the version is 123. - schemaVersion: string; -} - -// Use a deterministic way to generate the change id and schema version. -// Thus later we can derive the same id when we want to check the change. -function generateChangeIdAndSchemaVersion(repo: string, pr: string, file: string) : { id: string; version: string} { - // filename should follow yyy/<>_xxxx - const version = path.basename(file).split("_")[0] - // Replace all non-alphanumeric characters with hyphens - return { id: `ch-${repo}-pr${pr}-${version}`.replace(/[^a-zA-Z0-9]/g, '-'), version}; -} - async function run(): Promise { const githubToken = core.getInput('github-token', { required: true }); const pattern = core.getInput('pattern', { required: true }); diff --git a/.github/actions/upsert-issue/tsconfig.json b/.github/actions/upsert-issue/tsconfig.json index 665d16d..8949770 100644 --- a/.github/actions/upsert-issue/tsconfig.json +++ b/.github/actions/upsert-issue/tsconfig.json @@ -28,7 +28,7 @@ /* Modules */ "module": "commonjs", /* Specify what module code is generated. */ - "rootDir": "./", /* Specify the root folder within your source files. */ + "rootDir": "../", /* Specify the root folder within your source files. */ // "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */ // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ From caff279d88371365ae25c222430cbe542cc34a33 Mon Sep 17 00:00:00 2001 From: Tianzhou Chen Date: Fri, 15 Mar 2024 01:14:00 +0800 Subject: [PATCH 13/16] chore: revert module --- .../actions/check-issue-status/dist/index.js | 2 +- .github/actions/check-issue-status/index.ts | 26 ++++++++++++++++--- .github/actions/common/utils.ts | 21 --------------- .github/actions/upsert-issue/dist/index.js | 20 +++++++------- .github/actions/upsert-issue/index.ts | 22 +++++++++++++++- .github/actions/upsert-issue/pnpm-lock.yaml | 2 +- .github/actions/upsert-issue/tsconfig.json | 2 +- 7 files changed, 56 insertions(+), 39 deletions(-) delete mode 100644 .github/actions/common/utils.ts diff --git a/.github/actions/check-issue-status/dist/index.js b/.github/actions/check-issue-status/dist/index.js index cb0d5af..fece70b 100644 --- a/.github/actions/check-issue-status/dist/index.js +++ b/.github/actions/check-issue-status/dist/index.js @@ -302,7 +302,7 @@ function run() { } } if (hasMatch) { - core.error(`Migration ${change.file} not found in the rollout`); + core.setFailed(`Migration ${change.file} not found in the rollout`); } } core.info("Rollout details:\n" + JSON.stringify(changes, null, 2)); diff --git a/.github/actions/check-issue-status/index.ts b/.github/actions/check-issue-status/index.ts index 61d67ba..31a8ee1 100644 --- a/.github/actions/check-issue-status/index.ts +++ b/.github/actions/check-issue-status/index.ts @@ -22,9 +22,9 @@ interface Change { // Thus later we can derive the same id when we want to check the change. function generateChangeIdAndSchemaVersion(repo: string, pr: string, file: string) : { id: string; version: string} { // filename should follow yyy/<>_xxxx - const version = path.basename(file).split("_")[0] - // Replace all non-alphanumeric characters with hyphens - return { id: `ch-${repo}-pr${pr}-${version}`.replace(/[^a-zA-Z0-9]/g, '-'), version}; + const version = path.basename(file).split("_")[0] + // Replace all non-alphanumeric characters with hyphens + return { id: `ch-${repo}-pr${pr}-${version}`.replace(/[^a-zA-Z0-9]/g, '-'), version}; } async function run(): Promise { @@ -285,10 +285,28 @@ async function run(): Promise { } } if (hasMatch) { - core.error(`Migration ${change.file} not found in the rollout`) + core.setFailed(`Migration ${change.file} not found in the rollout`) } } + // Sample rollout details + // + // [ + // { + // "id": "ch-ci-example-pr11-1001", + // "file": "migrations/1001_init.up.sql", + // "content": "CREATE TABLE \"user\" (\n \"id\" SERIAL NOT NULL,\n \"firstName\" character varying NOT NULL,\n \"lastName\" character varying NOT NULL,\n \"age\" integer NOT NULL,\n CONSTRAINT \"PK_cace4a159ff9f2512dd42373760\" PRIMARY KEY (\"id\")\n);", + // "schemaVersion": "1001", + // "status": "DONE" + // }, + // { + // "id": "ch-ci-example-pr11-1002", + // "file": "migrations/1002_change.up.sql", + // "content": "ALTER TABLE \"user1\" DROP COLUMN \"age\";\nALTER TABLE \"user1\" ADD \"address\" character varying;\nALTER TABLE \"user1\" ADD \"gender\" character varying NOT NULL;", + // "schemaVersion": "1002", + // "status": "NOT_STARTED" + // } + // ] core.info("Rollout details:\n" + JSON.stringify(changes, null, 2)) core.setOutput("rollout-details", changes); } diff --git a/.github/actions/common/utils.ts b/.github/actions/common/utils.ts deleted file mode 100644 index d1bcf6f..0000000 --- a/.github/actions/common/utils.ts +++ /dev/null @@ -1,21 +0,0 @@ -import * as path from 'path'; - -export interface Change { - // Specify an id so that we can update the change afterwards. - id: string; - database: string; - file: string; - content: string; - // Extract from the filename. If filename is 123_init.sql, then the version is 123. - schemaVersion: string; -} - -// Use a deterministic way to generate the change id and schema version. -// Thus later we can derive the same id when we want to check the change. -export function generateChangeIdAndSchemaVersion(repo: string, pr: string, file: string) : { id: string; version: string} { - // filename should follow yyy/<>_xxxx - const version = path.basename(file).split("_")[0] - // Replace all non-alphanumeric characters with hyphens - return { id: `ch-${repo}-pr${pr}-${version}`.replace(/[^a-zA-Z0-9]/g, '-'), version}; -} - \ No newline at end of file diff --git a/.github/actions/upsert-issue/dist/index.js b/.github/actions/upsert-issue/dist/index.js index 54f18ce..19cdf0a 100644 --- a/.github/actions/upsert-issue/dist/index.js +++ b/.github/actions/upsert-issue/dist/index.js @@ -43,10 +43,18 @@ const core = __importStar(__nccwpck_require__(9093)); const github = __importStar(__nccwpck_require__(5942)); const fs_1 = __nccwpck_require__(7147); const glob = __importStar(__nccwpck_require__(5177)); +const path = __importStar(__nccwpck_require__(1017)); const diff_1 = __nccwpck_require__(7931); -const utils_1 = __nccwpck_require__(6473); let headers = {}; let projectUrl = ""; +// Use a deterministic way to generate the change id and schema version. +// Thus later we can derive the same id when we want to check the change. +function generateChangeIdAndSchemaVersion(repo, pr, file) { + // filename should follow yyy/<>_xxxx + const version = path.basename(file).split("_")[0]; + // Replace all non-alphanumeric characters with hyphens + return { id: `ch-${repo}-pr${pr}-${version}`.replace(/[^a-zA-Z0-9]/g, '-'), version }; +} function run() { return __awaiter(this, void 0, void 0, function* () { const githubToken = core.getInput('github-token', { required: true }); @@ -125,7 +133,7 @@ function collectChanges(githubToken, database, pattern) { let changes = []; for (const file of sqlFiles) { const content = yield fs_1.promises.readFile(file); - const { id, version } = (0, utils_1.generateChangeIdAndSchemaVersion)(repo, prNumber.toString(), file); + const { id, version } = generateChangeIdAndSchemaVersion(repo, prNumber.toString(), file); changes.push({ id, database, @@ -32514,14 +32522,6 @@ function wrappy (fn, cb) { } -/***/ }), - -/***/ 6473: -/***/ ((module) => { - -module.exports = eval("require")("common/utils"); - - /***/ }), /***/ 9491: diff --git a/.github/actions/upsert-issue/index.ts b/.github/actions/upsert-issue/index.ts index 1f6654f..56e2385 100644 --- a/.github/actions/upsert-issue/index.ts +++ b/.github/actions/upsert-issue/index.ts @@ -2,12 +2,32 @@ import * as core from '@actions/core'; import * as github from '@actions/github'; import { promises as fs } from 'fs'; import * as glob from 'glob'; +import * as path from 'path'; import { createPatch } from 'diff'; -import { Change, generateChangeIdAndSchemaVersion } from '../common/utils'; let headers = {}; let projectUrl = "" +interface Change { + // Specify an id so that we can update the change afterwards. + id: string; + database: string; + file: string; + content: string; + // Extract from the filename. If filename is 123_init.sql, then the version is 123. + schemaVersion: string; +} + +// Use a deterministic way to generate the change id and schema version. +// Thus later we can derive the same id when we want to check the change. +function generateChangeIdAndSchemaVersion(repo: string, pr: string, file: string) : { id: string; version: string} { + // filename should follow yyy/<>_xxxx + const version = path.basename(file).split("_")[0] + // Replace all non-alphanumeric characters with hyphens + return { id: `ch-${repo}-pr${pr}-${version}`.replace(/[^a-zA-Z0-9]/g, '-'), version}; +} + + async function run(): Promise { const githubToken = core.getInput('github-token', { required: true }); const pattern = core.getInput('pattern', { required: true }); diff --git a/.github/actions/upsert-issue/pnpm-lock.yaml b/.github/actions/upsert-issue/pnpm-lock.yaml index ecae61b..772d1b5 100644 --- a/.github/actions/upsert-issue/pnpm-lock.yaml +++ b/.github/actions/upsert-issue/pnpm-lock.yaml @@ -1,4 +1,4 @@ -lockfileVersion: '6.0' +lockfileVersion: '6.1' settings: autoInstallPeers: true diff --git a/.github/actions/upsert-issue/tsconfig.json b/.github/actions/upsert-issue/tsconfig.json index 8949770..665d16d 100644 --- a/.github/actions/upsert-issue/tsconfig.json +++ b/.github/actions/upsert-issue/tsconfig.json @@ -28,7 +28,7 @@ /* Modules */ "module": "commonjs", /* Specify what module code is generated. */ - "rootDir": "../", /* Specify the root folder within your source files. */ + "rootDir": "./", /* Specify the root folder within your source files. */ // "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */ // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ From 40e79966a54c0150ba9795839c653beb1e0a4394 Mon Sep 17 00:00:00 2001 From: Tianzhou Chen Date: Fri, 15 Mar 2024 01:25:16 +0800 Subject: [PATCH 14/16] chore: update --- .../actions/check-issue-status/dist/index.js | 26 ++++++++++++++++--- .github/actions/check-issue-status/index.ts | 8 +++--- .github/actions/sql-review/dist/index.js | 9 +++---- .github/actions/sql-review/index.ts | 9 +++---- .github/actions/sql-review/pnpm-lock.yaml | 2 +- 5 files changed, 33 insertions(+), 21 deletions(-) diff --git a/.github/actions/check-issue-status/dist/index.js b/.github/actions/check-issue-status/dist/index.js index fece70b..6b4943e 100644 --- a/.github/actions/check-issue-status/dist/index.js +++ b/.github/actions/check-issue-status/dist/index.js @@ -280,13 +280,13 @@ function run() { else { // This means the PR content is different from the Bytebase issue content. // It could be that Bytebase issue content is manually changed by someone. - core.error(`Migration mismatch for ${matchedChange.file} with task ${task.title} under stage ${stage.title}`); - core.error((0, diff_1.createPatch)('difference', matchedChange.content, actualRolloutContent)); + core.setFailed(`Migration mismatch for ${matchedChange.file} with task ${task.title} under stage ${stage.title}`); + core.setFailed((0, diff_1.createPatch)('difference', matchedChange.content, actualRolloutContent)); } } else { // This means Bytebase contains a task not found in the PR - core.error(`Unexpected task ${task.title} under stage ${stage.title} and content ${actualRolloutContent}`); + core.setFailed(`Unexpected task ${task.title} under stage ${stage.title} and content ${actualRolloutContent}`); } } } @@ -301,10 +301,28 @@ function run() { } } } - if (hasMatch) { + if (!hasMatch) { core.setFailed(`Migration ${change.file} not found in the rollout`); } } + // Sample rollout details + // + // [ + // { + // "id": "ch-ci-example-pr11-1001", + // "file": "migrations/1001_init.up.sql", + // "content": "CREATE TABLE \"user\" (\n \"id\" SERIAL NOT NULL,\n \"firstName\" character varying NOT NULL,\n \"lastName\" character varying NOT NULL,\n \"age\" integer NOT NULL,\n CONSTRAINT \"PK_cace4a159ff9f2512dd42373760\" PRIMARY KEY (\"id\")\n);", + // "schemaVersion": "1001", + // "status": "DONE" + // }, + // { + // "id": "ch-ci-example-pr11-1002", + // "file": "migrations/1002_change.up.sql", + // "content": "ALTER TABLE \"user1\" DROP COLUMN \"age\";\nALTER TABLE \"user1\" ADD \"address\" character varying;\nALTER TABLE \"user1\" ADD \"gender\" character varying NOT NULL;", + // "schemaVersion": "1002", + // "status": "NOT_STARTED" + // } + // ] core.info("Rollout details:\n" + JSON.stringify(changes, null, 2)); core.setOutput("rollout-details", changes); } diff --git a/.github/actions/check-issue-status/index.ts b/.github/actions/check-issue-status/index.ts index 31a8ee1..282e3e8 100644 --- a/.github/actions/check-issue-status/index.ts +++ b/.github/actions/check-issue-status/index.ts @@ -263,12 +263,12 @@ async function run(): Promise { } else { // This means the PR content is different from the Bytebase issue content. // It could be that Bytebase issue content is manually changed by someone. - core.error(`Migration mismatch for ${matchedChange.file} with task ${task.title} under stage ${stage.title}`) - core.error(createPatch('difference', matchedChange.content, actualRolloutContent)); + core.setFailed(`Migration mismatch for ${matchedChange.file} with task ${task.title} under stage ${stage.title}`) + core.setFailed(createPatch('difference', matchedChange.content, actualRolloutContent)); } } else { // This means Bytebase contains a task not found in the PR - core.error(`Unexpected task ${task.title} under stage ${stage.title} and content ${actualRolloutContent}`) + core.setFailed(`Unexpected task ${task.title} under stage ${stage.title} and content ${actualRolloutContent}`) } } } @@ -284,7 +284,7 @@ async function run(): Promise { } } } - if (hasMatch) { + if (!hasMatch) { core.setFailed(`Migration ${change.file} not found in the rollout`) } } diff --git a/.github/actions/sql-review/dist/index.js b/.github/actions/sql-review/dist/index.js index 7728c44..703b9f8 100644 --- a/.github/actions/sql-review/dist/index.js +++ b/.github/actions/sql-review/dist/index.js @@ -96,11 +96,10 @@ function run() { }); const httpStatus = response.status; if (httpStatus !== 200) { - core.error(`Failed to check SQL file ${file} with response code ${httpStatus}`); - process.exit(1); + throw new Error(`Failed to check SQL file ${file} with response code ${httpStatus}`); } const responseData = yield response.json(); - core.debug("Advices:" + JSON.stringify(responseData.advices)); + core.debug("Reviews:" + JSON.stringify(responseData.advices)); responseData.advices.forEach((advice) => { const annotation = `::${advice.status} file=${file},line=${advice.line},col=${advice.column},title=${advice.title} (${advice.code})::${advice.content}. https://www.bytebase.com/docs/reference/error-code/advisor#${advice.code}`; // Emit annotations for each advice @@ -111,9 +110,7 @@ function run() { }); } if (hasErrorOrWarning) { - core.error("Advice contains ERROR or WARNING violations. Marking for failure."); - // If you want to fail the GitHub Action if any error or warning is found - core.setFailed("SQL check failed due to ERROR or WARNING."); + core.setFailed("Review contains ERROR or WARNING violations. Marking for failure."); } } catch (error) { diff --git a/.github/actions/sql-review/index.ts b/.github/actions/sql-review/index.ts index f034ebf..0fbd3fb 100644 --- a/.github/actions/sql-review/index.ts +++ b/.github/actions/sql-review/index.ts @@ -71,14 +71,13 @@ async function run(): Promise { const httpStatus = response.status; if (httpStatus !== 200) { - core.error(`Failed to check SQL file ${file} with response code ${httpStatus}`); - process.exit(1); + throw new Error(`Failed to check SQL file ${file} with response code ${httpStatus}`); } const responseData = await response.json(); - core.debug("Advices:" + JSON.stringify(responseData.advices)); + core.debug("Reviews:" + JSON.stringify(responseData.advices)); responseData.advices.forEach((advice: { status: string; line: any; column: any; title: any; code: any; content: any; }) => { const annotation = `::${advice.status} file=${file},line=${advice.line},col=${advice.column},title=${advice.title} (${advice.code})::${advice.content}. https://www.bytebase.com/docs/reference/error-code/advisor#${advice.code}`; // Emit annotations for each advice @@ -91,9 +90,7 @@ async function run(): Promise { } if (hasErrorOrWarning) { - core.error("Advice contains ERROR or WARNING violations. Marking for failure."); - // If you want to fail the GitHub Action if any error or warning is found - core.setFailed("SQL check failed due to ERROR or WARNING."); + core.setFailed("Review contains ERROR or WARNING violations. Marking for failure."); } } catch (error) { if (error instanceof Error) core.setFailed(error.message); diff --git a/.github/actions/sql-review/pnpm-lock.yaml b/.github/actions/sql-review/pnpm-lock.yaml index 26537ea..2a4e624 100644 --- a/.github/actions/sql-review/pnpm-lock.yaml +++ b/.github/actions/sql-review/pnpm-lock.yaml @@ -1,4 +1,4 @@ -lockfileVersion: '6.0' +lockfileVersion: '6.1' settings: autoInstallPeers: true From 516b7b6cc904be7e7e00832e5d4f70ec34b19d40 Mon Sep 17 00:00:00 2001 From: Tianzhou Chen Date: Fri, 15 Mar 2024 01:35:36 +0800 Subject: [PATCH 15/16] chore: diff --- .github/actions/check-issue-status/dist/index.js | 2 +- .github/actions/check-issue-status/index.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/actions/check-issue-status/dist/index.js b/.github/actions/check-issue-status/dist/index.js index 6b4943e..984fa30 100644 --- a/.github/actions/check-issue-status/dist/index.js +++ b/.github/actions/check-issue-status/dist/index.js @@ -281,7 +281,7 @@ function run() { // This means the PR content is different from the Bytebase issue content. // It could be that Bytebase issue content is manually changed by someone. core.setFailed(`Migration mismatch for ${matchedChange.file} with task ${task.title} under stage ${stage.title}`); - core.setFailed((0, diff_1.createPatch)('difference', matchedChange.content, actualRolloutContent)); + core.setFailed((0, diff_1.createPatch)('difference', matchedChange.content, actualRolloutContent, matchedChange.file, task.title)); } } else { diff --git a/.github/actions/check-issue-status/index.ts b/.github/actions/check-issue-status/index.ts index 282e3e8..1b6dfec 100644 --- a/.github/actions/check-issue-status/index.ts +++ b/.github/actions/check-issue-status/index.ts @@ -264,7 +264,7 @@ async function run(): Promise { // This means the PR content is different from the Bytebase issue content. // It could be that Bytebase issue content is manually changed by someone. core.setFailed(`Migration mismatch for ${matchedChange.file} with task ${task.title} under stage ${stage.title}`) - core.setFailed(createPatch('difference', matchedChange.content, actualRolloutContent)); + core.setFailed(createPatch('difference', matchedChange.content, actualRolloutContent, matchedChange.file, task.title)); } } else { // This means Bytebase contains a task not found in the PR From 7e9e6c1dd2cfb49048d0a3584960d3d5e0f49e02 Mon Sep 17 00:00:00 2001 From: Tianzhou Chen Date: Fri, 15 Mar 2024 01:36:19 +0800 Subject: [PATCH 16/16] chore: remove migration --- migrations/1001_init.down.sql | 1 - migrations/1001_init.up.sql | 7 ------- migrations/1002_change.down.sql | 3 --- migrations/1002_change.up.sql | 3 --- 4 files changed, 14 deletions(-) delete mode 100644 migrations/1001_init.down.sql delete mode 100644 migrations/1001_init.up.sql delete mode 100644 migrations/1002_change.down.sql delete mode 100644 migrations/1002_change.up.sql diff --git a/migrations/1001_init.down.sql b/migrations/1001_init.down.sql deleted file mode 100644 index 3f8392b..0000000 --- a/migrations/1001_init.down.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE "user"; \ No newline at end of file diff --git a/migrations/1001_init.up.sql b/migrations/1001_init.up.sql deleted file mode 100644 index 9faaf92..0000000 --- a/migrations/1001_init.up.sql +++ /dev/null @@ -1,7 +0,0 @@ -CREATE TABLE "user" ( - "id" SERIAL NOT NULL, - "firstName" character varying NOT NULL, - "lastName" character varying NOT NULL, - "age" integer NOT NULL, - CONSTRAINT "PK_cace4a159ff9f2512dd42373760" PRIMARY KEY ("id") -); \ No newline at end of file diff --git a/migrations/1002_change.down.sql b/migrations/1002_change.down.sql deleted file mode 100644 index 94ff2c7..0000000 --- a/migrations/1002_change.down.sql +++ /dev/null @@ -1,3 +0,0 @@ -ALTER TABLE "user" DROP COLUMN "gender"; -ALTER TABLE "user" DROP COLUMN "address"; -ALTER TABLE "user" ADD "age" integer NOT NULL; \ No newline at end of file diff --git a/migrations/1002_change.up.sql b/migrations/1002_change.up.sql deleted file mode 100644 index dded889..0000000 --- a/migrations/1002_change.up.sql +++ /dev/null @@ -1,3 +0,0 @@ -ALTER TABLE "user1" DROP COLUMN "age"; -ALTER TABLE "user1" ADD "address" character varying; -ALTER TABLE "user1" ADD "gender" character varying NOT NULL; \ No newline at end of file