@@ -17,30 +17,58 @@ jobs:
17
17
outputs :
18
18
environment : ${{ steps.parse.outputs.environment }}
19
19
valid-command : ${{ steps.parse.outputs.valid-command }}
20
+ stage : ${{ steps.parse.outputs.stage }}
21
+ targets : ${{ steps.parse.outputs.targets }}
20
22
steps :
23
+ - name : Write command config
24
+ # write a config.yaml file to runner temp directory
25
+ run : |
26
+ cat <<EOF > ${{ runner.temp }}/config.yaml
27
+ test:
28
+ stage: environments/test
29
+ targets:
30
+ - instances/test-sample-instance/databases/hr_test
31
+ prod:
32
+ stage: environments/prod
33
+ targets:
34
+ - instances/prod-sample-instance/databases/hr_prod
35
+ EOF
21
36
- name : Parse migrate command
22
37
id : parse
23
38
run : |
24
39
COMMENT="${{ github.event.comment.body }}"
25
40
echo "Comment: $COMMENT"
41
+
42
+ CONFIG_FILE="${{ runner.temp }}/config.yaml"
43
+
44
+ # Get list of valid environments from config
45
+ VALID_ENVS=$(yq eval 'keys | join(", ")' "$CONFIG_FILE")
46
+ echo "valid-envs=$VALID_ENVS" >> $GITHUB_OUTPUT
26
47
27
48
# Extract environment from "/migrate <environment>"
28
49
if [[ $COMMENT =~ ^/migrate[[:space:]]+([a-zA-Z]+) ]]; then
29
50
ENVIRONMENT="${BASH_REMATCH[1]}"
30
51
echo "Parsed environment: $ENVIRONMENT"
31
52
32
- # Validate environment
33
- case $ENVIRONMENT in
34
- test|prod)
35
- echo "environment=$ENVIRONMENT" >> $GITHUB_OUTPUT
36
- echo "valid-command=true" >> $GITHUB_OUTPUT
37
- echo "✅ Valid environment: $ENVIRONMENT"
38
- ;;
39
- *)
40
- echo "valid-command=false" >> $GITHUB_OUTPUT
41
- echo "❌ Invalid environment: $ENVIRONMENT"
42
- ;;
43
- esac
53
+ # Check if environment exists in config using yq
54
+ if yq eval "has(\"$ENVIRONMENT\")" "$CONFIG_FILE" | grep -q true; then
55
+ echo "environment=$ENVIRONMENT" >> $GITHUB_OUTPUT
56
+ echo "valid-command=true" >> $GITHUB_OUTPUT
57
+
58
+ # Extract stage and targets from config for the environment
59
+ STAGE=$(yq eval ".$ENVIRONMENT.stage" "$CONFIG_FILE")
60
+ TARGETS=$(yq eval ".$ENVIRONMENT.targets | join(\",\")" "$CONFIG_FILE")
61
+
62
+ echo "stage=$STAGE" >> $GITHUB_OUTPUT
63
+ echo "targets=$TARGETS" >> $GITHUB_OUTPUT
64
+ echo "✅ Valid environment: $ENVIRONMENT"
65
+ echo " Stage: $STAGE"
66
+ echo " Targets: $TARGETS"
67
+ else
68
+ echo "valid-command=false" >> $GITHUB_OUTPUT
69
+ echo "❌ Invalid environment: $ENVIRONMENT"
70
+ echo " Valid environments are: $VALID_ENVS"
71
+ fi
44
72
else
45
73
echo "valid-command=false" >> $GITHUB_OUTPUT
46
74
echo "❌ Invalid command format"
62
90
❌ Invalid migrate command.
63
91
64
92
**Usage:** `/migrate <environment>`
65
- **Valid environments:** `test`, `prod `
93
+ **Valid environments:** `${{ steps.parse.outputs.valid-envs }} `
66
94
67
95
**Example:** `/migrate test`
68
96
reactions : confused
@@ -81,36 +109,25 @@ jobs:
81
109
ref : refs/pull/${{ github.event.issue.number }}/merge
82
110
83
111
- name : Comment deployment started
112
+ id : deployment-comment
84
113
uses : peter-evans/create-or-update-comment@v3
85
114
with :
86
115
issue-number : ${{ github.event.issue.number }}
87
116
body : |
88
- 🚀 **Migration deployment started **
117
+ 🚀 **Migration deployment starting **
89
118
90
119
**Environment:** `${{ needs.parse-command.outputs.environment }}`
91
120
**PR:** #${{ github.event.issue.number }}
92
121
**Triggered by:** @${{ github.event.comment.user.login }}
93
122
94
- Deploying database changes ...
123
+ Creating rollout plan ...
95
124
96
- - name : Set environment-specific targets
97
- id : env-config
98
- run : |
99
- case "${{ needs.parse-command.outputs.environment }}" in
100
- test)
101
- echo "bytebase-targets=instances/test-sample-instance/databases/hr_test" >> $GITHUB_OUTPUT
102
- echo "bytebase-stage=environments/test" >> $GITHUB_OUTPUT
103
- ;;
104
- prod)
105
- echo "bytebase-targets=instances/prod-sample-instance/databases/hr_prod" >> $GITHUB_OUTPUT
106
- echo "bytebase-stage=environments/prod" >> $GITHUB_OUTPUT
107
- ;;
108
- esac
125
+ Please check the [workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for details.
109
126
110
127
- name : Create rollout plan
111
128
id : create-rollout
112
129
env :
113
- BYTEBASE_TARGETS : ${{ steps.env-config .outputs.bytebase- targets }}
130
+ BYTEBASE_TARGETS : ${{ needs.parse-command .outputs.targets }}
114
131
FILE_PATTERN : " migrations-semver/*.sql"
115
132
BYTEBASE_OUTPUT : ${{ runner.temp }}/bytebase-metadata.json
116
133
run : |
@@ -128,9 +145,51 @@ jobs:
128
145
PLAN=$(jq -r .plan ${{ runner.temp }}/bytebase-metadata.json)
129
146
echo "plan=$PLAN" >> $GITHUB_OUTPUT
130
147
148
+ - name : Extract rollout metadata
149
+ id : extract-metadata
150
+ run : |
151
+ # Read the metadata file
152
+ METADATA_FILE="${{ runner.temp }}/bytebase-metadata.json"
153
+
154
+ # Extract release, plan, and rollout from metadata
155
+ RELEASE=$(jq -r .release "$METADATA_FILE")
156
+ PLAN=$(jq -r .plan "$METADATA_FILE")
157
+ ROLLOUT=$(jq -r .rollout "$METADATA_FILE")
158
+
159
+ # Trim trailing slash from BYTEBASE_URL if present
160
+ BASE_URL="${{ env.BYTEBASE_URL }}"
161
+ BASE_URL="${BASE_URL%/}"
162
+
163
+ # Output for use in comment
164
+ echo "release=$RELEASE" >> $GITHUB_OUTPUT
165
+ echo "plan=$PLAN" >> $GITHUB_OUTPUT
166
+ echo "rollout=$ROLLOUT" >> $GITHUB_OUTPUT
167
+ echo "base-url=$BASE_URL" >> $GITHUB_OUTPUT
168
+
169
+ - name : Update comment with rollout details
170
+ uses : peter-evans/create-or-update-comment@v3
171
+ with :
172
+ comment-id : ${{ steps.deployment-comment.outputs.comment-id }}
173
+ edit-mode : replace
174
+ body : |
175
+ 🚀 **Migration deployment in progress**
176
+
177
+ **Environment:** `${{ needs.parse-command.outputs.environment }}`
178
+ **PR:** #${{ github.event.issue.number }}
179
+ **Triggered by:** @${{ github.event.comment.user.login }}
180
+
181
+ **Bytebase Resources:**
182
+ - 📦 **Release:** ${{ steps.extract-metadata.outputs.base-url }}/${{ steps.extract-metadata.outputs.release }}
183
+ - 📝 **Plan:** ${{ steps.extract-metadata.outputs.base-url }}/${{ steps.extract-metadata.outputs.plan }}
184
+ - 🚀 **Rollout:** ${{ steps.extract-metadata.outputs.base-url }}/${{ steps.extract-metadata.outputs.rollout }}
185
+
186
+ Executing database changes...
187
+
188
+ Please check the [workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for details.
189
+
131
190
- name : Execute rollout
132
191
env :
133
- BYTEBASE_TARGET_STAGE : ${{ steps.env-config .outputs.bytebase- stage }}
192
+ BYTEBASE_TARGET_STAGE : ${{ needs.parse-command .outputs.stage }}
134
193
run : |
135
194
echo "Executing rollout to ${{ needs.parse-command.outputs.environment }}..."
136
195
@@ -146,26 +205,40 @@ jobs:
146
205
if : success()
147
206
uses : peter-evans/create-or-update-comment@v3
148
207
with :
149
- issue-number : ${{ github.event.issue.number }}
208
+ comment-id : ${{ steps.deployment-comment.outputs.comment-id }}
209
+ edit-mode : replace
150
210
body : |
151
211
✅ **Migration deployment completed successfully**
152
-
153
- **Environment:** `${{ needs.parse-command.outputs.environment }}`
212
+
213
+ **Environment:** `${{ needs.parse-command.outputs.environment }}`
154
214
**PR:** #${{ github.event.issue.number }}
155
215
**Triggered by:** @${{ github.event.comment.user.login }}
216
+
217
+ **Bytebase Resources:**
218
+ - 📦 **Release:** ${{ steps.extract-metadata.outputs.base-url }}/${{ steps.extract-metadata.outputs.release }}
219
+ - 📝 **Plan:** ${{ steps.extract-metadata.outputs.base-url }}/${{ steps.extract-metadata.outputs.plan }}
220
+ - 🚀 **Rollout:** ${{ steps.extract-metadata.outputs.base-url }}/${{ steps.extract-metadata.outputs.rollout }}
221
+
222
+ Database schema has been successfully updated.
156
223
157
- Database schema has been updated in the ` ${{ needs.parse-command.outputs.environment }}` environment .
224
+ Please check the [workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/ ${{ github.run_id }}) for details .
158
225
159
226
- name : Comment deployment failure
160
227
if : failure()
161
228
uses : peter-evans/create-or-update-comment@v3
162
229
with :
163
- issue-number : ${{ github.event.issue.number }}
230
+ comment-id : ${{ steps.deployment-comment.outputs.comment-id }}
231
+ edit-mode : replace
164
232
body : |
165
233
❌ **Migration deployment failed**
166
-
167
- **Environment:** `${{ needs.parse-command.outputs.environment }}`
234
+
235
+ **Environment:** `${{ needs.parse-command.outputs.environment }}`
168
236
**PR:** #${{ github.event.issue.number }}
169
237
**Triggered by:** @${{ github.event.comment.user.login }}
170
-
238
+
239
+ **Bytebase Resources:**
240
+ - 📦 **Release:** ${{ steps.extract-metadata.outputs.base-url }}/${{ steps.extract-metadata.outputs.release }}
241
+ - 📝 **Plan:** ${{ steps.extract-metadata.outputs.base-url }}/${{ steps.extract-metadata.outputs.plan }}
242
+ - 🚀 **Rollout:** ${{ steps.extract-metadata.outputs.base-url }}/${{ steps.extract-metadata.outputs.rollout }}
243
+
171
244
Please check the [workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for details.
0 commit comments