@@ -102,16 +102,29 @@ jobs:
102
102
cp database/schema/mysql-schema-new.sql database/schema/mysql-schema.sql
103
103
fi
104
104
105
+ - name : Determine target branch
106
+ id : target-branch
107
+ run : |
108
+ if [[ "${{ github.event_name }}" == "pull_request" ]]; then
109
+ # If this is a PR, use the base branch of the PR
110
+ echo "branch=${{ github.base_ref }}" >> $GITHUB_OUTPUT
111
+ else
112
+ # For push events, default to development
113
+ echo "branch=development" >> $GITHUB_OUTPUT
114
+ fi
115
+
105
116
- name : Check for existing PRs
106
117
id : check-pr
107
118
if : steps.diff.outputs.has_changes == 'true'
108
119
run : |
109
- PR_EXISTS=$(gh pr list --base development --head "update-schema-dump*" --json number --jq 'length')
120
+ # First check if there's an existing open PR with any update-schema-dump branch
121
+ PR_EXISTS=$(gh pr list --state open --head "update-schema-dump" --json number --jq 'length')
110
122
if [ "$PR_EXISTS" -gt "0" ]; then
111
123
echo "existing_pr=true" >> $GITHUB_OUTPUT
112
- PR_NUMBER=$(gh pr list --base development --head "update-schema-dump* " --json number --jq '.[0].number')
113
- BRANCH_NAME=$(gh pr view $PR_NUMBER -- json headRefName --jq '.headRefName')
124
+ PR_NUMBER=$(gh pr list --state open --head "update-schema-dump" --json number,headRefName --jq '.[0].number')
125
+ BRANCH_NAME=$(gh pr list --state open --head "update-schema-dump" -- json headRefName --jq '.[0] .headRefName')
114
126
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT
127
+ echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT
115
128
else
116
129
echo "existing_pr=false" >> $GITHUB_OUTPUT
117
130
fi
@@ -131,6 +144,18 @@ jobs:
131
144
env :
132
145
GH_TOKEN : ${{ secrets.PERSONAL_ACCESS_TOKEN }}
133
146
147
+ - name : Update existing PR description
148
+ if : steps.diff.outputs.has_changes == 'true' && steps.check-pr.outputs.existing_pr == 'true'
149
+ run : |
150
+ gh pr edit ${{ steps.check-pr.outputs.pr_number }} --body "This PR updates the MySQL schema dump with the latest migration changes.
151
+
152
+ Related to commit: ${{ steps.find-commit.outputs.commit_id }}
153
+ Commit message: ${{ steps.find-commit.outputs.commit_msg }}
154
+
155
+ [View commit](https://github.com/HDInnovations/UNIT3D/commit/${{ steps.find-commit.outputs.commit_id }})"
156
+ env :
157
+ GH_TOKEN : ${{ secrets.PERSONAL_ACCESS_TOKEN }}
158
+
134
159
- name : Create new PR with schema changes
135
160
if : steps.diff.outputs.has_changes == 'true' && steps.check-pr.outputs.existing_pr == 'false'
136
161
uses : peter-evans/create-pull-request@v5
@@ -148,7 +173,7 @@ jobs:
148
173
branch : update-schema-dump
149
174
branch-suffix : timestamp
150
175
delete-branch : true
151
- base : development
176
+ base : ${{ steps.target-branch.outputs.branch }}
152
177
path : .
153
178
add-paths : |
154
179
database/schema/mysql-schema.sql
0 commit comments