Skip to content

Commit d1cd82e

Browse files
authored
docs: github chatops integration tutorial (#888)
1 parent 4893655 commit d1cd82e

File tree

4 files changed

+75
-2
lines changed

4 files changed

+75
-2
lines changed
50.5 KB
Loading
53.2 KB
Loading
96.4 KB
Loading

mintlify/tutorials/gitops-github-workflow.mdx

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ This tutorial shows you how to build an database GitOps workflow using GitHub Ac
3232

3333
2. Manually control rollouts by stage
3434

35+
3. Deploy changes via ChatOps-style PR comments
36+
3537
<Info>
3638

3739
While we use PostgreSQL with GitHub Actions in this guide, you can apply these concepts to other SQL or NoSQL databases with any CI platforms like GitLab CI, Bitbucket Pipelines, or Azure DevOps using the Bytebase API.
@@ -63,10 +65,11 @@ https://github.com/bytebase/example-gitops-github-flow
6365

6466
### Step 4 - Fork the Example Repository and Configure Variables
6567

66-
1. Fork [https://github.com/bytebase/example-gitops-github-flow](https://github.com/bytebase/example-gitops-github-flow). There are two workflows in this repository:
68+
1. Fork [https://github.com/bytebase/example-gitops-github-flow](https://github.com/bytebase/example-gitops-github-flow). There are three workflows in this repository:
6769

6870
- `.github/workflows/sql-review-action.yml`: [Lint the SQL](/sql-review/review-policy/) migration files after the PR is created.
6971
- `.github/workflows/release-action.yml`: Create a release in Bytebase after the PR is merged to the `main` branch.
72+
- `.github/workflows/chatops-migrate.yml`: Deploy changes to specific environments via PR comments using `/migrate` command.
7073

7174
1. Go into `.github/workflows/release-action.yml` and `.github/workflows/sql-review-action.yml`. In the `env` section, replace the variable values with your own and commit the changes.
7275

@@ -165,6 +168,76 @@ You can also manually control the rollout by stage.
165168

166169
![gh-deploy-finish](/content/docs/tutorials/gitops-github-workflow/gh-deploy-finish.webp)
167170

171+
## ChatOps Deployment via PR Comments
172+
173+
In addition to automatic and manual deployments, you can also deploy database changes to any environment directly from pull request comments using ChatOps commands.
174+
175+
Team members can trigger deployments by commenting `/migrate <environment>` on any pull request. The workflow will:
176+
1. Validate the command and environment
177+
2. Create a rollout plan in Bytebase
178+
3. Execute the migration to the specified environment
179+
4. Report the results back in the PR comments
180+
181+
### Step 1 - Configure ChatOps Workflow
182+
183+
1. Go into `.github/workflows/chatops-migrate.yml`. In the `env` section, replace the variable values with your own:
184+
185+
- **BYTEBASE_URL**: your ngrok url
186+
- **BYTEBASE_SERVICE_ACCOUNT**: `[email protected]`
187+
- **BYTEBASE_PROJECT**: `projects/project-sample`
188+
- **FILE_PATTERN**: `migrations-semver/*.sql`
189+
190+
2. In the same workflow file, modify the config generation step to match your environments:
191+
192+
```yml
193+
- name: Write command config
194+
run: |
195+
cat <<EOF > ${{ runner.temp }}/bytebase-action-config.yaml
196+
test:
197+
stage: environments/test
198+
targets:
199+
- instances/test-sample-instance/databases/hr_test
200+
prod:
201+
stage: environments/prod
202+
targets:
203+
- instances/prod-sample-instance/databases/hr_prod
204+
EOF
205+
```
206+
207+
3. Set your service account password in the repository secrets setting with the name `BYTEBASE_SERVICE_ACCOUNT_SECRET`.
208+
209+
4. In **Settings > Environments**, ensure you have environments matching your config (e.g., "test", "prod"). For production, configure deployment protection rules if needed.
210+
211+
### Step 2 - Deploy via PR Comments
212+
213+
1. Create a new branch with this file and create a pull request:
214+
215+
- 1.14.0_code.sql
216+
217+
```sql
218+
ALTER TABLE IF EXISTS users ADD COLUMN IF NOT EXISTS code VARCHAR(255) NOT NULL DEFAULT '';
219+
```
220+
221+
2. After the SQL review passes, comment `/migrate test` on the PR to deploy to test environment.
222+
223+
![gh-chatops-test](/content/docs/tutorials/gitops-github-workflow/gh-chatops-test.webp)
224+
225+
3. The workflow will add a 🚀 reaction and post deployment progress in the PR comments.
226+
227+
![gh-chatops-progress](/content/docs/tutorials/gitops-github-workflow/gh-chatops-progress.webp)
228+
229+
4. When deployment completes, you'll see a success message with links to Bytebase resources.
230+
231+
![gh-chatops-success](/content/docs/tutorials/gitops-github-workflow/gh-chatops-success.webp)
232+
233+
5. To deploy to production, comment `/migrate prod`. If production requires approval, the workflow will wait for reviewers.
234+
168235
## Summary
169236

170-
Now you have learned how to database GitOps with GitHub Action. If you want to trigger a release creation with other git providers (e.g. GitLab, Bitbucket, Azure DevOps), you may customize the workflow file.
237+
Now you have learned how to implement database GitOps with GitHub Actions in three ways:
238+
239+
1. **Automatic deployment** after merging to main branch
240+
2. **Manual rollout** with environment-level approval
241+
3. **ChatOps deployment** via PR comments for pre-merge testing
242+
243+
If you want to trigger a release creation with other git providers (e.g. GitLab, Bitbucket, Azure DevOps), you may customize the workflow file.

0 commit comments

Comments
 (0)