From 6e135c3310eafeaee588c5ab35643b8e0a7386f0 Mon Sep 17 00:00:00 2001 From: p0ny Date: Wed, 10 Sep 2025 17:17:27 +0800 Subject: [PATCH 1/2] chore: update chatops readme --- README.md | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/README.md b/README.md index fd99781..4c26ffc 100644 --- a/README.md +++ b/README.md @@ -63,3 +63,54 @@ Set your service account password in the repository secrets setting with the nam > [!IMPORTANT] > The migration filename SHOULD comply to the naming scheme described in [bytebase-action](https://github.com/bytebase/bytebase/tree/main/action#global-flags) `--file-pattern` flag section. + +### How to configure chatops-migrate.yml + +Copy [chatops-migrate.yml](/.github/workflows/chatops-migrate.yml) to your repository. + +This workflow enables ChatOps-style deployments through PR comments. Team members can trigger migrations by commenting `/migrate ` on pull requests. + +#### Configuration + +1. **Define environments in the workflow**: Edit the `config.yaml` generation step to define your environments and their database targets. + +> [!NOTE] +> The top-level keys (e.g., `test`, `prod`) are used as GitHub Actions job environments, so they must match the environment names configured in your repository settings. + + +```yml + - name: Write command config + run: | + cat < ${{ runner.temp }}/config.yaml + test: + stage: environments/test + targets: + - instances/test-sample-instance/databases/hr_test + prod: + stage: environments/prod + targets: + - instances/prod-sample-instance/databases/hr_prod + EOF +``` + +- `stage`: The environment of the databases (e.g., `environments/test`) +- `targets`: List of databases (e.g., `instances/test-sample-instance/databases/hr_test`) + +2. **Set environment variables**: Configure these variables in the workflow: + +```yml +env: + BYTEBASE_URL: https://demo.bytebase.com + BYTEBASE_SERVICE_ACCOUNT: api@service.bytebase.com + BYTEBASE_SERVICE_ACCOUNT_SECRET: ${{ secrets.BYTEBASE_SERVICE_ACCOUNT_SECRET }} + BYTEBASE_PROJECT: "projects/hr" +``` + +3. **Configure GitHub environments**: Create environments matching your config (e.g., "test", "prod") in repository settings. Add deployment protection rules for production environments. + +4. **Add service account secret**: Set `BYTEBASE_SERVICE_ACCOUNT_SECRET` in repository secrets. + +#### Usage + +- Comment `/migrate ` on a PR to trigger deployment to that environment +- Example: `/migrate prod` deploys to production (requires environment approval if configured) From 550039b3341f50282351e8cf40ac046a2f6e7092 Mon Sep 17 00:00:00 2001 From: p0ny Date: Wed, 10 Sep 2025 17:30:43 +0800 Subject: [PATCH 2/2] move FILE_PATTERN out for visibility --- .github/workflows/chatops-migrate.yml | 2 +- README.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/chatops-migrate.yml b/.github/workflows/chatops-migrate.yml index 7a622d8..2654ea6 100644 --- a/.github/workflows/chatops-migrate.yml +++ b/.github/workflows/chatops-migrate.yml @@ -9,6 +9,7 @@ env: BYTEBASE_SERVICE_ACCOUNT: api@service.bytebase.com BYTEBASE_SERVICE_ACCOUNT_SECRET: ${{ secrets.BYTEBASE_SERVICE_ACCOUNT_SECRET }} BYTEBASE_PROJECT: "projects/hr" + FILE_PATTERN: "migrations-semver/*.sql" jobs: parse-command: @@ -128,7 +129,6 @@ jobs: id: create-rollout env: BYTEBASE_TARGETS: ${{ needs.parse-command.outputs.targets }} - FILE_PATTERN: "migrations-semver/*.sql" BYTEBASE_OUTPUT: ${{ runner.temp }}/bytebase-metadata.json run: | echo "Creating rollout plan for ${{ needs.parse-command.outputs.environment }}..." diff --git a/README.md b/README.md index 4c26ffc..0415c74 100644 --- a/README.md +++ b/README.md @@ -104,6 +104,7 @@ env: BYTEBASE_SERVICE_ACCOUNT: api@service.bytebase.com BYTEBASE_SERVICE_ACCOUNT_SECRET: ${{ secrets.BYTEBASE_SERVICE_ACCOUNT_SECRET }} BYTEBASE_PROJECT: "projects/hr" + FILE_PATTERN: "migrations-semver/*.sql" ``` 3. **Configure GitHub environments**: Create environments matching your config (e.g., "test", "prod") in repository settings. Add deployment protection rules for production environments.