|
| 1 | +name: Build and push release 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 |
| 23 | + environment: test |
| 24 | + env: |
| 25 | + BYTEBASE_URL: https://demo.bytebase.com |
| 26 | + BYTEBASE_SERVICE_ACCOUNT: [email protected] |
| 27 | + BYTEBASE_PROJECT: "projects/project-sample" |
| 28 | + # The Bytebase rollout pipeline will deploy to 'test' and 'prod' environments. |
| 29 | + # 'deploy_to_test' job rollouts the 'test' stage and 'deploy_to_prod' job rollouts the 'prod' stage. |
| 30 | + BYTEBASE_TARGETS: "instances/test-sample-instance/databases/hr_test,instances/prod-sample-instance/databases/hr_prod" |
| 31 | + FILE_PATTERN: "migrations/*.sql" |
| 32 | + outputs: |
| 33 | + bytebase_plan: ${{ steps.create_plan.outputs.plan }} |
| 34 | + deployment_required: ${{ steps.create_plan.outputs.deployment-required }} |
| 35 | + steps: |
| 36 | + - name: Checkout |
| 37 | + uses: actions/checkout@v4 |
| 38 | + - name: Login to Bytebase |
| 39 | + id: login |
| 40 | + uses: bytebase/login-action@v1 |
| 41 | + with: |
| 42 | + bytebase-url: ${{ env.BYTEBASE_URL }} |
| 43 | + service-key: ${{ env.BYTEBASE_SERVICE_ACCOUNT }} |
| 44 | + service-secret: ${{secrets.BYTEBASE_SERVICE_ACCOUNT_SECRET}} # Please use secrets for sensitive data in production. |
| 45 | + - name: Create release |
| 46 | + id: create_release |
| 47 | + uses: bytebase/create-release-action@v1 |
| 48 | + with: |
| 49 | + url: ${{ env.BYTEBASE_URL }} |
| 50 | + token: ${{ steps.login.outputs.token }} |
| 51 | + file-pattern: ${{ env.FILE_PATTERN }} |
| 52 | + # fail the action if release checks report any error. |
| 53 | + check-release: "FAIL_ON_ERROR" |
| 54 | + project: ${{ env.BYTEBASE_PROJECT }} |
| 55 | + targets: ${{ env.BYTEBASE_TARGETS }} |
| 56 | + validate-only: false |
| 57 | + - name: Create plan |
| 58 | + id: create_plan |
| 59 | + uses: bytebase/create-plan-from-release-action@v1 |
| 60 | + with: |
| 61 | + url: ${{ env.BYTEBASE_URL }} |
| 62 | + token: ${{ steps.login.outputs.token }} |
| 63 | + project: ${{ env.BYTEBASE_PROJECT }} |
| 64 | + release: ${{ steps.create_release.outputs.release }} |
| 65 | + targets: ${{ env.BYTEBASE_TARGETS }} |
| 66 | + check-plan: "SKIP" |
| 67 | + - name: Rollout |
| 68 | + id: rollout |
| 69 | + uses: bytebase/rollout-action@v1 |
| 70 | + if: ${{ steps.create_plan.outputs.deployment_required == 'true' }} |
| 71 | + with: |
| 72 | + url: ${{ env.BYTEBASE_URL }} |
| 73 | + token: ${{ steps.login.outputs.token }} |
| 74 | + plan: ${{ steps.create_plan.outputs.plan }} |
| 75 | + target-stage: 'Test Stage' |
| 76 | + - name: Deploy app |
| 77 | + run: | |
| 78 | + echo "Deploying app to test environment..." |
| 79 | + echo "Deploy app to test environment done!" |
| 80 | + deploy_to_prod: |
| 81 | + needs: deploy_to_test |
| 82 | + runs-on: ubuntu-latest |
| 83 | + environment: prod |
| 84 | + env: |
| 85 | + BYTEBASE_URL: https://demo.bytebase.com |
| 86 | + BYTEBASE_SERVICE_ACCOUNT: [email protected] |
| 87 | + if: ${{ needs.deploy_to_test.outputs.deployment_required == 'true' }} |
| 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: Rollout |
| 99 | + id: rollout |
| 100 | + uses: bytebase/rollout-action@v1 |
| 101 | + with: |
| 102 | + url: ${{ env.BYTEBASE_URL }} |
| 103 | + token: ${{ steps.login.outputs.token }} |
| 104 | + plan: ${{ needs.deploy_to_test.outputs.bytebase_plan }} |
| 105 | + target-stage: 'Prod Stage' |
| 106 | + - name: Deploy app |
| 107 | + run: | |
| 108 | + echo "Deploying app to prod environment..." |
| 109 | + echo "Deploy app to prod environment done!" |
0 commit comments