trigger #5
This file contains hidden or 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: Rollout (wi) | |
| on: | |
| push: | |
| branches: ["wi-test"] | |
| paths: ["migrations/*.sql"] | |
| env: | |
| BYTEBASE_URL: https://4932-103-137-247-74.ngrok-free.app | |
| BYTEBASE_WORKLOAD_IDENTITY: wi@db333.workload.bytebase.com | |
| BYTEBASE_PROJECT: projects/db333 | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Build | |
| run: echo "Building..." | |
| create-rollout: | |
| needs: build | |
| permissions: | |
| id-token: write | |
| runs-on: ubuntu-latest | |
| container: | |
| image: bytebase/bytebase-action@sha256:689ac56a16273b5e68ecbdf820fc8ec17dd3ba2ef7b10f5685e04eeda1bcc4c3 | |
| outputs: | |
| bytebase-plan: ${{ steps.set-output.outputs.plan }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Exchange token | |
| id: bytebase-auth | |
| run: | | |
| OIDC_TOKEN=$(curl -s -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \ | |
| "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=bytebase" | jq -r '.value') | |
| ACCESS_TOKEN=$(curl -s -X POST "$BYTEBASE_URL/v1/auth:exchangeToken" \ | |
| -H "Content-Type: application/json" \ | |
| -d "{\"token\":\"$OIDC_TOKEN\",\"email\":\"$BYTEBASE_WORKLOAD_IDENTITY\"}" \ | |
| | jq -r '.accessToken') | |
| echo "access-token=$ACCESS_TOKEN" >> $GITHUB_OUTPUT | |
| - name: Create rollout | |
| run: | | |
| bytebase-action rollout \ | |
| --url=$BYTEBASE_URL \ | |
| --access-token=${{ steps.bytebase-auth.outputs.access-token }} \ | |
| --project=$BYTEBASE_PROJECT \ | |
| --targets=instances/dbdbdb/databases/db_0 \ | |
| --file-pattern=migrations/*.sql \ | |
| --output=${{ runner.temp }}/bytebase-metadata.json | |
| - name: Set output | |
| id: set-output | |
| run: | | |
| PLAN=$(jq -r .plan ${{ runner.temp }}/bytebase-metadata.json) | |
| echo "plan=$PLAN" >> $GITHUB_OUTPUT | |
| deploy-to-test: | |
| needs: create-rollout | |
| permissions: | |
| id-token: write | |
| runs-on: ubuntu-latest | |
| environment: test | |
| container: | |
| image: bytebase/bytebase-action@sha256:689ac56a16273b5e68ecbdf820fc8ec17dd3ba2ef7b10f5685e04eeda1bcc4c3 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Exchange token | |
| id: bytebase-auth | |
| run: | | |
| OIDC_TOKEN=$(curl -s -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \ | |
| "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=bytebase" | jq -r '.value') | |
| ACCESS_TOKEN=$(curl -s -X POST "$BYTEBASE_URL/v1/auth:exchangeToken" \ | |
| -H "Content-Type: application/json" \ | |
| -d "{\"token\":\"$OIDC_TOKEN\",\"email\":\"$BYTEBASE_WORKLOAD_IDENTITY\"}" \ | |
| | jq -r '.accessToken') | |
| echo "access-token=$ACCESS_TOKEN" >> $GITHUB_OUTPUT | |
| - name: Deploy to test | |
| run: | | |
| bytebase-action rollout \ | |
| --url=$BYTEBASE_URL \ | |
| --access-token=${{ steps.bytebase-auth.outputs.access-token }} \ | |
| --project=$BYTEBASE_PROJECT \ | |
| --target-stage=environments/test \ | |
| --plan=${{ needs.create-rollout.outputs.bytebase-plan }} | |
| deploy-to-prod: | |
| needs: [deploy-to-test, create-rollout] | |
| permissions: | |
| id-token: write | |
| runs-on: ubuntu-latest | |
| environment: prod | |
| container: | |
| image: bytebase/bytebase-action@sha256:689ac56a16273b5e68ecbdf820fc8ec17dd3ba2ef7b10f5685e04eeda1bcc4c3 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Exchange token | |
| id: bytebase-auth | |
| run: | | |
| OIDC_TOKEN=$(curl -s -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \ | |
| "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=bytebase" | jq -r '.value') | |
| ACCESS_TOKEN=$(curl -s -X POST "$BYTEBASE_URL/v1/auth:exchangeToken" \ | |
| -H "Content-Type: application/json" \ | |
| -d "{\"token\":\"$OIDC_TOKEN\",\"email\":\"$BYTEBASE_WORKLOAD_IDENTITY\"}" \ | |
| | jq -r '.accessToken') | |
| echo "access-token=$ACCESS_TOKEN" >> $GITHUB_OUTPUT | |
| - name: Deploy to prod | |
| run: | | |
| bytebase-action rollout \ | |
| --url=$BYTEBASE_URL \ | |
| --access-token=${{ steps.bytebase-auth.outputs.access-token }} \ | |
| --project=$BYTEBASE_PROJECT \ | |
| --target-stage=environments/prod \ | |
| --plan=${{ needs.create-rollout.outputs.bytebase-plan }} |