-
Notifications
You must be signed in to change notification settings - Fork 0
103 lines (84 loc) · 3.12 KB
/
pgschema-plan-multi.yml
File metadata and controls
103 lines (84 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
name: pgschema Plan - Multi File
on:
pull_request:
types: [opened, synchronize, reopened]
paths:
- 'multifile/**'
- '.github/workflows/pgschema-plan-multi.yml'
permissions:
contents: read
pull-requests: write
jobs:
pgschema-plan-multi:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: 'stable'
- name: Install pgschema
run: go install github.com/pgschema/pgschema@latest
- name: Run pgschema plan
id: plan
run: |
# Run pgschema plan with directory of SQL files
PLAN_OUTPUT=$(pgschema plan \
--host "${{ secrets.DB_HOST }}" \
--port "${{ secrets.DB_PORT }}" \
--db "${{ secrets.DB_NAME }}" \
--user "${{ secrets.DB_USER }}" \
--file "${{ github.workspace }}/multifile/main.sql" \
--format human 2>&1)
# Escape special characters for GitHub Actions
PLAN_OUTPUT="${PLAN_OUTPUT//'%'/'%25'}"
PLAN_OUTPUT="${PLAN_OUTPUT//$'\n'/'%0A'}"
PLAN_OUTPUT="${PLAN_OUTPUT//$'\r'/'%0D'}"
# Set output
echo "plan<<EOF" >> $GITHUB_OUTPUT
echo "$PLAN_OUTPUT" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
env:
PGPASSWORD: ${{ secrets.DB_PASSWORD }}
- name: Comment PR
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const planOutput = `${{ steps.plan.outputs.plan }}`;
// Decode the escaped output
const decodedOutput = decodeURIComponent(planOutput);
const body = `## pgschema Plan Output (Multi File)
<details>
<summary>Click to expand plan details</summary>
\`\`\`
${decodedOutput}
\`\`\`
</details>
---
*This comment was automatically generated by the pgschema Multi File Plan workflow.*`;
// Try to find existing comment
const { data: comments } = await github.rest.issues.listComments({
...context.repo,
issue_number: context.issue.number,
});
const botComment = comments.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('pgschema Plan Output (Multi File)')
);
if (botComment) {
// Update existing comment
await github.rest.issues.updateComment({
...context.repo,
comment_id: botComment.id,
body: body
});
} else {
// Create new comment
await github.rest.issues.createComment({
...context.repo,
issue_number: context.issue.number,
body: body
});
}