Skip to content

Commit a666949

Browse files
authored
feat: examples using bytebase-action (#19)
1 parent cfb2f4c commit a666949

8 files changed

+116
-3
lines changed

.github/workflows/release-action.yml

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Rollout using bytebase-action image
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v4
14+
- name: Build app and upload
15+
run: |
16+
echo "Building..."
17+
echo "Build done!"
18+
echo "Uploading..."
19+
echo "Upload done!"
20+
deploy-to-test:
21+
needs: build
22+
runs-on: ubuntu-latest # use self-hosted machines if your Bytebase runs in internal networks.
23+
environment: test
24+
container:
25+
image: docker://bytebase/bytebase-action:latest
26+
outputs:
27+
bytebase-plan: ${{ steps.set-output.outputs.plan }}
28+
steps:
29+
- name: Checkout
30+
uses: actions/checkout@v4
31+
- name: rollout
32+
env:
33+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34+
BYTEBASE_URL: https://demo.bytebase.com
35+
BYTEBASE_SERVICE_ACCOUNT: [email protected]
36+
BYTEBASE_SERVICE_ACCOUNT_SECRET: ${{secrets.BYTEBASE_SERVICE_ACCOUNT_SECRET}}
37+
BYTEBASE_PROJECT: "projects/project-sample"
38+
BYTEBASE_TARGETS: "instances/test-sample-instance/databases/hr_test,instances/prod-sample-instance/databases/hr_prod"
39+
BYTEBASE_TARGET_STAGE: environments/test
40+
FILE_PATTERN: "migrations/*.sql"
41+
BYTEBASE_OUTPUT: ${{ runner.temp }}/bytebase-metadata.json
42+
run: |
43+
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 }}
44+
- name: Set output
45+
id: set-output
46+
run: |
47+
PLAN=$(jq -r .plan ${{ runner.temp }}/bytebase-metadata.json)
48+
echo "plan=$PLAN" >> $GITHUB_OUTPUT
49+
- name: Deploy app
50+
run: |
51+
echo "Deploying app to test environment..."
52+
echo "Deploy app to test environment done!"
53+
deploy-to-prod:
54+
needs: deploy-to-test
55+
runs-on: ubuntu-latest
56+
environment: prod
57+
container:
58+
image: docker://bytebase/bytebase-action:latest
59+
steps:
60+
- name: Checkout
61+
uses: actions/checkout@v4
62+
- name: rollout
63+
env:
64+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
65+
BYTEBASE_URL: https://demo.bytebase.com
66+
BYTEBASE_SERVICE_ACCOUNT: [email protected]
67+
BYTEBASE_SERVICE_ACCOUNT_SECRET: ${{secrets.BYTEBASE_SERVICE_ACCOUNT_SECRET}}
68+
BYTEBASE_PROJECT: "projects/project-sample"
69+
BYTEBASE_TARGET_STAGE: environments/prod
70+
run: |
71+
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 }}
72+
- name: Deploy app
73+
run: |
74+
echo "Deploying app to prod environment..."
75+
echo "Deploy app to prod environment done!"

.github/workflows/release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build and push release image
1+
name: Rollout
22

33
on:
44
push:
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: SQL review on pull request using bytebase-action image
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
paths:
8+
- "migrations/*.sql"
9+
10+
jobs:
11+
check-release-on-prod:
12+
permissions:
13+
pull-requests: write # write permission required to allow the action writes the check results to the comment.
14+
runs-on: ubuntu-latest # use self-hosted machines if your Bytebase runs in internal networks.
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
- name: Check release
19+
uses: docker://bytebase/bytebase-action:latest
20+
env:
21+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # set GITHUB_TOKEN because the 'Check release' step needs it to comment the pull request with check results.
22+
BYTEBASE_URL: https://demo.bytebase.com
23+
BYTEBASE_SERVICE_ACCOUNT: [email protected]
24+
BYTEBASE_SERVICE_ACCOUNT_SECRET: ${{secrets.BYTEBASE_SERVICE_ACCOUNT_SECRET}}
25+
BYTEBASE_PROJECT: "projects/project-sample"
26+
BYTEBASE_TARGETS: "instances/prod-sample-instance/databases/hr_prod"
27+
FILE_PATTERN: "migrations/*.sql"
28+
with:
29+
entrypoint: bytebase-action
30+
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 }}

migrations/202503141135_sleep.sql

-1
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
ALTER TABLE IF EXISTS ticket ADD release_date DATE;
1+
ALTER TABLE IF EXISTS ticket ADD IF NOT EXISTS release_date DATE;

migrations/202504171429_1.sql

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CREATE TABLE IF NOT EXISTS wer (
2+
id int
3+
);

migrations/202504171526_2.sql

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CREATE TABLE IF NOT EXISTS oijoir (
2+
id int
3+
);

migrations/202504301754_1.sql

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CREATE TABLE IF NOT EXISTS geoiwjgoiwerjg (
2+
id int
3+
);

0 commit comments

Comments
 (0)