Skip to content

Commit 9a87a3c

Browse files
committed
fix: simplify the check migrations script
1 parent 24ef27e commit 9a87a3c

File tree

1 file changed

+26
-18
lines changed

1 file changed

+26
-18
lines changed

.github/workflows/check-migrations.yml

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,37 @@ name: Check Migrations
33
on:
44
pull_request:
55
types: [opened, synchronize]
6+
paths:
7+
- 'src/database/migrations/**'
68

79
jobs:
810
check-migrations:
911
runs-on: ubuntu-latest
1012

1113
steps:
12-
- name: Checkout repository
13-
uses: actions/checkout@v4
14+
- name: Checkout repository
15+
uses: actions/checkout@v4
1416

15-
- name: Check for migration changes
16-
id: check_migrations
17-
run: |
18-
git diff --name-only origin/main...HEAD | grep '^src/database/migrations/' || echo "no-changes" > no_changes
17+
- name: Check and add comment to PR
18+
uses: actions/github-script@v4
19+
with:
20+
github-token: ${{ secrets.GITHUB_TOKEN }}
21+
script: |
22+
const { data: comments } = await github.rest.issues.listComments({
23+
owner: context.repo.owner,
24+
repo: context.repo.repo,
25+
issue_number: context.issue.number,
26+
});
1927
20-
- name: Add comment to PR
21-
if: steps.check_migrations.outputs.changes != 'no-changes'
22-
uses: actions/github-script@v4
23-
with:
24-
github-token: ${{ secrets.GITHUB_TOKEN }}
25-
script: |
26-
github.issues.createComment({
27-
issue_number: context.issue.number,
28-
owner: context.repo.owner,
29-
repo: context.repo.repo,
30-
body: "It looks like you've made changes to the migrations. Have you run `npm run db:generate-schema` to ensure the updated schemas are included in your PR?"
31-
})
28+
const commentExists = comments.some(comment =>
29+
comment.body.includes("It looks like you've made changes to the migrations.")
30+
);
31+
32+
if (!commentExists) {
33+
await github.rest.issues.createComment({
34+
owner: context.repo.owner,
35+
repo: context.repo.repo,
36+
issue_number: context.issue.number,
37+
body: "It looks like you've made changes to the migrations. Have you run `npm run db:generate-schema` to ensure the updated schemas are included in your PR?"
38+
});
39+
}

0 commit comments

Comments
 (0)