@@ -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
@@ -93,24 +121,10 @@ jobs:
93
121
94
122
Deploying database changes...
95
123
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
109
-
110
124
- name : Create rollout plan
111
125
id : create-rollout
112
126
env :
113
- BYTEBASE_TARGETS : ${{ steps.env-config .outputs.bytebase- targets }}
127
+ BYTEBASE_TARGETS : ${{ needs.parse-command .outputs.targets }}
114
128
FILE_PATTERN : " migrations-semver/*.sql"
115
129
BYTEBASE_OUTPUT : ${{ runner.temp }}/bytebase-metadata.json
116
130
run : |
@@ -128,9 +142,49 @@ jobs:
128
142
PLAN=$(jq -r .plan ${{ runner.temp }}/bytebase-metadata.json)
129
143
echo "plan=$PLAN" >> $GITHUB_OUTPUT
130
144
145
+ - name : Extract rollout metadata
146
+ id : extract-metadata
147
+ run : |
148
+ # Read the metadata file
149
+ METADATA_FILE="${{ runner.temp }}/bytebase-metadata.json"
150
+
151
+ # Extract release, plan, and rollout from metadata
152
+ RELEASE=$(jq -r .release "$METADATA_FILE")
153
+ PLAN=$(jq -r .plan "$METADATA_FILE")
154
+ ROLLOUT=$(jq -r .rollout "$METADATA_FILE")
155
+
156
+ # Trim trailing slash from BYTEBASE_URL if present
157
+ BASE_URL="${{ env.BYTEBASE_URL }}"
158
+ BASE_URL="${BASE_URL%/}"
159
+
160
+ # Output for use in comment
161
+ echo "release=$RELEASE" >> $GITHUB_OUTPUT
162
+ echo "plan=$PLAN" >> $GITHUB_OUTPUT
163
+ echo "rollout=$ROLLOUT" >> $GITHUB_OUTPUT
164
+ echo "base-url=$BASE_URL" >> $GITHUB_OUTPUT
165
+
166
+ - name : Comment rollout details
167
+ id : rollout-comment
168
+ uses : peter-evans/create-or-update-comment@v3
169
+ with :
170
+ issue-number : ${{ github.event.issue.number }}
171
+ body : |
172
+ 🚀 **Migration deployment starting**
173
+
174
+ **Environment:** `${{ needs.parse-command.outputs.environment }}`
175
+ **PR:** #${{ github.event.issue.number }}
176
+ **Triggered by:** @${{ github.event.comment.user.login }}
177
+
178
+ **Bytebase Resources:**
179
+ - 📦 **Release:** ${{ steps.extract-metadata.outputs.base-url }}/${{ steps.extract-metadata.outputs.release }}
180
+ - 📝 **Plan:** ${{ steps.extract-metadata.outputs.base-url }}/${{ steps.extract-metadata.outputs.plan }}
181
+ - 🚀 **Rollout:** ${{ steps.extract-metadata.outputs.base-url }}/${{ steps.extract-metadata.outputs.rollout }}
182
+
183
+ Executing database changes...
184
+
131
185
- name : Execute rollout
132
186
env :
133
- BYTEBASE_TARGET_STAGE : ${{ steps.env-config .outputs.bytebase- stage }}
187
+ BYTEBASE_TARGET_STAGE : ${{ needs.parse-command .outputs.stage }}
134
188
run : |
135
189
echo "Executing rollout to ${{ needs.parse-command.outputs.environment }}..."
136
190
@@ -146,26 +200,36 @@ jobs:
146
200
if : success()
147
201
uses : peter-evans/create-or-update-comment@v3
148
202
with :
149
- issue-number : ${{ github.event.issue.number }}
203
+ comment-id : ${{ steps.rollout-comment.outputs.comment-id }}
150
204
body : |
151
205
✅ **Migration deployment completed successfully**
152
-
153
- **Environment:** `${{ needs.parse-command.outputs.environment }}`
206
+
207
+ **Environment:** `${{ needs.parse-command.outputs.environment }}`
154
208
**PR:** #${{ github.event.issue.number }}
155
209
**Triggered by:** @${{ github.event.comment.user.login }}
156
-
157
- Database schema has been updated in the `${{ needs.parse-command.outputs.environment }}` environment.
210
+
211
+ **Bytebase Resources:**
212
+ - 📦 **Release:** ${{ steps.extract-metadata.outputs.base-url }}/${{ steps.extract-metadata.outputs.release }}
213
+ - 📝 **Plan:** ${{ steps.extract-metadata.outputs.base-url }}/${{ steps.extract-metadata.outputs.plan }}
214
+ - 🚀 **Rollout:** ${{ steps.extract-metadata.outputs.base-url }}/${{ steps.extract-metadata.outputs.rollout }}
215
+
216
+ Database schema has been successfully updated.
158
217
159
218
- name : Comment deployment failure
160
219
if : failure()
161
220
uses : peter-evans/create-or-update-comment@v3
162
221
with :
163
- issue-number : ${{ github.event.issue.number }}
222
+ comment-id : ${{ steps.rollout-comment.outputs.comment-id }}
164
223
body : |
165
224
❌ **Migration deployment failed**
166
-
167
- **Environment:** `${{ needs.parse-command.outputs.environment }}`
225
+
226
+ **Environment:** `${{ needs.parse-command.outputs.environment }}`
168
227
**PR:** #${{ github.event.issue.number }}
169
228
**Triggered by:** @${{ github.event.comment.user.login }}
170
-
229
+
230
+ **Bytebase Resources:**
231
+ - 📦 **Release:** ${{ steps.extract-metadata.outputs.base-url }}/${{ steps.extract-metadata.outputs.release }}
232
+ - 📝 **Plan:** ${{ steps.extract-metadata.outputs.base-url }}/${{ steps.extract-metadata.outputs.plan }}
233
+ - 🚀 **Rollout:** ${{ steps.extract-metadata.outputs.base-url }}/${{ steps.extract-metadata.outputs.rollout }}
234
+
171
235
Please check the [workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for details.
0 commit comments