From 00aaaefb95dd6a07e4f3abc04aac12dac59c29f1 Mon Sep 17 00:00:00 2001 From: Jim Daniels Wasswa Date: Wed, 27 Dec 2023 11:17:15 +0800 Subject: [PATCH 1/3] chore: make notify_slack ation generic --- .github/actions/notify_slack/action.yml | 27 ++------- .github/workflows/release_production.yml | 70 ++++++++++++++++++------ .github/workflows/release_staging.yml | 30 +++++++++- 3 files changed, 86 insertions(+), 41 deletions(-) diff --git a/.github/actions/notify_slack/action.yml b/.github/actions/notify_slack/action.yml index a416c5c36..e8e12f0ec 100644 --- a/.github/actions/notify_slack/action.yml +++ b/.github/actions/notify_slack/action.yml @@ -1,37 +1,20 @@ name: notify_slack -description: Send Slack notifications +description: Send Slack notification inputs: SLACK_WEBHOOK_URL: description: Slack webhook URL required: true - STATUS: - description: Job status + MESSAGE: + description: 'Status message' required: true - RELEASE_TYPE: - description: Release type - required: true - VERSION: - description: Version - required: true - default: N/A runs: using: composite steps: - - name: Send Slack Notification on Success - if: ${{ inputs.STATUS == 'success' }} + - name: Send Slack Notification run: |- curl -X POST -H 'Content-type: application/json' \ --data '{ - "text": "'"${{ inputs.RELEASE_TYPE }}"' Release succeeded for api.deriv.com with version *'"${{ inputs.VERSION }}"'*" + "text": "${{ inputs.MESSAGE }}", }' \ ${{ inputs.SLACK_WEBHOOK_URL }} shell: bash - - name: Send Slack Notification on Failure - if: ${{ inputs.STATUS == 'failure' }} - run: |- - curl -X POST -H 'Content-type: application/json' \ - --data '{ - "text": "'"${{ inputs.RELEASE_TYPE }}"' Release failed for api.deriv.com with version *'"${{ inputs.VERSION }}"'*" - }' \ - ${{ inputs.SLACK_WEBHOOK_URL }} - shell: bash diff --git a/.github/workflows/release_production.yml b/.github/workflows/release_production.yml index cbc80af27..f39b683f9 100644 --- a/.github/workflows/release_production.yml +++ b/.github/workflows/release_production.yml @@ -3,6 +3,8 @@ on: push: tags: - production_v* +env: + RELEASE_TYPE: Production jobs: build_and_publish: name: Builds and Publishes to Cloudflare Pages Production @@ -25,7 +27,7 @@ jobs: uses: ./.github/actions/versioning with: RELEASE_TAG: ${{ github.ref_name }} - RELEASE_TYPE: production + RELEASE_TYPE: ${{ env.RELEASE_TYPE }} - name: Extract version id: extract_version run: echo "RELEASE_VERSION=$(cat build/version)" >> $GITHUB_OUTPUT @@ -34,7 +36,52 @@ jobs: with: CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} + - name: Upload Build Artifact + uses: actions/upload-artifact@v4 + with: + name: build + path: . + retention-days: 1 + + send_slack_notification: + name: Send Slack Notification + environment: Production + runs-on: ubuntu-latest # TODO: Replace this with the appropriate runner for Deriv-Api-Docs when provided + if: always() + needs: [build_and_publish] + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Conclusion + uses: technote-space/workflow-conclusion-action@v3 + - name: Create Slack Message + id: create_slack_message + run: | + if [ "${{ env.WORKFLOW_CONCLUSION }}" == "success" ]; then + echo "MESSAGE=${{ env.RELEASE_TYPE }} Release succeeded for api.deriv.com with version *${{ needs.build_and_publish.outputs.RELEASE_VERSION }}*" >> $GITHUB_ENV + elif ["${{ env.WORKFLOW_CONCLUSION }}" == "failure"]; then + echo "MESSAGE=${{ env.RELEASE_TYPE }} Release failed for api.deriv.com with version *${{ needs.build_and_publish.outputs.RELEASE_VERSION }}*" >> $GITHUB_ENV + else + echo "MESSAGE=Unkown outcome" >> $GITHUB_ENV + fi + - name: Send Slack Notification + uses: ./.github/actions/notify_slack + with: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} + MESSAGE: ${{ steps.create_slack_message.outputs.MESSAGE }} + + build_and_publish_to_docker_k8s: + name: Builds and Publishes image to Docker and Kubernetes + runs-on: ubuntu-latest + environment: Production + needs: [build_and_publish] + steps: + - name: Download Build Artifact + uses: actions/download-artifact@v4 + with: + name: build - name: Publish to Docker + id: publish_to_docker uses: ./.github/actions/publish_to_docker with: DOCKER_LATEST_IMAGE_TAG: 'latest' @@ -43,6 +90,7 @@ jobs: DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }} - name: Deploy to Kubernetes + id: deploy_to_kubernetes uses: ./.github/actions/deploy_to_kubernetes with: K8S_VERSION: ${{ github.ref_name }} @@ -51,23 +99,9 @@ jobs: SERVICEACCOUNT_TOKEN: ${{ secrets.SERVICEACCOUNT_TOKEN }} KUBE_SERVER: ${{ secrets.KUBE_SERVER }} DOCKERHUB_ORGANISATION: ${{ secrets.DOCKERHUB_ORGANISATION }} - - send_slack_notification: - name: Send Slack Notification - environment: Production - runs-on: ubuntu-latest # TODO: Replace this with the appropriate runner for Deriv-Api-Docs when provided - if: always() - needs: - - build_and_publish - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Conclusion - uses: technote-space/workflow-conclusion-action@v3 - name: Send Slack Notification + if: ${{ steps.publish_to_docker.outcome != 'success' || steps.deploy_to_kubernetes.outcome != 'success' }} uses: ./.github/actions/notify_slack with: - RELEASE_TYPE: Production - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} - STATUS: ${{ env.WORKFLOW_CONCLUSION }} - version: ${{ needs.build_and_publish.outputs.RELEASE_VERSION}} + RELEASE_TYPE: ${{ env.RELEASE_TYPE }} + MESSAGE: "'${{ env.RELEASE_TYPE }}' Docker Publish and Kubernetes Deployment for api.deriv.com with version *'${{ needs.build_and_publish.outputs.RELEASE_VERSION }}'* has Failed *" \ No newline at end of file diff --git a/.github/workflows/release_staging.yml b/.github/workflows/release_staging.yml index 72cd005e6..9837fab5b 100644 --- a/.github/workflows/release_staging.yml +++ b/.github/workflows/release_staging.yml @@ -3,11 +3,15 @@ on: push: branches: - master +env: + RELEASE_TYPE: Staging jobs: build_and_publish: name: Builds and Publishes to Cloudflare Pages Staging runs-on: ubuntu-latest # TODO: Replace this with the appropriate runner for Deriv-Api-Docs when provided environment: Staging + outputs: + RELEASE_VERSION: ${{ steps.extract_version.outputs.RELEASE_VERSION }} steps: - name: Checkout uses: actions/checkout@v4 @@ -25,13 +29,30 @@ jobs: uses: ./.github/actions/versioning with: RELEASE_TAG: ${{ github.sha }} - RELEASE_TYPE: staging + RELEASE_TYPE: ${{ env.RELEASE_TYPE }} + - name: Extract version + id: extract_version + run: echo "RELEASE_VERSION=${version}" >> $GITHUB_OUTPUT - name: Publish to Cloudflare Pages Staging uses: ./.github/actions/publish_to_pages_staging with: CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} + - name: Upload Build Artifact + uses: actions/upload-artifact@v4 + with: + name: build + path: . + retention-days: 1 + + build_and_publish_to_docker_k8s: + name: Builds and Publishes image to Docker and Kubernetes + runs-on: ubuntu-latest + environment: Staging + needs: [build_and_publish] + steps: - name: Publish to Docker + id: publish_to_docker uses: ./.github/actions/publish_to_docker with: DOCKER_LATEST_IMAGE_TAG: 'latest-staging' @@ -40,6 +61,7 @@ jobs: DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }} - name: Deploy to Kubernetes + id: deploy_to_kubernetes uses: ./.github/actions/deploy_to_kubernetes with: K8S_VERSION: ${{ github.ref_name }} @@ -48,3 +70,9 @@ jobs: SERVICEACCOUNT_TOKEN: ${{ secrets.SERVICEACCOUNT_TOKEN }} KUBE_SERVER: ${{ secrets.KUBE_SERVER }} DOCKERHUB_ORGANISATION: ${{ secrets.DOCKERHUB_ORGANISATION }} + - name: Send Slack Notification + if: ${{ steps.publish_to_docker.outcome != 'success' || steps.deploy_to_kubernetes.outcome != 'success' }} + uses: ./.github/actions/notify_slack + with: + RELEASE_TYPE: ${{ env.RELEASE_TYPE }} + MESSAGE: "'${{ env.RELEASE_TYPE }}' Docker Publish and Kubernetes Deployment for api.deriv.com with version *'${{ needs.build_and_publish.outputs.RELEASE_VERSION }}'* has Failed *" From b85b6263f34df4cd9685d8e628c5a28fc1deb738 Mon Sep 17 00:00:00 2001 From: Jim Daniels Wasswa Date: Wed, 27 Dec 2023 11:29:00 +0800 Subject: [PATCH 2/3] chore: remove unnecessary comment and add a new line at the end of the file --- .github/workflows/release_production.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release_production.yml b/.github/workflows/release_production.yml index f39b683f9..b42a32db8 100644 --- a/.github/workflows/release_production.yml +++ b/.github/workflows/release_production.yml @@ -46,7 +46,7 @@ jobs: send_slack_notification: name: Send Slack Notification environment: Production - runs-on: ubuntu-latest # TODO: Replace this with the appropriate runner for Deriv-Api-Docs when provided + runs-on: ubuntu-latest if: always() needs: [build_and_publish] steps: @@ -104,4 +104,4 @@ jobs: uses: ./.github/actions/notify_slack with: RELEASE_TYPE: ${{ env.RELEASE_TYPE }} - MESSAGE: "'${{ env.RELEASE_TYPE }}' Docker Publish and Kubernetes Deployment for api.deriv.com with version *'${{ needs.build_and_publish.outputs.RELEASE_VERSION }}'* has Failed *" \ No newline at end of file + MESSAGE: "'${{ env.RELEASE_TYPE }}' Docker Publish and Kubernetes Deployment for api.deriv.com with version *'${{ needs.build_and_publish.outputs.RELEASE_VERSION }}'* has Failed *" From 16b9db82e393c13650b24fe3109df5838ae50282 Mon Sep 17 00:00:00 2001 From: Jim Daniels Wasswa Date: Tue, 2 Jan 2024 12:34:39 +0800 Subject: [PATCH 3/3] chore: revert changes to staging workflow --- .github/workflows/release_staging.yml | 30 +-------------------------- 1 file changed, 1 insertion(+), 29 deletions(-) diff --git a/.github/workflows/release_staging.yml b/.github/workflows/release_staging.yml index 9837fab5b..72cd005e6 100644 --- a/.github/workflows/release_staging.yml +++ b/.github/workflows/release_staging.yml @@ -3,15 +3,11 @@ on: push: branches: - master -env: - RELEASE_TYPE: Staging jobs: build_and_publish: name: Builds and Publishes to Cloudflare Pages Staging runs-on: ubuntu-latest # TODO: Replace this with the appropriate runner for Deriv-Api-Docs when provided environment: Staging - outputs: - RELEASE_VERSION: ${{ steps.extract_version.outputs.RELEASE_VERSION }} steps: - name: Checkout uses: actions/checkout@v4 @@ -29,30 +25,13 @@ jobs: uses: ./.github/actions/versioning with: RELEASE_TAG: ${{ github.sha }} - RELEASE_TYPE: ${{ env.RELEASE_TYPE }} - - name: Extract version - id: extract_version - run: echo "RELEASE_VERSION=${version}" >> $GITHUB_OUTPUT + RELEASE_TYPE: staging - name: Publish to Cloudflare Pages Staging uses: ./.github/actions/publish_to_pages_staging with: CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} - - name: Upload Build Artifact - uses: actions/upload-artifact@v4 - with: - name: build - path: . - retention-days: 1 - - build_and_publish_to_docker_k8s: - name: Builds and Publishes image to Docker and Kubernetes - runs-on: ubuntu-latest - environment: Staging - needs: [build_and_publish] - steps: - name: Publish to Docker - id: publish_to_docker uses: ./.github/actions/publish_to_docker with: DOCKER_LATEST_IMAGE_TAG: 'latest-staging' @@ -61,7 +40,6 @@ jobs: DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }} - name: Deploy to Kubernetes - id: deploy_to_kubernetes uses: ./.github/actions/deploy_to_kubernetes with: K8S_VERSION: ${{ github.ref_name }} @@ -70,9 +48,3 @@ jobs: SERVICEACCOUNT_TOKEN: ${{ secrets.SERVICEACCOUNT_TOKEN }} KUBE_SERVER: ${{ secrets.KUBE_SERVER }} DOCKERHUB_ORGANISATION: ${{ secrets.DOCKERHUB_ORGANISATION }} - - name: Send Slack Notification - if: ${{ steps.publish_to_docker.outcome != 'success' || steps.deploy_to_kubernetes.outcome != 'success' }} - uses: ./.github/actions/notify_slack - with: - RELEASE_TYPE: ${{ env.RELEASE_TYPE }} - MESSAGE: "'${{ env.RELEASE_TYPE }}' Docker Publish and Kubernetes Deployment for api.deriv.com with version *'${{ needs.build_and_publish.outputs.RELEASE_VERSION }}'* has Failed *"