From 03dcaf861505215fdafaba4d9907465ad635cd26 Mon Sep 17 00:00:00 2001 From: Eric Cabrel TIOGO Date: Sat, 22 Jun 2024 23:19:16 +0200 Subject: [PATCH] build: apply migration in prod --- .github/workflows/migration-db-deploy.yml | 72 ++++++++++++----------- 1 file changed, 38 insertions(+), 34 deletions(-) diff --git a/.github/workflows/migration-db-deploy.yml b/.github/workflows/migration-db-deploy.yml index b3e6cf77..f8643f54 100644 --- a/.github/workflows/migration-db-deploy.yml +++ b/.github/workflows/migration-db-deploy.yml @@ -23,41 +23,44 @@ jobs: - name: Set database branch name run: echo "PSCALE_BRANCH_NAME=$(echo ${{ github.head_ref }} | tr -cd '[:alnum:]-'| tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV - - name: Get the deploy request number in development branch - env: - PLANETSCALE_SERVICE_TOKEN_ID: ${{ secrets.PLANETSCALE_SERVICE_TOKEN_ID }} - PLANETSCALE_SERVICE_TOKEN: ${{ secrets.PLANETSCALE_SERVICE_TOKEN }} - run: | - DEV_DEPLOY_REQUEST_NUMBER=$(pscale deploy-request show ${{ secrets.PLANETSCALE_DATABASE_NAME }} ${{ env.PSCALE_BRANCH_NAME }} --org ${{ secrets.PLANETSCALE_ORG_NAME }} -f json | jq -r '.number') - echo "DEV_DEPLOY_REQUEST_NUMBER=$DEV_DEPLOY_REQUEST_NUMBER" >> $GITHUB_ENV - - - name: Check deployment state - continue-on-error: false - env: - PLANETSCALE_SERVICE_TOKEN_ID: ${{ secrets.PLANETSCALE_SERVICE_TOKEN_ID }} - PLANETSCALE_SERVICE_TOKEN: ${{ secrets.PLANETSCALE_SERVICE_TOKEN }} - run: | - for i in {1..10}; do - DEPLOYMENT_STATE=$(pscale deploy-request show ${{ secrets.PLANETSCALE_DATABASE_NAME }} ${{ env.DEV_DEPLOY_REQUEST_NUMBER }} --org ${{ secrets.PLANETSCALE_ORG_NAME }} -f json | jq -r '.deployment_state') - echo "Deployment State: $DEPLOYMENT_STATE" - - if [ "$DEPLOYMENT_STATE" = "ready" ]; then - echo "Deployment state is ready. Continuing." - echo "DEPLOY_REQUEST_OPENED=true" >> $GITHUB_ENV - break - fi +# - name: Get the deploy request number in development branch +# env: +# PLANETSCALE_SERVICE_TOKEN_ID: ${{ secrets.PLANETSCALE_SERVICE_TOKEN_ID }} +# PLANETSCALE_SERVICE_TOKEN: ${{ secrets.PLANETSCALE_SERVICE_TOKEN }} +# run: | +# DEV_DEPLOY_REQUEST_NUMBER=$(pscale deploy-request show ${{ secrets.PLANETSCALE_DATABASE_NAME }} ${{ env.PSCALE_BRANCH_NAME }} --org ${{ secrets.PLANETSCALE_ORG_NAME }} -f json | jq -r '.number') +# echo "DEV_DEPLOY_REQUEST_NUMBER=$DEV_DEPLOY_REQUEST_NUMBER" >> $GITHUB_ENV +# +# +# - name: Check deployment state +# continue-on-error: false +# env: +# PLANETSCALE_SERVICE_TOKEN_ID: ${{ secrets.PLANETSCALE_SERVICE_TOKEN_ID }} +# PLANETSCALE_SERVICE_TOKEN: ${{ secrets.PLANETSCALE_SERVICE_TOKEN }} +# run: | +# for i in {1..10}; do +# DEPLOYMENT_STATE=$(pscale deploy-request show ${{ secrets.PLANETSCALE_DATABASE_NAME }} ${{ env.DEV_DEPLOY_REQUEST_NUMBER }} --org ${{ secrets.PLANETSCALE_ORG_NAME }} -f json | jq -r '.deployment_state') +# echo "Deployment State: $DEPLOYMENT_STATE" +# +# if [ "$DEPLOYMENT_STATE" = "ready" ]; then +# echo "Deployment state is ready. Continuing." +# echo "DEPLOY_REQUEST_OPENED=true" >> $GITHUB_ENV +# break +# fi +# +# echo "Deployment state is not ready. Waiting 2 seconds before checking again." +# sleep 2 +# done +# +# +# - name: Deploy schema migration in the development branch +# continue-on-error: false +# env: +# PLANETSCALE_SERVICE_TOKEN_ID: ${{ secrets.PLANETSCALE_SERVICE_TOKEN_ID }} +# PLANETSCALE_SERVICE_TOKEN: ${{ secrets.PLANETSCALE_SERVICE_TOKEN }} +# run: | +# pscale deploy-request deploy ${{ secrets.PLANETSCALE_DATABASE_NAME }} ${{ env.DEV_DEPLOY_REQUEST_NUMBER }} --org ${{ secrets.PLANETSCALE_ORG_NAME }} --wait - echo "Deployment state is not ready. Waiting 2 seconds before checking again." - sleep 2 - done - - - name: Deploy schema migration in the development branch - continue-on-error: false - env: - PLANETSCALE_SERVICE_TOKEN_ID: ${{ secrets.PLANETSCALE_SERVICE_TOKEN_ID }} - PLANETSCALE_SERVICE_TOKEN: ${{ secrets.PLANETSCALE_SERVICE_TOKEN }} - run: | - pscale deploy-request deploy ${{ secrets.PLANETSCALE_DATABASE_NAME }} ${{ env.DEV_DEPLOY_REQUEST_NUMBER }} --org ${{ secrets.PLANETSCALE_ORG_NAME }} --wait - name: Deploy schema migration in the production branch if: ${{ success() }} @@ -67,6 +70,7 @@ jobs: PLANETSCALE_SERVICE_TOKEN: ${{ secrets.PLANETSCALE_SERVICE_TOKEN }} run: | pscale deploy-request create ${{ secrets.PLANETSCALE_DATABASE_NAME }} ${{ env.PSCALE_BRANCH_NAME }} \ + --org ${{ secrets.PLANETSCALE_ORG_NAME }} \ --into main \ --notes "Apply changes to the production branch"