From 5f71a7a502e4ef18f26d9c10f753e5fab34de7db Mon Sep 17 00:00:00 2001 From: Eric Cabrel TIOGO Date: Sat, 22 Jun 2024 17:07:36 +0200 Subject: [PATCH] build: global env variable --- .github/workflows/migration-db-check.yml | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/.github/workflows/migration-db-check.yml b/.github/workflows/migration-db-check.yml index 46ce3fd7..fe79b109 100644 --- a/.github/workflows/migration-db-check.yml +++ b/.github/workflows/migration-db-check.yml @@ -6,6 +6,10 @@ on: paths: - 'packages/domain/prisma/migrations/**' +env: + PLANETSCALE_SERVICE_TOKEN_ID: ${{ secrets.PLANETSCALE_SERVICE_TOKEN_ID }} + PLANETSCALE_SERVICE_TOKEN: ${{ secrets.PLANETSCALE_SERVICE_TOKEN }} + jobs: migration-detail: runs-on: ubuntu-latest @@ -19,9 +23,6 @@ jobs: run: echo "PSCALE_BRANCH_NAME=$(echo ${{ github.head_ref }} | tr -cd '[:alnum:]-'| tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV - name: Create deploy request on development branch - env: - PLANETSCALE_SERVICE_TOKEN_ID: ${{ secrets.PLANETSCALE_SERVICE_TOKEN_ID }} - PLANETSCALE_SERVICE_TOKEN: ${{ secrets.PLANETSCALE_SERVICE_TOKEN }} run: | set +e pscale deploy-request show ${{ secrets.PLANETSCALE_DATABASE_NAME }} ${{ env.PSCALE_BRANCH_NAME }} --org ${{ secrets.PLANETSCALE_ORG_NAME }} @@ -29,9 +30,9 @@ jobs: set -e if [ $exit_code -eq 0 ]; then - echo "Deploy request exists. Skipping creation." + echo "Deploy request exists: skipping creation" else - echo "Deploy request does not exist. Creating." + echo "Deploy request does not exist: creating..." pscale deploy-request create ${{ secrets.PLANETSCALE_DATABASE_NAME }} ${{ env.PSCALE_BRANCH_NAME }} \ --org ${{ secrets.PLANETSCALE_ORG_NAME }} \ --into dev \ @@ -39,18 +40,12 @@ jobs: fi - name: Get deploy request number - env: - PLANETSCALE_SERVICE_TOKEN_ID: ${{ secrets.PLANETSCALE_SERVICE_TOKEN_ID }} - PLANETSCALE_SERVICE_TOKEN: ${{ secrets.PLANETSCALE_SERVICE_TOKEN }} run: | 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 "DEPLOY_REQUEST_NUMBER=$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.DEPLOY_REQUEST_NUMBER }} --org ${{ secrets.PLANETSCALE_ORG_NAME }} --format json | jq -r '.deployment_state') @@ -69,9 +64,6 @@ jobs: - name: Collect the migration diff continue-on-error: false if: ${{ env.DEPLOY_REQUEST_OPENED }} - env: - PLANETSCALE_SERVICE_TOKEN_ID: ${{ secrets.PLANETSCALE_SERVICE_TOKEN_ID }} - PLANETSCALE_SERVICE_TOKEN: ${{ secrets.PLANETSCALE_SERVICE_TOKEN }} run: | deploy_data=$(pscale api organizations/${{ secrets.PLANETSCALE_ORG_NAME }}/databases/${{ secrets.PLANETSCALE_DATABASE_NAME }}/deploy-requests/${{ env.DEPLOY_REQUEST_NUMBER }}/deployment --org planetscale) can_drop_data=$(echo "$deploy_data" | jq -r '.deploy_operations[] | select(.can_drop_data == true) | .can_drop_data') @@ -100,7 +92,6 @@ jobs: pscale deploy-request diff ${{ secrets.PLANETSCALE_DATABASE_NAME }} ${{ env.DEPLOY_REQUEST_NUMBER }} --org ${{ secrets.PLANETSCALE_ORG_NAME }} -f json | jq -r '.[].raw' >> migration-message.txt echo "\`\`\`" >> migration-message.txt - - name: Comment pull request with the migration diff uses: thollander/actions-comment-pull-request@v2 if: ${{ env.DEPLOY_REQUEST_OPENED }}