Skip to content

Commit a76dca2

Browse files
committed
init
1 parent c369ab7 commit a76dca2

File tree

2 files changed

+209
-0
lines changed

2 files changed

+209
-0
lines changed

.github/workflows/release.yml

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
name: Build and push release image
2+
3+
on:
4+
push:
5+
branches:
6+
- test
7+
- prod
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v4
15+
- name: Build app and upload
16+
run: |
17+
echo "Building..."
18+
echo "Build done!"
19+
echo "Uploading..."
20+
echo "Upload done!"
21+
deploy-to-test:
22+
needs: build
23+
runs-on: ubuntu-latest # use self-hosted machines if your Bytebase runs in internal networks.
24+
environment: test
25+
env:
26+
BYTEBASE_URL: https://demo.bytebase.com
27+
BYTEBASE_SERVICE_ACCOUNT: [email protected]
28+
BYTEBASE_PROJECT: "projects/project-sample"
29+
BYTEBASE_TARGETS: "instances/test-sample-instance/databases/hr_test"
30+
FILE_PATTERN: "migrations/*.sql"
31+
if: github.ref == 'refs/heads/test'
32+
steps:
33+
- name: Checkout
34+
uses: actions/checkout@v4
35+
- name: Login to Bytebase
36+
id: login
37+
uses: bytebase/login-action@v1
38+
with:
39+
bytebase-url: ${{ env.BYTEBASE_URL }}
40+
service-key: ${{ env.BYTEBASE_SERVICE_ACCOUNT }}
41+
service-secret: ${{secrets.BYTEBASE_SERVICE_ACCOUNT_SECRET}} # Please use secrets for sensitive data in production.
42+
- name: Create release
43+
id: create-release
44+
uses: bytebase/create-release-action@v1
45+
with:
46+
url: ${{ env.BYTEBASE_URL }}
47+
token: ${{ steps.login.outputs.token }}
48+
file-pattern: ${{ env.FILE_PATTERN }}
49+
# fail the action if release checks report any error.
50+
check-release: "FAIL_ON_ERROR"
51+
project: ${{ env.BYTEBASE_PROJECT }}
52+
targets: ${{ env.BYTEBASE_TARGETS }}
53+
validate-only: false
54+
- name: Create plan
55+
id: create-plan
56+
uses: bytebase/create-plan-from-release-action@v1
57+
with:
58+
url: ${{ env.BYTEBASE_URL }}
59+
token: ${{ steps.login.outputs.token }}
60+
project: ${{ env.BYTEBASE_PROJECT }}
61+
release: ${{ steps.create-release.outputs.release }}
62+
targets: ${{ env.BYTEBASE_TARGETS }}
63+
check-plan: "SKIP"
64+
- name: Rollout
65+
id: rollout
66+
uses: bytebase/rollout-action@v2
67+
if: ${{ steps.create-plan.outputs.deployment-required == 'true' }}
68+
with:
69+
url: ${{ env.BYTEBASE_URL }}
70+
token: ${{ steps.login.outputs.token }}
71+
plan: ${{ steps.create-plan.outputs.plan }}
72+
target-stage: 'environments/test'
73+
- name: Deploy app
74+
run: |
75+
echo "Deploying app to test environment..."
76+
echo "Deploy app to test environment done!"
77+
deploy-to-prod:
78+
needs: build
79+
runs-on: ubuntu-latest # use self-hosted machines if your Bytebase runs in internal networks.
80+
environment: prod
81+
env:
82+
BYTEBASE_URL: https://demo.bytebase.com
83+
BYTEBASE_SERVICE_ACCOUNT: [email protected]
84+
BYTEBASE_PROJECT: "projects/project-sample"
85+
BYTEBASE_TARGETS: "instances/prod-sample-instance/databases/hr_prod"
86+
FILE_PATTERN: "migrations/*.sql"
87+
if: github.ref == 'refs/heads/prod'
88+
steps:
89+
- name: Checkout
90+
uses: actions/checkout@v4
91+
- name: Login to Bytebase
92+
id: login
93+
uses: bytebase/login-action@v1
94+
with:
95+
bytebase-url: ${{ env.BYTEBASE_URL }}
96+
service-key: ${{ env.BYTEBASE_SERVICE_ACCOUNT }}
97+
service-secret: ${{secrets.BYTEBASE_SERVICE_ACCOUNT_SECRET}} # Please use secrets for sensitive data in production.
98+
- name: Create release
99+
id: create-release
100+
uses: bytebase/create-release-action@v1
101+
with:
102+
url: ${{ env.BYTEBASE_URL }}
103+
token: ${{ steps.login.outputs.token }}
104+
file-pattern: ${{ env.FILE_PATTERN }}
105+
# fail the action if release checks report any error.
106+
check-release: "FAIL_ON_ERROR"
107+
project: ${{ env.BYTEBASE_PROJECT }}
108+
targets: ${{ env.BYTEBASE_TARGETS }}
109+
validate-only: false
110+
- name: Create plan
111+
id: create-plan
112+
uses: bytebase/create-plan-from-release-action@v1
113+
with:
114+
url: ${{ env.BYTEBASE_URL }}
115+
token: ${{ steps.login.outputs.token }}
116+
project: ${{ env.BYTEBASE_PROJECT }}
117+
release: ${{ steps.create-release.outputs.release }}
118+
targets: ${{ env.BYTEBASE_TARGETS }}
119+
check-plan: "SKIP"
120+
- name: Rollout
121+
id: rollout
122+
uses: bytebase/rollout-action@v2
123+
if: ${{ steps.create-plan.outputs.deployment-required == 'true' }}
124+
with:
125+
url: ${{ env.BYTEBASE_URL }}
126+
token: ${{ steps.login.outputs.token }}
127+
plan: ${{ steps.create-plan.outputs.plan }}
128+
target-stage: 'environments/prod'
129+
- name: Deploy app
130+
run: |
131+
echo "Deploying app to prod environment..."
132+
echo "Deploy app to prod environment done!"

.github/workflows/sql-review.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: SQL review on pull request
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- test
7+
- prod
8+
paths:
9+
- "migrations/*.sql"
10+
11+
jobs:
12+
check-release-on-test:
13+
permissions:
14+
pull-requests: write # write permission required to allow the action writes the check results to the comment.
15+
runs-on: ubuntu-latest # use self-hosted machines if your Bytebase runs in internal networks.
16+
env:
17+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # set GITHUB_TOKEN because the 'Check release' step needs it to comment the pull request with check results.
18+
BYTEBASE_URL: https://demo.bytebase.com
19+
BYTEBASE_SERVICE_ACCOUNT: [email protected]
20+
BYTEBASE_PROJECT: "projects/project-sample"
21+
BYTEBASE_TARGETS: "instances/test-sample-instance/databases/hr_test"
22+
FILE_PATTERN: "migrations/*.sql"
23+
if: github.base_ref == 'test'
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v4
27+
- name: Login to Bytebase
28+
id: login
29+
uses: bytebase/login-action@v1
30+
with:
31+
bytebase-url: ${{ env.BYTEBASE_URL }}
32+
service-key: ${{ env.BYTEBASE_SERVICE_ACCOUNT }}
33+
service-secret: ${{secrets.BYTEBASE_SERVICE_ACCOUNT_SECRET}} # Please use secrets for sensitive data in production.
34+
- name: Check release
35+
uses: bytebase/create-release-action@v1
36+
with:
37+
url: ${{ env.BYTEBASE_URL }}
38+
token: ${{ steps.login.outputs.token }}
39+
file-pattern: ${{ env.FILE_PATTERN }}
40+
# fail the action if release checks report any error.
41+
check-release: "FAIL_ON_ERROR"
42+
project: ${{ env.BYTEBASE_PROJECT }}
43+
targets: ${{ env.BYTEBASE_TARGETS }}
44+
validate-only: true
45+
check-release-on-prod:
46+
permissions:
47+
pull-requests: write # write permission required to allow the action writes the check results to the comment.
48+
runs-on: ubuntu-latest
49+
env:
50+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # set GITHUB_TOKEN because the 'Check release' step needs it to comment the pull request with check results.
51+
BYTEBASE_URL: https://demo.bytebase.com
52+
BYTEBASE_SERVICE_ACCOUNT: [email protected]
53+
BYTEBASE_PROJECT: "projects/project-sample"
54+
BYTEBASE_TARGETS: "instances/prod-sample-instance/databases/hr_prod"
55+
FILE_PATTERN: "migrations/*.sql"
56+
if: github.base_ref == 'prod'
57+
steps:
58+
- name: Checkout
59+
uses: actions/checkout@v4
60+
- name: Login to Bytebase
61+
id: login
62+
uses: bytebase/login-action@v1
63+
with:
64+
bytebase-url: ${{ env.BYTEBASE_URL }}
65+
service-key: ${{ env.BYTEBASE_SERVICE_ACCOUNT }}
66+
service-secret: ${{secrets.BYTEBASE_SERVICE_ACCOUNT_SECRET}} # Please use secrets for sensitive data in production.
67+
- name: Check release
68+
uses: bytebase/create-release-action@v1
69+
with:
70+
url: ${{ env.BYTEBASE_URL }}
71+
token: ${{ steps.login.outputs.token }}
72+
file-pattern: ${{ env.FILE_PATTERN }}
73+
# fail the action if release checks report any error.
74+
check-release: "FAIL_ON_ERROR"
75+
project: ${{ env.BYTEBASE_PROJECT }}
76+
targets: ${{ env.BYTEBASE_TARGETS }}
77+
validate-only: true

0 commit comments

Comments
 (0)