mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-05 03:26:27 +00:00
Merge pull request #2039 from akhilmhdh/feat/migration-file-checks
feat: added slugify migration file creater name and additional check to ensure migration files are not editied in PR
This commit is contained in:
@@ -0,0 +1,25 @@
|
|||||||
|
name: Check migration file edited
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
types: [opened, synchronize]
|
||||||
|
paths:
|
||||||
|
- 'backend/src/db/migrations/**'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
rename:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Check out repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Check any migration files are modified, renamed or duplicated.
|
||||||
|
run: |
|
||||||
|
git diff --name-status HEAD^ HEAD backend/src/db/migrations | grep '^M\|^R\|^C' || true | cut -f2 | xargs -r -n1 basename > edited_files.txt
|
||||||
|
if [ -s edited_files.txt ]; then
|
||||||
|
echo "Exiting migration files cannot be modified."
|
||||||
|
cat edited_files.txt
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
@@ -19,18 +19,16 @@ jobs:
|
|||||||
|
|
||||||
- name: Get list of newly added files in migration folder
|
- name: Get list of newly added files in migration folder
|
||||||
run: |
|
run: |
|
||||||
git diff --name-status HEAD^ HEAD backend/src/db/migrations | grep '^A' | cut -f2 | xargs -n1 basename > added_files.txt
|
git diff --name-status HEAD^ HEAD backend/src/db/migrations | grep '^A' || true | cut -f2 | xargs -r -n1 basename > added_files.txt
|
||||||
if [ ! -s added_files.txt ]; then
|
if [ ! -s added_files.txt ]; then
|
||||||
echo "No new files added. Skipping"
|
echo "No new files added. Skipping"
|
||||||
echo "SKIP_RENAME=true" >> $GITHUB_ENV
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Script to rename migrations
|
- name: Script to rename migrations
|
||||||
if: env.SKIP_RENAME != 'true'
|
|
||||||
run: python .github/resources/rename_migration_files.py
|
run: python .github/resources/rename_migration_files.py
|
||||||
|
|
||||||
- name: Commit and push changes
|
- name: Commit and push changes
|
||||||
if: env.SKIP_RENAME != 'true'
|
|
||||||
run: |
|
run: |
|
||||||
git config user.name github-actions
|
git config user.name github-actions
|
||||||
git config user.email [email protected]
|
git config user.email [email protected]
|
||||||
|
|||||||
@@ -2,13 +2,14 @@
|
|||||||
import { execSync } from "child_process";
|
import { execSync } from "child_process";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import promptSync from "prompt-sync";
|
import promptSync from "prompt-sync";
|
||||||
|
import slugify from "@sindresorhus/slugify"
|
||||||
|
|
||||||
const prompt = promptSync({ sigint: true });
|
const prompt = promptSync({ sigint: true });
|
||||||
|
|
||||||
const migrationName = prompt("Enter name for migration: ");
|
const migrationName = prompt("Enter name for migration: ");
|
||||||
|
|
||||||
// Remove spaces from migration name and replace with hyphens
|
// Remove spaces from migration name and replace with hyphens
|
||||||
const formattedMigrationName = migrationName.replace(/\s+/g, "-");
|
const formattedMigrationName = slugify(migrationName);
|
||||||
|
|
||||||
execSync(
|
execSync(
|
||||||
`npx knex migrate:make --knexfile ${path.join(__dirname, "../src/db/knexfile.ts")} -x ts ${formattedMigrationName}`,
|
`npx knex migrate:make --knexfile ${path.join(__dirname, "../src/db/knexfile.ts")} -x ts ${formattedMigrationName}`,
|
||||||
|
|||||||
Reference in New Issue
Block a user