mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
ci: check alteration sequence (#2746)
This commit is contained in:
parent
74c1532a38
commit
b5b1e5f258
3 changed files with 83 additions and 22 deletions
19
.github/workflows/main.yml
vendored
19
.github/workflows/main.yml
vendored
|
@ -90,3 +90,22 @@ jobs:
|
||||||
uses: docker/build-push-action@v3
|
uses: docker/build-push-action@v3
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
|
|
||||||
|
main-alteration-sequence:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
fetch-depth: 2
|
||||||
|
|
||||||
|
- name: Setup Node and pnpm
|
||||||
|
uses: silverhand-io/actions-node-pnpm-run-steps@v2
|
||||||
|
with:
|
||||||
|
node-version: 18
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: pnpm prepack
|
||||||
|
|
||||||
|
- name: Check alteration sequence
|
||||||
|
run: node .scripts/check-alterations-sequence.js
|
||||||
|
|
36
.scripts/check-alterations-sequence.js
Normal file
36
.scripts/check-alterations-sequence.js
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
/**
|
||||||
|
* This script runs a task to check alteration files seqence:
|
||||||
|
* new files should come last
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
const { execSync } = require("child_process");
|
||||||
|
|
||||||
|
const alterationFilePrefix = "packages/schemas/alterations/";
|
||||||
|
|
||||||
|
const allAlterations = execSync("pnpm cli db alter list", {
|
||||||
|
encoding: "utf-8",
|
||||||
|
})
|
||||||
|
.split("\n")
|
||||||
|
.filter((filename) => Boolean(filename))
|
||||||
|
.map((filename) => filename.replace(".js", ""));
|
||||||
|
|
||||||
|
const diffFiles = execSync("git diff --name-only HEAD HEAD~1", {
|
||||||
|
encoding: "utf-8",
|
||||||
|
});
|
||||||
|
const committedAlterations = diffFiles
|
||||||
|
.split("\n")
|
||||||
|
.filter((filename) => filename.startsWith(alterationFilePrefix))
|
||||||
|
.map((filename) =>
|
||||||
|
filename.replace(alterationFilePrefix, "").replace(".ts", "")
|
||||||
|
);
|
||||||
|
|
||||||
|
for (const alteration of committedAlterations) {
|
||||||
|
const index = allAlterations.indexOf(alteration);
|
||||||
|
|
||||||
|
if (index < allAlterations.length - committedAlterations.length) {
|
||||||
|
throw new Error(
|
||||||
|
`Wrong alteration sequence for commited file: ${alteration}\nAll timestamps of committed alteration files should be greater than the biggest one in the base branch.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -72,7 +72,7 @@ const alteration: CommandModule<unknown, { action: string; target?: string }> =
|
||||||
builder: (yargs) =>
|
builder: (yargs) =>
|
||||||
yargs
|
yargs
|
||||||
.positional('action', {
|
.positional('action', {
|
||||||
describe: 'The action to perform, now it only accepts `deploy`',
|
describe: 'The action to perform, now it only accepts `deploy` and `list`',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
demandOption: true,
|
demandOption: true,
|
||||||
})
|
})
|
||||||
|
@ -81,10 +81,13 @@ const alteration: CommandModule<unknown, { action: string; target?: string }> =
|
||||||
type: 'string',
|
type: 'string',
|
||||||
}),
|
}),
|
||||||
handler: async ({ action, target }) => {
|
handler: async ({ action, target }) => {
|
||||||
if (action !== 'deploy') {
|
if (action === 'list') {
|
||||||
log.error('Unsupported action');
|
const files = await getAlterationFiles();
|
||||||
}
|
|
||||||
|
|
||||||
|
for (const file of files) {
|
||||||
|
console.log(file.filename);
|
||||||
|
}
|
||||||
|
} else if (action === 'deploy') {
|
||||||
const pool = await createPoolFromConfig();
|
const pool = await createPoolFromConfig();
|
||||||
const alterations = await chooseAlterationsByVersion(
|
const alterations = await chooseAlterationsByVersion(
|
||||||
await getUndeployedAlterations(pool),
|
await getUndeployedAlterations(pool),
|
||||||
|
@ -104,6 +107,9 @@ const alteration: CommandModule<unknown, { action: string; target?: string }> =
|
||||||
}
|
}
|
||||||
|
|
||||||
await pool.end();
|
await pool.end();
|
||||||
|
} else {
|
||||||
|
log.error('Unsupported action');
|
||||||
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue