Skip to content
This repository was archived by the owner on May 13, 2024. It is now read-only.

Commit 00aaaef

Browse files
committed
chore: make notify_slack ation generic
1 parent 96a8512 commit 00aaaef

File tree

3 files changed

+86
-41
lines changed

3 files changed

+86
-41
lines changed
Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,20 @@
11
name: notify_slack
2-
description: Send Slack notifications
2+
description: Send Slack notification
33
inputs:
44
SLACK_WEBHOOK_URL:
55
description: Slack webhook URL
66
required: true
7-
STATUS:
8-
description: Job status
7+
MESSAGE:
8+
description: 'Status message'
99
required: true
10-
RELEASE_TYPE:
11-
description: Release type
12-
required: true
13-
VERSION:
14-
description: Version
15-
required: true
16-
default: N/A
1710
runs:
1811
using: composite
1912
steps:
20-
- name: Send Slack Notification on Success
21-
if: ${{ inputs.STATUS == 'success' }}
13+
- name: Send Slack Notification
2214
run: |-
2315
curl -X POST -H 'Content-type: application/json' \
2416
--data '{
25-
"text": "'"${{ inputs.RELEASE_TYPE }}"' Release succeeded for api.deriv.com with version *'"${{ inputs.VERSION }}"'*"
17+
"text": "${{ inputs.MESSAGE }}",
2618
}' \
2719
${{ inputs.SLACK_WEBHOOK_URL }}
2820
shell: bash
29-
- name: Send Slack Notification on Failure
30-
if: ${{ inputs.STATUS == 'failure' }}
31-
run: |-
32-
curl -X POST -H 'Content-type: application/json' \
33-
--data '{
34-
"text": "'"${{ inputs.RELEASE_TYPE }}"' Release failed for api.deriv.com with version *'"${{ inputs.VERSION }}"'*"
35-
}' \
36-
${{ inputs.SLACK_WEBHOOK_URL }}
37-
shell: bash

.github/workflows/release_production.yml

Lines changed: 52 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ on:
33
push:
44
tags:
55
- production_v*
6+
env:
7+
RELEASE_TYPE: Production
68
jobs:
79
build_and_publish:
810
name: Builds and Publishes to Cloudflare Pages Production
@@ -25,7 +27,7 @@ jobs:
2527
uses: ./.github/actions/versioning
2628
with:
2729
RELEASE_TAG: ${{ github.ref_name }}
28-
RELEASE_TYPE: production
30+
RELEASE_TYPE: ${{ env.RELEASE_TYPE }}
2931
- name: Extract version
3032
id: extract_version
3133
run: echo "RELEASE_VERSION=$(cat build/version)" >> $GITHUB_OUTPUT
@@ -34,7 +36,52 @@ jobs:
3436
with:
3537
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
3638
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
39+
- name: Upload Build Artifact
40+
uses: actions/upload-artifact@v4
41+
with:
42+
name: build
43+
path: .
44+
retention-days: 1
45+
46+
send_slack_notification:
47+
name: Send Slack Notification
48+
environment: Production
49+
runs-on: ubuntu-latest # TODO: Replace this with the appropriate runner for Deriv-Api-Docs when provided
50+
if: always()
51+
needs: [build_and_publish]
52+
steps:
53+
- name: Checkout
54+
uses: actions/checkout@v4
55+
- name: Conclusion
56+
uses: technote-space/workflow-conclusion-action@v3
57+
- name: Create Slack Message
58+
id: create_slack_message
59+
run: |
60+
if [ "${{ env.WORKFLOW_CONCLUSION }}" == "success" ]; then
61+
echo "MESSAGE=${{ env.RELEASE_TYPE }} Release succeeded for api.deriv.com with version *${{ needs.build_and_publish.outputs.RELEASE_VERSION }}*" >> $GITHUB_ENV
62+
elif ["${{ env.WORKFLOW_CONCLUSION }}" == "failure"]; then
63+
echo "MESSAGE=${{ env.RELEASE_TYPE }} Release failed for api.deriv.com with version *${{ needs.build_and_publish.outputs.RELEASE_VERSION }}*" >> $GITHUB_ENV
64+
else
65+
echo "MESSAGE=Unkown outcome" >> $GITHUB_ENV
66+
fi
67+
- name: Send Slack Notification
68+
uses: ./.github/actions/notify_slack
69+
with:
70+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
71+
MESSAGE: ${{ steps.create_slack_message.outputs.MESSAGE }}
72+
73+
build_and_publish_to_docker_k8s:
74+
name: Builds and Publishes image to Docker and Kubernetes
75+
runs-on: ubuntu-latest
76+
environment: Production
77+
needs: [build_and_publish]
78+
steps:
79+
- name: Download Build Artifact
80+
uses: actions/download-artifact@v4
81+
with:
82+
name: build
3783
- name: Publish to Docker
84+
id: publish_to_docker
3885
uses: ./.github/actions/publish_to_docker
3986
with:
4087
DOCKER_LATEST_IMAGE_TAG: 'latest'
@@ -43,6 +90,7 @@ jobs:
4390
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
4491
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
4592
- name: Deploy to Kubernetes
93+
id: deploy_to_kubernetes
4694
uses: ./.github/actions/deploy_to_kubernetes
4795
with:
4896
K8S_VERSION: ${{ github.ref_name }}
@@ -51,23 +99,9 @@ jobs:
5199
SERVICEACCOUNT_TOKEN: ${{ secrets.SERVICEACCOUNT_TOKEN }}
52100
KUBE_SERVER: ${{ secrets.KUBE_SERVER }}
53101
DOCKERHUB_ORGANISATION: ${{ secrets.DOCKERHUB_ORGANISATION }}
54-
55-
send_slack_notification:
56-
name: Send Slack Notification
57-
environment: Production
58-
runs-on: ubuntu-latest # TODO: Replace this with the appropriate runner for Deriv-Api-Docs when provided
59-
if: always()
60-
needs:
61-
- build_and_publish
62-
steps:
63-
- name: Checkout
64-
uses: actions/checkout@v4
65-
- name: Conclusion
66-
uses: technote-space/workflow-conclusion-action@v3
67102
- name: Send Slack Notification
103+
if: ${{ steps.publish_to_docker.outcome != 'success' || steps.deploy_to_kubernetes.outcome != 'success' }}
68104
uses: ./.github/actions/notify_slack
69105
with:
70-
RELEASE_TYPE: Production
71-
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
72-
STATUS: ${{ env.WORKFLOW_CONCLUSION }}
73-
version: ${{ needs.build_and_publish.outputs.RELEASE_VERSION}}
106+
RELEASE_TYPE: ${{ env.RELEASE_TYPE }}
107+
MESSAGE: "'${{ env.RELEASE_TYPE }}' Docker Publish and Kubernetes Deployment for api.deriv.com with version *'${{ needs.build_and_publish.outputs.RELEASE_VERSION }}'* has Failed *"

