From fc0c0b88ede8d4ca4b7f4c8683faa6c1435aecc0 Mon Sep 17 00:00:00 2001 From: Simon Kelly Date: Thu, 17 Oct 2024 15:25:01 +0200 Subject: [PATCH 1/3] only deploy after tests are complete --- .github/workflows/deploy.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 472f11a7f..c9f54653a 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -23,8 +23,10 @@ on: options: - dev - prod - push: - branches: [ "main" ] + workflow_run: + workflows: [ Run Django Tests, Build Front End ] + types: + - completed permissions: id-token: write From 2dcb9a5aa9f2b3e592278a69c7d6484c498b8893 Mon Sep 17 00:00:00 2001 From: Simon Kelly Date: Thu, 17 Oct 2024 15:35:27 +0200 Subject: [PATCH 2/3] create and update deployments --- .github/workflows/deploy.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index c9f54653a..163e52a34 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -31,6 +31,7 @@ on: permissions: id-token: write contents: read + deployments: write jobs: deploy: @@ -66,6 +67,15 @@ jobs: echo "ECS_SERVICE_CELERY=$APP_NAME-${{ env.DEPLOY_ENV }}-Celery" >> "$GITHUB_ENV" echo "ECS_SERVICE_CELERY_BEAT=$APP_NAME-${{ env.DEPLOY_ENV }}-CeleryBeat" >> "$GITHUB_ENV" + - name: Create GitHub deployment + uses: chrnorm/deployment-action@v2 + id: deployment + with: + token: '${{ github.token }}' + environment: "aws-${{ env.DEPLOY_ENV }}" + production-environment: ${{ env.DEPLOY_ENV == 'prod' }} + + - name: configure aws credentials uses: aws-actions/configure-aws-credentials@v4.0.2 with: @@ -159,3 +169,12 @@ jobs: - name: Wait for service stability run: | aws ecs wait services-stable --cluster $ECS_CLUSTER --services $ECS_SERVICE_DJANGO $ECS_SERVICE_CELERY $ECS_SERVICE_CELERY_BEAT + + - name: Update deployment status + if: success() + uses: chrnorm/deployment-status@v2 + with: + token: '${{ github.token }}' + environment-url: ${{ steps.deployment.outputs.environment_url }} + deployment-id: ${{ steps.deployment.outputs.deployment_id }} + state: "${{ success() && 'success' || 'failure' }}" From 01a29d15614f6aa93d96bab74a1607cef2b43312 Mon Sep 17 00:00:00 2001 From: Simon Kelly Date: Thu, 17 Oct 2024 15:39:47 +0200 Subject: [PATCH 3/3] separate steps for success and failure --- .github/workflows/deploy.yml | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 163e52a34..6c3587ddc 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -170,11 +170,20 @@ jobs: run: | aws ecs wait services-stable --cluster $ECS_CLUSTER --services $ECS_SERVICE_DJANGO $ECS_SERVICE_CELERY $ECS_SERVICE_CELERY_BEAT - - name: Update deployment status + - name: Update deployment status (success) if: success() uses: chrnorm/deployment-status@v2 with: token: '${{ github.token }}' environment-url: ${{ steps.deployment.outputs.environment_url }} deployment-id: ${{ steps.deployment.outputs.deployment_id }} - state: "${{ success() && 'success' || 'failure' }}" + state: 'success' + + - name: Update deployment status (failure) + if: failure() + uses: chrnorm/deployment-status@v2 + with: + token: '${{ github.token }}' + environment-url: ${{ steps.deployment.outputs.environment_url }} + deployment-id: ${{ steps.deployment.outputs.deployment_id }} + state: 'failure'