From aadd4cc912b0610f9e4e733cfacc52c37abfb0eb Mon Sep 17 00:00:00 2001 From: p0ny Date: Thu, 17 Apr 2025 14:28:00 +0800 Subject: [PATCH 01/23] test action --- .github/workflows/sql-review-action.yml | 27 +++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .github/workflows/sql-review-action.yml diff --git a/.github/workflows/sql-review-action.yml b/.github/workflows/sql-review-action.yml new file mode 100644 index 0000000..16df5f7 --- /dev/null +++ b/.github/workflows/sql-review-action.yml @@ -0,0 +1,27 @@ +name: SQL review on pull request using bytebase-action image + +on: + pull_request: + branches: + - main + paths: + - "migrations/*.sql" + +jobs: + check-release-on-test: + permissions: + pull-requests: write # write permission required to allow the action writes the check results to the comment. + runs-on: ubuntu-latest # use self-hosted machines if your Bytebase runs in internal networks. + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Check release + uses: docker://bytebase/bytebase-action:latest + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # set GITHUB_TOKEN because the 'Check release' step needs it to comment the pull request with check results. + BYTEBASE_URL: https://demo.bytebase.com + BYTEBASE_SERVICE_ACCOUNT: ci@service.bytebase.com + BYTEBASE_SERVICE_ACCOUNT_SECRET: ${{secrets.BYTEBASE_SERVICE_ACCOUNT_SECRET}} + BYTEBASE_PROJECT: "projects/project-sample" + BYTEBASE_TARGETS: "instances/test-sample-instance/databases/hr_test" + FILE_PATTERN: "migrations/*.sql" From b3b91153691744bab60c9522bb32144adbb40167 Mon Sep 17 00:00:00 2001 From: p0ny Date: Thu, 17 Apr 2025 14:30:13 +0800 Subject: [PATCH 02/23] sql --- migrations/202504171429_1.sql | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 migrations/202504171429_1.sql diff --git a/migrations/202504171429_1.sql b/migrations/202504171429_1.sql new file mode 100644 index 0000000..89cfa57 --- /dev/null +++ b/migrations/202504171429_1.sql @@ -0,0 +1,3 @@ +CREATE TABLE IF NOT EXISTS wer ( + id int +); \ No newline at end of file From 8cc8abe3909ff84eb60c9a4b3fabc1c574fab4b9 Mon Sep 17 00:00:00 2001 From: p0ny Date: Thu, 17 Apr 2025 14:34:49 +0800 Subject: [PATCH 03/23] u --- .github/workflows/sql-review-action.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/sql-review-action.yml b/.github/workflows/sql-review-action.yml index 16df5f7..9fd0385 100644 --- a/.github/workflows/sql-review-action.yml +++ b/.github/workflows/sql-review-action.yml @@ -8,7 +8,7 @@ on: - "migrations/*.sql" jobs: - check-release-on-test: + check-release-on-prod: permissions: pull-requests: write # write permission required to allow the action writes the check results to the comment. runs-on: ubuntu-latest # use self-hosted machines if your Bytebase runs in internal networks. @@ -23,5 +23,6 @@ jobs: BYTEBASE_SERVICE_ACCOUNT: ci@service.bytebase.com BYTEBASE_SERVICE_ACCOUNT_SECRET: ${{secrets.BYTEBASE_SERVICE_ACCOUNT_SECRET}} BYTEBASE_PROJECT: "projects/project-sample" - BYTEBASE_TARGETS: "instances/test-sample-instance/databases/hr_test" + BYTEBASE_TARGETS: "instances/test-sample-instance/databases/hr_prod" FILE_PATTERN: "migrations/*.sql" + GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }} From b4fbe6115d02993f1be3f0fd1539345cff6d6414 Mon Sep 17 00:00:00 2001 From: p0ny Date: Thu, 17 Apr 2025 14:35:52 +0800 Subject: [PATCH 04/23] u --- .github/workflows/sql-review-action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sql-review-action.yml b/.github/workflows/sql-review-action.yml index 9fd0385..16b8620 100644 --- a/.github/workflows/sql-review-action.yml +++ b/.github/workflows/sql-review-action.yml @@ -23,6 +23,6 @@ jobs: BYTEBASE_SERVICE_ACCOUNT: ci@service.bytebase.com BYTEBASE_SERVICE_ACCOUNT_SECRET: ${{secrets.BYTEBASE_SERVICE_ACCOUNT_SECRET}} BYTEBASE_PROJECT: "projects/project-sample" - BYTEBASE_TARGETS: "instances/test-sample-instance/databases/hr_prod" + BYTEBASE_TARGETS: "instances/prod-sample-instance/databases/hr_prod" FILE_PATTERN: "migrations/*.sql" GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }} From ef121eb53deaa768032f118f787021796937d6ad Mon Sep 17 00:00:00 2001 From: p0ny Date: Thu, 17 Apr 2025 15:26:58 +0800 Subject: [PATCH 05/23] u --- migrations/202504171526_2.sql | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 migrations/202504171526_2.sql diff --git a/migrations/202504171526_2.sql b/migrations/202504171526_2.sql new file mode 100644 index 0000000..6cceccc --- /dev/null +++ b/migrations/202504171526_2.sql @@ -0,0 +1,3 @@ +CREATE TABLE IF NOT EXISTS oijoir ( + id int +); \ No newline at end of file From 9617d336abf398398774b87c012657262a282377 Mon Sep 17 00:00:00 2001 From: p0ny Date: Thu, 17 Apr 2025 16:43:08 +0800 Subject: [PATCH 06/23] u --- .github/workflows/sql-review-action.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/sql-review-action.yml b/.github/workflows/sql-review-action.yml index 16b8620..85c54ff 100644 --- a/.github/workflows/sql-review-action.yml +++ b/.github/workflows/sql-review-action.yml @@ -15,6 +15,9 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + - name: print event + run: | + cat $GITHUB_EVENT_PATH - name: Check release uses: docker://bytebase/bytebase-action:latest env: From 5a9954d883966ae45cf6e3892021083bf35f7114 Mon Sep 17 00:00:00 2001 From: p0ny Date: Thu, 17 Apr 2025 16:58:06 +0800 Subject: [PATCH 07/23] Revert "u" This reverts commit 9617d336abf398398774b87c012657262a282377. --- .github/workflows/sql-review-action.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/sql-review-action.yml b/.github/workflows/sql-review-action.yml index 85c54ff..16b8620 100644 --- a/.github/workflows/sql-review-action.yml +++ b/.github/workflows/sql-review-action.yml @@ -15,9 +15,6 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - - name: print event - run: | - cat $GITHUB_EVENT_PATH - name: Check release uses: docker://bytebase/bytebase-action:latest env: From f6e2a4cfad126558478812de6e2c773fa5f198c8 Mon Sep 17 00:00:00 2001 From: p0ny Date: Thu, 17 Apr 2025 16:58:21 +0800 Subject: [PATCH 08/23] u --- .github/workflows/sql-review-action.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/sql-review-action.yml b/.github/workflows/sql-review-action.yml index 16b8620..4377f60 100644 --- a/.github/workflows/sql-review-action.yml +++ b/.github/workflows/sql-review-action.yml @@ -25,4 +25,3 @@ jobs: BYTEBASE_PROJECT: "projects/project-sample" BYTEBASE_TARGETS: "instances/prod-sample-instance/databases/hr_prod" FILE_PATTERN: "migrations/*.sql" - GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }} From 337d5f751dd5bca4a86220fbbdea0b3fe01a66f7 Mon Sep 17 00:00:00 2001 From: p0ny Date: Wed, 30 Apr 2025 17:59:39 +0800 Subject: [PATCH 09/23] Merge pull request #2 from RainbowDashy/test-action-2 test action --- .github/workflows/sql-review-action.yml | 3 +++ migrations/202504301754_1.sql | 3 +++ 2 files changed, 6 insertions(+) create mode 100644 migrations/202504301754_1.sql diff --git a/.github/workflows/sql-review-action.yml b/.github/workflows/sql-review-action.yml index 4377f60..26029a8 100644 --- a/.github/workflows/sql-review-action.yml +++ b/.github/workflows/sql-review-action.yml @@ -25,3 +25,6 @@ jobs: BYTEBASE_PROJECT: "projects/project-sample" BYTEBASE_TARGETS: "instances/prod-sample-instance/databases/hr_prod" FILE_PATTERN: "migrations/*.sql" + with: + entrypoint: bytebase-action + args: check --url ${{ env.BYTEBASE_URL }} --service-account ${{ env.BYTEBASE_SERVICE_ACCOUNT }} --project ${{ env.BYTEBASE_PROJECT }} --targets ${{ env.BYTEBASE_TARGETS }} --file-pattern ${{ env.FILE_PATTERN }} diff --git a/migrations/202504301754_1.sql b/migrations/202504301754_1.sql new file mode 100644 index 0000000..ca94e07 --- /dev/null +++ b/migrations/202504301754_1.sql @@ -0,0 +1,3 @@ +CREATE TABLE IF NOT EXISTS geoiwjgoiwerjg ( + id int +); \ No newline at end of file From bdbb9d84bbccaaf0a8011225af88b61c9f4a38de Mon Sep 17 00:00:00 2001 From: p0ny Date: Wed, 7 May 2025 12:00:54 +0800 Subject: [PATCH 10/23] u --- .github/workflows/release-action.yml | 48 ++++++++++++++++++++++++++++ .github/workflows/release.yml | 2 +- 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/release-action.yml diff --git a/.github/workflows/release-action.yml b/.github/workflows/release-action.yml new file mode 100644 index 0000000..c39cefb --- /dev/null +++ b/.github/workflows/release-action.yml @@ -0,0 +1,48 @@ +name: Rollout using bytebase-action image + +on: + push: + branches: + - main + - test-cd-action-1 + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Build app and upload + run: | + echo "Building..." + echo "Build done!" + echo "Uploading..." + echo "Upload done!" + deploy-to-all: + needs: build + runs-on: ubuntu-latest # use self-hosted machines if your Bytebase runs in internal networks. + outputs: + bytebase-plan: ${{ steps.create-plan.outputs.plan }} + deployment-required: ${{ steps.create-plan.outputs.deployment-required }} + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: rollout + uses: docker://bytebase/bytebase-action:latest + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + BYTEBASE_URL: https://demo.bytebase.com + BYTEBASE_SERVICE_ACCOUNT: ci@service.bytebase.com + BYTEBASE_SERVICE_ACCOUNT_SECRET: ${{secrets.BYTEBASE_SERVICE_ACCOUNT_SECRET}} + BYTEBASE_PROJECT: "projects/project-sample" + BYTEBASE_TARGETS: "instances/prod-sample-instance/databases/hr_prod" + BYTEBASE_TARGET_STAGE: environments/test + FILE_PATTERN: "migrations/*.sql" + BYTEBASE_OUTPUT: ${{ runner.temp }}/bytebase-metadata.json + with: + entrypoint: bytebase-action + args: rollout --url=${{ env.BYTEBASE_URL }} --service-account=${{ env.BYTEBASE_SERVICE_ACCOUNT }} --service-account-secret=${{ env.BYTEBASE_SERVICE_ACCOUNT_SECRET }} --project=${{ env.BYTEBASE_PROJECT }} --file-pattern=${{ env.FILE_PATTERN }} --targets=${{ env.BYTEBASE_TARGETS }} --target-stage=${{ env.BYTEBASE_TARGET_STAGE }} --output=${{ env.BYTEBASE_OUTPUT }} + - name: Check output + run: | + echo "Output: ${{ runner.temp }}/bytebase-metadata.json" + cat ${{ runner.temp }}/bytebase-metadata.json \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8728f9c..b0e3cc6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,4 +1,4 @@ -name: Build and push release image +name: Rollout on: push: From e0353d9528aa4ccede338225b1eb4325da10bd94 Mon Sep 17 00:00:00 2001 From: p0ny Date: Wed, 7 May 2025 15:31:29 +0800 Subject: [PATCH 11/23] p --- .github/workflows/release-action.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/release-action.yml b/.github/workflows/release-action.yml index c39cefb..094c8e7 100644 --- a/.github/workflows/release-action.yml +++ b/.github/workflows/release-action.yml @@ -27,6 +27,9 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + - name: ls + run: | + ls -al migrations - name: rollout uses: docker://bytebase/bytebase-action:latest env: From d7fb40b9fb7481c2ecc758dd8b65684631ff1605 Mon Sep 17 00:00:00 2001 From: p0ny Date: Wed, 7 May 2025 15:32:34 +0800 Subject: [PATCH 12/23] targets --- .github/workflows/release-action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release-action.yml b/.github/workflows/release-action.yml index 094c8e7..7d2d6e8 100644 --- a/.github/workflows/release-action.yml +++ b/.github/workflows/release-action.yml @@ -38,7 +38,7 @@ jobs: BYTEBASE_SERVICE_ACCOUNT: ci@service.bytebase.com BYTEBASE_SERVICE_ACCOUNT_SECRET: ${{secrets.BYTEBASE_SERVICE_ACCOUNT_SECRET}} BYTEBASE_PROJECT: "projects/project-sample" - BYTEBASE_TARGETS: "instances/prod-sample-instance/databases/hr_prod" + BYTEBASE_TARGETS: "instances/test-sample-instance/databases/hr_test,instances/prod-sample-instance/databases/hr_prod" BYTEBASE_TARGET_STAGE: environments/test FILE_PATTERN: "migrations/*.sql" BYTEBASE_OUTPUT: ${{ runner.temp }}/bytebase-metadata.json From 34a10a45e08a862ad33497ce2c4fd9b0485d4025 Mon Sep 17 00:00:00 2001 From: p0ny Date: Wed, 7 May 2025 15:43:18 +0800 Subject: [PATCH 13/23] u --- migrations/202503141135_sleep.sql | 1 - 1 file changed, 1 deletion(-) delete mode 100644 migrations/202503141135_sleep.sql diff --git a/migrations/202503141135_sleep.sql b/migrations/202503141135_sleep.sql deleted file mode 100644 index 52b20e4..0000000 --- a/migrations/202503141135_sleep.sql +++ /dev/null @@ -1 +0,0 @@ -select sleep(100000) From 2dd4f27d87620d85e8feeb9357a2857981f69f84 Mon Sep 17 00:00:00 2001 From: p0ny Date: Wed, 7 May 2025 15:58:01 +0800 Subject: [PATCH 14/23] fix sql --- migrations/202503181018_ticket_table_add_date_column.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migrations/202503181018_ticket_table_add_date_column.sql b/migrations/202503181018_ticket_table_add_date_column.sql index e9549c7..025d45f 100644 --- a/migrations/202503181018_ticket_table_add_date_column.sql +++ b/migrations/202503181018_ticket_table_add_date_column.sql @@ -1 +1 @@ -ALTER TABLE IF EXISTS ticket ADD release_date DATE; +ALTER TABLE IF EXISTS ticket ADD IF NOT EXISTS release_date DATE; From 95e2e01601ae82bd551c47c3665443f5fd19ac2f Mon Sep 17 00:00:00 2001 From: p0ny Date: Wed, 7 May 2025 16:35:25 +0800 Subject: [PATCH 15/23] chore: use /bin/sh as entrypoint --- .github/workflows/release-action.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/release-action.yml b/.github/workflows/release-action.yml index 7d2d6e8..9eae8c5 100644 --- a/.github/workflows/release-action.yml +++ b/.github/workflows/release-action.yml @@ -27,9 +27,6 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - - name: ls - run: | - ls -al migrations - name: rollout uses: docker://bytebase/bytebase-action:latest env: @@ -43,9 +40,10 @@ jobs: FILE_PATTERN: "migrations/*.sql" BYTEBASE_OUTPUT: ${{ runner.temp }}/bytebase-metadata.json with: - entrypoint: bytebase-action - args: rollout --url=${{ env.BYTEBASE_URL }} --service-account=${{ env.BYTEBASE_SERVICE_ACCOUNT }} --service-account-secret=${{ env.BYTEBASE_SERVICE_ACCOUNT_SECRET }} --project=${{ env.BYTEBASE_PROJECT }} --file-pattern=${{ env.FILE_PATTERN }} --targets=${{ env.BYTEBASE_TARGETS }} --target-stage=${{ env.BYTEBASE_TARGET_STAGE }} --output=${{ env.BYTEBASE_OUTPUT }} + entrypoint: /bin/sh + args: bytebase-action rollout --url=${{ env.BYTEBASE_URL }} --service-account=${{ env.BYTEBASE_SERVICE_ACCOUNT }} --service-account-secret=${{ env.BYTEBASE_SERVICE_ACCOUNT_SECRET }} --project=${{ env.BYTEBASE_PROJECT }} --file-pattern=${{ env.FILE_PATTERN }} --targets=${{ env.BYTEBASE_TARGETS }} --target-stage=${{ env.BYTEBASE_TARGET_STAGE }} --output=${{ env.BYTEBASE_OUTPUT }} - name: Check output run: | + ls -al ${{ runner.temp }} echo "Output: ${{ runner.temp }}/bytebase-metadata.json" cat ${{ runner.temp }}/bytebase-metadata.json \ No newline at end of file From 3baac5d088d0e7964120e86ddc6b01b29ea84499 Mon Sep 17 00:00:00 2001 From: p0ny Date: Wed, 7 May 2025 16:54:00 +0800 Subject: [PATCH 16/23] -c --- .github/workflows/release-action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release-action.yml b/.github/workflows/release-action.yml index 9eae8c5..d8fe8c7 100644 --- a/.github/workflows/release-action.yml +++ b/.github/workflows/release-action.yml @@ -41,7 +41,7 @@ jobs: BYTEBASE_OUTPUT: ${{ runner.temp }}/bytebase-metadata.json with: entrypoint: /bin/sh - args: bytebase-action rollout --url=${{ env.BYTEBASE_URL }} --service-account=${{ env.BYTEBASE_SERVICE_ACCOUNT }} --service-account-secret=${{ env.BYTEBASE_SERVICE_ACCOUNT_SECRET }} --project=${{ env.BYTEBASE_PROJECT }} --file-pattern=${{ env.FILE_PATTERN }} --targets=${{ env.BYTEBASE_TARGETS }} --target-stage=${{ env.BYTEBASE_TARGET_STAGE }} --output=${{ env.BYTEBASE_OUTPUT }} + args: -c bytebase-action rollout --url=${{ env.BYTEBASE_URL }} --service-account=${{ env.BYTEBASE_SERVICE_ACCOUNT }} --service-account-secret=${{ env.BYTEBASE_SERVICE_ACCOUNT_SECRET }} --project=${{ env.BYTEBASE_PROJECT }} --file-pattern=${{ env.FILE_PATTERN }} --targets=${{ env.BYTEBASE_TARGETS }} --target-stage=${{ env.BYTEBASE_TARGET_STAGE }} --output=${{ env.BYTEBASE_OUTPUT }} - name: Check output run: | ls -al ${{ runner.temp }} From 2a8e1aa69f06714173138385764e15fe42672b1d Mon Sep 17 00:00:00 2001 From: p0ny Date: Wed, 7 May 2025 16:55:09 +0800 Subject: [PATCH 17/23] ls --- .github/workflows/release-action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release-action.yml b/.github/workflows/release-action.yml index d8fe8c7..766fdb0 100644 --- a/.github/workflows/release-action.yml +++ b/.github/workflows/release-action.yml @@ -41,7 +41,7 @@ jobs: BYTEBASE_OUTPUT: ${{ runner.temp }}/bytebase-metadata.json with: entrypoint: /bin/sh - args: -c bytebase-action rollout --url=${{ env.BYTEBASE_URL }} --service-account=${{ env.BYTEBASE_SERVICE_ACCOUNT }} --service-account-secret=${{ env.BYTEBASE_SERVICE_ACCOUNT_SECRET }} --project=${{ env.BYTEBASE_PROJECT }} --file-pattern=${{ env.FILE_PATTERN }} --targets=${{ env.BYTEBASE_TARGETS }} --target-stage=${{ env.BYTEBASE_TARGET_STAGE }} --output=${{ env.BYTEBASE_OUTPUT }} + args: -c 'bytebase-action rollout --url=${{ env.BYTEBASE_URL }} --service-account=${{ env.BYTEBASE_SERVICE_ACCOUNT }} --service-account-secret=${{ env.BYTEBASE_SERVICE_ACCOUNT_SECRET }} --project=${{ env.BYTEBASE_PROJECT }} --file-pattern=${{ env.FILE_PATTERN }} --targets=${{ env.BYTEBASE_TARGETS }} --target-stage=${{ env.BYTEBASE_TARGET_STAGE }} --output=${{ env.BYTEBASE_OUTPUT }} && ls -al ${{ runner.temp }}' - name: Check output run: | ls -al ${{ runner.temp }} From 5e05c8ee68247b969d552c1ad331b79a0f718309 Mon Sep 17 00:00:00 2001 From: p0ny Date: Wed, 7 May 2025 16:58:14 +0800 Subject: [PATCH 18/23] gemini attempt 1 --- .github/workflows/release-action.yml | 74 ++++++++++++++++++++++++++-- 1 file changed, 69 insertions(+), 5 deletions(-) diff --git a/.github/workflows/release-action.yml b/.github/workflows/release-action.yml index 766fdb0..a944bd9 100644 --- a/.github/workflows/release-action.yml +++ b/.github/workflows/release-action.yml @@ -21,13 +21,17 @@ jobs: deploy-to-all: needs: build runs-on: ubuntu-latest # use self-hosted machines if your Bytebase runs in internal networks. + # Note: The 'outputs' section below refers to 'steps.create-plan', + # which is not defined in this job. You might need to adjust this + # if you intend to output data from the 'rollout' step. outputs: - bytebase-plan: ${{ steps.create-plan.outputs.plan }} + bytebase-plan: ${{ steps.create-plan.outputs.plan }} deployment-required: ${{ steps.create-plan.outputs.deployment-required }} steps: - name: Checkout uses: actions/checkout@v4 - name: rollout + id: bytebase_rollout # Added an id for potential future use with outputs uses: docker://bytebase/bytebase-action:latest env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -38,12 +42,72 @@ jobs: BYTEBASE_TARGETS: "instances/test-sample-instance/databases/hr_test,instances/prod-sample-instance/databases/hr_prod" BYTEBASE_TARGET_STAGE: environments/test FILE_PATTERN: "migrations/*.sql" - BYTEBASE_OUTPUT: ${{ runner.temp }}/bytebase-metadata.json + # Define the output path using runner.temp; GitHub Actions should handle syncing this + BYTEBASE_OUTPUT_FILE_PATH: "${{ runner.temp }}/bytebase-metadata.json" with: entrypoint: /bin/sh - args: -c 'bytebase-action rollout --url=${{ env.BYTEBASE_URL }} --service-account=${{ env.BYTEBASE_SERVICE_ACCOUNT }} --service-account-secret=${{ env.BYTEBASE_SERVICE_ACCOUNT_SECRET }} --project=${{ env.BYTEBASE_PROJECT }} --file-pattern=${{ env.FILE_PATTERN }} --targets=${{ env.BYTEBASE_TARGETS }} --target-stage=${{ env.BYTEBASE_TARGET_STAGE }} --output=${{ env.BYTEBASE_OUTPUT }} && ls -al ${{ runner.temp }}' + args: | + -c " + echo '--- Starting bytebase-action script ---' + echo 'Runner temp directory (inside container context): ${{ runner.temp }}' + echo 'Target output file path: ${{ env.BYTEBASE_OUTPUT_FILE_PATH }}' + + # Ensure the target directory for the output file exists + # dirname needs the path, so quote it properly + TARGET_DIR=$(dirname \"${{ env.BYTEBASE_OUTPUT_FILE_PATH }}\") + echo \"Ensuring output directory exists: $TARGET_DIR\" + mkdir -p \"$TARGET_DIR\" + + echo 'Executing: bytebase-action rollout ...' + # Execute the bytebase-action command + # Ensure arguments with environment variables are properly quoted if they might contain spaces + # or special characters, though for these specific env vars, it might not be strictly needed. + bytebase-action rollout \ + --url='${{ env.BYTEBASE_URL }}' \ + --service-account='${{ env.BYTEBASE_SERVICE_ACCOUNT }}' \ + --service-account-secret='${{ env.BYTEBASE_SERVICE_ACCOUNT_SECRET }}' \ + --project='${{ env.BYTEBASE_PROJECT }}' \ + --file-pattern='${{ env.FILE_PATTERN }}' \ + --targets='${{ env.BYTEBASE_TARGETS }}' \ + --target-stage='${{ env.BYTEBASE_TARGET_STAGE }}' \ + --output='${{ env.BYTEBASE_OUTPUT_FILE_PATH }}' + + ACTION_EXIT_CODE=$? + echo \"bytebase-action rollout command finished with exit code: $ACTION_EXIT_CODE\" + + # Check if the action succeeded and if the file was created + if [ $ACTION_EXIT_CODE -eq 0 ]; then + echo 'Action succeeded. Checking for output file existence inside container script:' + if [ -f \"${{ env.BYTEBASE_OUTPUT_FILE_PATH }}\" ]; then + echo 'Output file FOUND by script:' + ls -l \"${{ env.BYTEBASE_OUTPUT_FILE_PATH }}\" + echo '--- Content of output file (from inside action script) ---' + cat \"${{ env.BYTEBASE_OUTPUT_FILE_PATH }}\" + echo '--- End of content ---' + else + echo 'Output file NOT FOUND by script at ${{ env.BYTEBASE_OUTPUT_FILE_PATH }}.' + echo 'Listing directory contents of $TARGET_DIR:' + ls -la \"$TARGET_DIR\" + fi + else + echo 'bytebase-action command failed (exit code $ACTION_EXIT_CODE), skipping output file check by script.' + fi + echo '--- Ending bytebase-action script ---' + # Propagate the exit code of the bytebase-action command + exit $ACTION_EXIT_CODE + " - name: Check output + # This step will run by default only if the 'rollout' step succeeds. + # If you want it to run even if 'rollout' fails (e.g., for debugging), add: if: always() run: | + echo "--- Check output step on runner ---" + echo "Runner temp directory (on runner): ${{ runner.temp }}" + echo "Expected output file (on runner): ${{ runner.temp }}/bytebase-metadata.json" + echo "Listing contents of ${{ runner.temp }} on runner:" ls -al ${{ runner.temp }} - echo "Output: ${{ runner.temp }}/bytebase-metadata.json" - cat ${{ runner.temp }}/bytebase-metadata.json \ No newline at end of file + echo "Attempting to cat the file from runner:" + # Use the same env var name for consistency, or the direct path + cat ${{ env.BYTEBASE_OUTPUT_FILE_PATH }} # This env var was set in the previous step, + # but it's better to use the known path directly if env var scope is an issue. + # Using the explicit path: + # cat ${{ runner.temp }}/bytebase-metadata.json From ca4aa5d91885fc26b453b1f658d85b6d9388bc9e Mon Sep 17 00:00:00 2001 From: p0ny Date: Wed, 7 May 2025 17:05:14 +0800 Subject: [PATCH 19/23] job container --- .github/workflows/release-action.yml | 81 ++++------------------------ 1 file changed, 9 insertions(+), 72 deletions(-) diff --git a/.github/workflows/release-action.yml b/.github/workflows/release-action.yml index a944bd9..4d7c628 100644 --- a/.github/workflows/release-action.yml +++ b/.github/workflows/release-action.yml @@ -21,18 +21,15 @@ jobs: deploy-to-all: needs: build runs-on: ubuntu-latest # use self-hosted machines if your Bytebase runs in internal networks. - # Note: The 'outputs' section below refers to 'steps.create-plan', - # which is not defined in this job. You might need to adjust this - # if you intend to output data from the 'rollout' step. + container: + image: docker://bytebase/bytebase-action:latest outputs: - bytebase-plan: ${{ steps.create-plan.outputs.plan }} + bytebase-plan: ${{ steps.create-plan.outputs.plan }} deployment-required: ${{ steps.create-plan.outputs.deployment-required }} steps: - name: Checkout uses: actions/checkout@v4 - name: rollout - id: bytebase_rollout # Added an id for potential future use with outputs - uses: docker://bytebase/bytebase-action:latest env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} BYTEBASE_URL: https://demo.bytebase.com @@ -42,72 +39,12 @@ jobs: BYTEBASE_TARGETS: "instances/test-sample-instance/databases/hr_test,instances/prod-sample-instance/databases/hr_prod" BYTEBASE_TARGET_STAGE: environments/test FILE_PATTERN: "migrations/*.sql" - # Define the output path using runner.temp; GitHub Actions should handle syncing this - BYTEBASE_OUTPUT_FILE_PATH: "${{ runner.temp }}/bytebase-metadata.json" - with: - entrypoint: /bin/sh - args: | - -c " - echo '--- Starting bytebase-action script ---' - echo 'Runner temp directory (inside container context): ${{ runner.temp }}' - echo 'Target output file path: ${{ env.BYTEBASE_OUTPUT_FILE_PATH }}' - - # Ensure the target directory for the output file exists - # dirname needs the path, so quote it properly - TARGET_DIR=$(dirname \"${{ env.BYTEBASE_OUTPUT_FILE_PATH }}\") - echo \"Ensuring output directory exists: $TARGET_DIR\" - mkdir -p \"$TARGET_DIR\" - - echo 'Executing: bytebase-action rollout ...' - # Execute the bytebase-action command - # Ensure arguments with environment variables are properly quoted if they might contain spaces - # or special characters, though for these specific env vars, it might not be strictly needed. - bytebase-action rollout \ - --url='${{ env.BYTEBASE_URL }}' \ - --service-account='${{ env.BYTEBASE_SERVICE_ACCOUNT }}' \ - --service-account-secret='${{ env.BYTEBASE_SERVICE_ACCOUNT_SECRET }}' \ - --project='${{ env.BYTEBASE_PROJECT }}' \ - --file-pattern='${{ env.FILE_PATTERN }}' \ - --targets='${{ env.BYTEBASE_TARGETS }}' \ - --target-stage='${{ env.BYTEBASE_TARGET_STAGE }}' \ - --output='${{ env.BYTEBASE_OUTPUT_FILE_PATH }}' - - ACTION_EXIT_CODE=$? - echo \"bytebase-action rollout command finished with exit code: $ACTION_EXIT_CODE\" - - # Check if the action succeeded and if the file was created - if [ $ACTION_EXIT_CODE -eq 0 ]; then - echo 'Action succeeded. Checking for output file existence inside container script:' - if [ -f \"${{ env.BYTEBASE_OUTPUT_FILE_PATH }}\" ]; then - echo 'Output file FOUND by script:' - ls -l \"${{ env.BYTEBASE_OUTPUT_FILE_PATH }}\" - echo '--- Content of output file (from inside action script) ---' - cat \"${{ env.BYTEBASE_OUTPUT_FILE_PATH }}\" - echo '--- End of content ---' - else - echo 'Output file NOT FOUND by script at ${{ env.BYTEBASE_OUTPUT_FILE_PATH }}.' - echo 'Listing directory contents of $TARGET_DIR:' - ls -la \"$TARGET_DIR\" - fi - else - echo 'bytebase-action command failed (exit code $ACTION_EXIT_CODE), skipping output file check by script.' - fi - echo '--- Ending bytebase-action script ---' - # Propagate the exit code of the bytebase-action command - exit $ACTION_EXIT_CODE - " + BYTEBASE_OUTPUT: ${{ runner.temp }}/bytebase-metadata.json + run: | + bytebase-action rollout --url=${{ env.BYTEBASE_URL }} --service-account=${{ env.BYTEBASE_SERVICE_ACCOUNT }} --service-account-secret=${{ env.BYTEBASE_SERVICE_ACCOUNT_SECRET }} --project=${{ env.BYTEBASE_PROJECT }} --file-pattern=${{ env.FILE_PATTERN }} --targets=${{ env.BYTEBASE_TARGETS }} --target-stage=${{ env.BYTEBASE_TARGET_STAGE }} --output=${{ env.BYTEBASE_OUTPUT }} + ls -al ${{ runner.temp }} - name: Check output - # This step will run by default only if the 'rollout' step succeeds. - # If you want it to run even if 'rollout' fails (e.g., for debugging), add: if: always() run: | - echo "--- Check output step on runner ---" - echo "Runner temp directory (on runner): ${{ runner.temp }}" - echo "Expected output file (on runner): ${{ runner.temp }}/bytebase-metadata.json" - echo "Listing contents of ${{ runner.temp }} on runner:" ls -al ${{ runner.temp }} - echo "Attempting to cat the file from runner:" - # Use the same env var name for consistency, or the direct path - cat ${{ env.BYTEBASE_OUTPUT_FILE_PATH }} # This env var was set in the previous step, - # but it's better to use the known path directly if env var scope is an issue. - # Using the explicit path: - # cat ${{ runner.temp }}/bytebase-metadata.json + echo "Output: ${{ runner.temp }}/bytebase-metadata.json" + cat ${{ runner.temp }}/bytebase-metadata.json \ No newline at end of file From 7ba376410a2ac3bde5282c96d2a2de3bbc9a6df6 Mon Sep 17 00:00:00 2001 From: p0ny Date: Wed, 7 May 2025 17:44:29 +0800 Subject: [PATCH 20/23] set output --- .github/workflows/release-action.yml | 29 ++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/.github/workflows/release-action.yml b/.github/workflows/release-action.yml index 4d7c628..6a640eb 100644 --- a/.github/workflows/release-action.yml +++ b/.github/workflows/release-action.yml @@ -18,14 +18,14 @@ jobs: echo "Build done!" echo "Uploading..." echo "Upload done!" - deploy-to-all: + deploy-to-test: needs: build runs-on: ubuntu-latest # use self-hosted machines if your Bytebase runs in internal networks. + environment: test container: image: docker://bytebase/bytebase-action:latest outputs: - bytebase-plan: ${{ steps.create-plan.outputs.plan }} - deployment-required: ${{ steps.create-plan.outputs.deployment-required }} + bytebase-plan: ${{ steps.set-output.outputs.plan }} steps: - name: Checkout uses: actions/checkout@v4 @@ -42,9 +42,22 @@ jobs: BYTEBASE_OUTPUT: ${{ runner.temp }}/bytebase-metadata.json run: | bytebase-action rollout --url=${{ env.BYTEBASE_URL }} --service-account=${{ env.BYTEBASE_SERVICE_ACCOUNT }} --service-account-secret=${{ env.BYTEBASE_SERVICE_ACCOUNT_SECRET }} --project=${{ env.BYTEBASE_PROJECT }} --file-pattern=${{ env.FILE_PATTERN }} --targets=${{ env.BYTEBASE_TARGETS }} --target-stage=${{ env.BYTEBASE_TARGET_STAGE }} --output=${{ env.BYTEBASE_OUTPUT }} - ls -al ${{ runner.temp }} - - name: Check output + - name: Set output + id: set-output run: | - ls -al ${{ runner.temp }} - echo "Output: ${{ runner.temp }}/bytebase-metadata.json" - cat ${{ runner.temp }}/bytebase-metadata.json \ No newline at end of file + PLAN=$(jq -r .plan ${{ runner.temp }}/bytebase-metadata.json) + echo "plan=$PLAN" >> $GITHUB_OUTPUT + deploy-to-prod: + needs: deploy-to-test + runs-on: ubuntu-latest + environment: prod + container: + image: docker://bytebase/bytebase-action:latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: rollout + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + echo ${{ needs.deploy-to-test.outputs.bytebase-plan }} From 512636ec41e6752784986f738e563c847a0f2ad5 Mon Sep 17 00:00:00 2001 From: p0ny Date: Thu, 8 May 2025 10:43:59 +0800 Subject: [PATCH 21/23] deploy to prod --- .github/workflows/release-action.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release-action.yml b/.github/workflows/release-action.yml index 6a640eb..1edfc00 100644 --- a/.github/workflows/release-action.yml +++ b/.github/workflows/release-action.yml @@ -59,5 +59,10 @@ jobs: - name: rollout env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + BYTEBASE_URL: https://demo.bytebase.com + BYTEBASE_SERVICE_ACCOUNT: ci@service.bytebase.com + BYTEBASE_SERVICE_ACCOUNT_SECRET: ${{secrets.BYTEBASE_SERVICE_ACCOUNT_SECRET}} + BYTEBASE_PROJECT: "projects/project-sample" + BYTEBASE_TARGET_STAGE: environments/prod run: | - echo ${{ needs.deploy-to-test.outputs.bytebase-plan }} + bytebase-action rollout --url=${{ env.BYTEBASE_URL }} --service-account=${{ env.BYTEBASE_SERVICE_ACCOUNT }} --service-account-secret=${{ env.BYTEBASE_SERVICE_ACCOUNT_SECRET }} --project=${{ env.BYTEBASE_PROJECT }} --target-stage=${{ env.BYTEBASE_TARGET_STAGE }} --plan=${{ needs.deploy-to-test.outputs.bytebase-plan }} \ No newline at end of file From c8dc2891e7d69933d45ce1f1481ec3cea0dc3462 Mon Sep 17 00:00:00 2001 From: p0ny Date: Thu, 8 May 2025 11:24:24 +0800 Subject: [PATCH 22/23] echo --- .github/workflows/release-action.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release-action.yml b/.github/workflows/release-action.yml index 1edfc00..a24f695 100644 --- a/.github/workflows/release-action.yml +++ b/.github/workflows/release-action.yml @@ -47,6 +47,10 @@ jobs: run: | PLAN=$(jq -r .plan ${{ runner.temp }}/bytebase-metadata.json) echo "plan=$PLAN" >> $GITHUB_OUTPUT + - name: Deploy app + run: | + echo "Deploying app to test environment..." + echo "Deploy app to test environment done!" deploy-to-prod: needs: deploy-to-test runs-on: ubuntu-latest @@ -65,4 +69,8 @@ jobs: BYTEBASE_PROJECT: "projects/project-sample" BYTEBASE_TARGET_STAGE: environments/prod run: | - bytebase-action rollout --url=${{ env.BYTEBASE_URL }} --service-account=${{ env.BYTEBASE_SERVICE_ACCOUNT }} --service-account-secret=${{ env.BYTEBASE_SERVICE_ACCOUNT_SECRET }} --project=${{ env.BYTEBASE_PROJECT }} --target-stage=${{ env.BYTEBASE_TARGET_STAGE }} --plan=${{ needs.deploy-to-test.outputs.bytebase-plan }} \ No newline at end of file + bytebase-action rollout --url=${{ env.BYTEBASE_URL }} --service-account=${{ env.BYTEBASE_SERVICE_ACCOUNT }} --service-account-secret=${{ env.BYTEBASE_SERVICE_ACCOUNT_SECRET }} --project=${{ env.BYTEBASE_PROJECT }} --target-stage=${{ env.BYTEBASE_TARGET_STAGE }} --plan=${{ needs.deploy-to-test.outputs.bytebase-plan }} + - name: Deploy app + run: | + echo "Deploying app to prod environment..." + echo "Deploy app to prod environment done!" \ No newline at end of file From be3244774bcb335853576ca706d7af397a1e2474 Mon Sep 17 00:00:00 2001 From: p0ny Date: Thu, 8 May 2025 11:25:33 +0800 Subject: [PATCH 23/23] push --- .github/workflows/release-action.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/release-action.yml b/.github/workflows/release-action.yml index a24f695..4f3bee1 100644 --- a/.github/workflows/release-action.yml +++ b/.github/workflows/release-action.yml @@ -4,7 +4,6 @@ on: push: branches: - main - - test-cd-action-1 jobs: build: