chore: use path filter (#3) #5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and push release image | |
on: | |
push: | |
branches: | |
- main | |
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_test: | |
needs: build | |
runs-on: ubuntu-latest # use self-hosted machines if your Bytebase runs in internal networks. | |
environment: test | |
env: | |
BYTEBASE_URL: https://demo.bytebase.com | |
BYTEBASE_SERVICE_ACCOUNT: [email protected] | |
BYTEBASE_PROJECT: "projects/project-sample" | |
# The Bytebase rollout pipeline will deploy to 'test' and 'prod' environments. | |
# 'deploy_to_test' job rollouts the 'test' stage and 'deploy_to_prod' job rollouts the 'prod' stage. | |
BYTEBASE_TARGETS: "instances/test-sample-instance/databases/hr_test,instances/prod-sample-instance/databases/hr_prod" | |
FILE_PATTERN: "migrations/*.sql" | |
outputs: | |
bytebase_plan: ${{ steps.create_plan.outputs.plan }} | |
deployment_required: ${{ steps.create_plan.outputs.deployment-required }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Login to Bytebase | |
id: login | |
uses: bytebase/login-action@v1 | |
with: | |
bytebase-url: ${{ env.BYTEBASE_URL }} | |
service-key: ${{ env.BYTEBASE_SERVICE_ACCOUNT }} | |
service-secret: ${{secrets.BYTEBASE_SERVICE_ACCOUNT_SECRET}} # Please use secrets for sensitive data in production. | |
- name: Create release | |
id: create_release | |
uses: bytebase/create-release-action@v1 | |
with: | |
url: ${{ env.BYTEBASE_URL }} | |
token: ${{ steps.login.outputs.token }} | |
file-pattern: ${{ env.FILE_PATTERN }} | |
# fail the action if release checks report any error. | |
check-release: "FAIL_ON_ERROR" | |
project: ${{ env.BYTEBASE_PROJECT }} | |
targets: ${{ env.BYTEBASE_TARGETS }} | |
validate-only: false | |
- name: Create plan | |
id: create_plan | |
uses: bytebase/create-plan-from-release-action@v1 | |
with: | |
url: ${{ env.BYTEBASE_URL }} | |
token: ${{ steps.login.outputs.token }} | |
project: ${{ env.BYTEBASE_PROJECT }} | |
release: ${{ steps.create_release.outputs.release }} | |
targets: ${{ env.BYTEBASE_TARGETS }} | |
check-plan: "SKIP" | |
- name: Rollout | |
id: rollout | |
uses: bytebase/rollout-action@v1 | |
if: ${{ steps.create_plan.outputs.deployment-required == 'true' }} | |
with: | |
url: ${{ env.BYTEBASE_URL }} | |
token: ${{ steps.login.outputs.token }} | |
plan: ${{ steps.create_plan.outputs.plan }} | |
target-stage: test # the environment resource id. | |
- 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 | |
environment: prod | |
env: | |
BYTEBASE_URL: https://demo.bytebase.com | |
BYTEBASE_SERVICE_ACCOUNT: [email protected] | |
if: ${{ needs.deploy_to_test.outputs.deployment-required == 'true' }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Login to Bytebase | |
id: login | |
uses: bytebase/login-action@v1 | |
with: | |
bytebase-url: ${{ env.BYTEBASE_URL }} | |
service-key: ${{ env.BYTEBASE_SERVICE_ACCOUNT }} | |
service-secret: ${{secrets.BYTEBASE_SERVICE_ACCOUNT_SECRET}} # Please use secrets for sensitive data in production. | |
- name: Rollout | |
id: rollout | |
uses: bytebase/rollout-action@v1 | |
with: | |
url: ${{ env.BYTEBASE_URL }} | |
token: ${{ steps.login.outputs.token }} | |
plan: ${{ needs.deploy_to_test.outputs.bytebase_plan }} | |
target-stage: prod # the environment resource id. | |
- name: Deploy app | |
run: | | |
echo "Deploying app to prod environment..." | |
echo "Deploy app to prod environment done!" |