.github/workflows/release_staging.yml

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@ on:
33
push:
44
branches:
55
- master
6+
env:
7+
RELEASE_TYPE: Staging
68
jobs:
79
build_and_publish:
810
name: Builds and Publishes to Cloudflare Pages Staging
911
runs-on: ubuntu-latest # TODO: Replace this with the appropriate runner for Deriv-Api-Docs when provided
1012
environment: Staging
13+
outputs:
14+
RELEASE_VERSION: ${{ steps.extract_version.outputs.RELEASE_VERSION }}
1115
steps:
1216
- name: Checkout
1317
uses: actions/checkout@v4
@@ -25,13 +29,30 @@ jobs:
2529
uses: ./.github/actions/versioning
2630
with:
2731
RELEASE_TAG: ${{ github.sha }}
28-
RELEASE_TYPE: staging
32+
RELEASE_TYPE: ${{ env.RELEASE_TYPE }}
33+
- name: Extract version
34+
id: extract_version
35+
run: echo "RELEASE_VERSION=${version}" >> $GITHUB_OUTPUT
2936
- name: Publish to Cloudflare Pages Staging
3037
uses: ./.github/actions/publish_to_pages_staging
3138
with:
3239
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
3340
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
41+
- name: Upload Build Artifact
42+
uses: actions/upload-artifact@v4
43+
with:
44+
name: build
45+
path: .
46+
retention-days: 1
47+
48+
build_and_publish_to_docker_k8s:
49+
name: Builds and Publishes image to Docker and Kubernetes
50+
runs-on: ubuntu-latest
51+
environment: Staging
52+
needs: [build_and_publish]
53+
steps:
3454
- name: Publish to Docker
55+
id: publish_to_docker
3556
uses: ./.github/actions/publish_to_docker
3657
with:
3758
DOCKER_LATEST_IMAGE_TAG: 'latest-staging'
@@ -40,6 +61,7 @@ jobs:
4061
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
4162
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
4263
- name: Deploy to Kubernetes
64+
id: deploy_to_kubernetes
4365
uses: ./.github/actions/deploy_to_kubernetes
4466
with:
4567
K8S_VERSION: ${{ github.ref_name }}
@@ -48,3 +70,9 @@ jobs:
4870
SERVICEACCOUNT_TOKEN: ${{ secrets.SERVICEACCOUNT_TOKEN }}
4971
KUBE_SERVER: ${{ secrets.KUBE_SERVER }}
5072
DOCKERHUB_ORGANISATION: ${{ secrets.DOCKERHUB_ORGANISATION }}
73+
- name: Send Slack Notification
74+
if: ${{ steps.publish_to_docker.outcome != 'success' || steps.deploy_to_kubernetes.outcome != 'success' }}
75+
uses: ./.github/actions/notify_slack
76+
with:
77+
RELEASE_TYPE: ${{ env.RELEASE_TYPE }}
78+
MESSAGE: "'${{ env.RELEASE_TYPE }}' Docker Publish and Kubernetes Deployment for api.deriv.com with version *'${{ needs.build_and_publish.outputs.RELEASE_VERSION }}'* has Failed *"

0 commit comments

Comments
 (0)