From 340e3abc8d1f8a89a265164c63d31d57986f3d33 Mon Sep 17 00:00:00 2001 From: "Ali(Ako) Hosseini" Date: Mon, 16 Oct 2023 15:07:44 +0800 Subject: [PATCH 01/12] ci: add publish to cf pages actions --- .../publish_to_pages_production/action.yml | 21 +++++++++++++++++++ .../publish_to_pages_staging/action.yml | 21 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 .github/actions/publish_to_pages_production/action.yml create mode 100644 .github/actions/publish_to_pages_staging/action.yml diff --git a/.github/actions/publish_to_pages_production/action.yml b/.github/actions/publish_to_pages_production/action.yml new file mode 100644 index 0000000000..5a58701145 --- /dev/null +++ b/.github/actions/publish_to_pages_production/action.yml @@ -0,0 +1,21 @@ +name: publish_to_pages_production +description: Publish to cloudflare pages (production) +inputs: + CLOUDFLARE_ACCOUNT_ID: + description: 'Cloudflare account id' + required: true + CLOUDFLARE_API_TOKEN: + description: 'Cloudflare token' + required: true +runs: + using: composite + steps: + - name: Publish to cloudflare pages (production) + env: + CLOUDFLARE_ACCOUNT_ID: ${{ inputs.CLOUDFLARE_ACCOUNT_ID }} + CLOUDFLARE_API_TOKEN: ${{ inputs.CLOUDFLARE_API_TOKEN }} + run: | + npm i wrangler@3.1.0 + npx wrangler pages deploy dist/ --project-name=deriv-smarttrader --branch=main + echo "New website - http://dsmarttrader.deriv.com" + shell: bash diff --git a/.github/actions/publish_to_pages_staging/action.yml b/.github/actions/publish_to_pages_staging/action.yml new file mode 100644 index 0000000000..cd8cd66fc3 --- /dev/null +++ b/.github/actions/publish_to_pages_staging/action.yml @@ -0,0 +1,21 @@ +name: publish_to_pages_staging +description: Publish to cloudflare pages (staging) +inputs: + CLOUDFLARE_ACCOUNT_ID: + description: 'Cloudflare account id' + required: true + CLOUDFLARE_API_TOKEN: + description: 'Cloudflare token' + required: true +runs: + using: composite + steps: + - name: Publish to cloudflare pages (staging) + env: + CLOUDFLARE_ACCOUNT_ID: ${{ inputs.CLOUDFLARE_ACCOUNT_ID }} + CLOUDFLARE_API_TOKEN: ${{ inputs.CLOUDFLARE_API_TOKEN }} + run: | + npm i wrangler@3.1.0 + npx wrangler pages deploy dist/ --project-name=deriv-smarttrader --branch=staging + echo "New staging website - http://staging-dsmarttrader.deriv.com" + shell: bash From 48846b498f3fca6931f3f3a27107acfb260775e6 Mon Sep 17 00:00:00 2001 From: "Ali(Ako) Hosseini" Date: Mon, 16 Oct 2023 15:08:09 +0800 Subject: [PATCH 02/12] ci: add slack notification action --- .../send_slack_notifications/action.yml | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 .github/actions/send_slack_notifications/action.yml diff --git a/.github/actions/send_slack_notifications/action.yml b/.github/actions/send_slack_notifications/action.yml new file mode 100644 index 0000000000..d37c1031c2 --- /dev/null +++ b/.github/actions/send_slack_notifications/action.yml @@ -0,0 +1,39 @@ +name: send_slack_notifications +description: Send Slack notifications +inputs: + SLACK_WEBHOOK_URL: + description: 'Slack webhook URL' + required: true + status: + description: 'Job status' + 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' + run: | + curl -X POST -H 'Content-type: application/json' \ + --data '{ + "text": "${{ inputs.RELEASE_TYPE }} Release succeeded for dsmarttrader.deriv.com with version ${{ inputs.VERSION }}" + }' \ + ${{ 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 dsmarttrader.deriv.com with version ${{ inputs.VERSION }}" + }' \ + ${{ inputs.SLACK_WEBHOOK_URL }} + shell: bash From 69a17fd854f4caa33872dcb3f2b9fc2141f8d83a Mon Sep 17 00:00:00 2001 From: "Ali(Ako) Hosseini" Date: Mon, 16 Oct 2023 15:08:21 +0800 Subject: [PATCH 03/12] ci: add staging workflow --- .github/workflows/release-staging.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .github/workflows/release-staging.yml diff --git a/.github/workflows/release-staging.yml b/.github/workflows/release-staging.yml new file mode 100644 index 0000000000..73a210956c --- /dev/null +++ b/.github/workflows/release-staging.yml @@ -0,0 +1,27 @@ +name: SmartTrader Test Workflow + +on: + push: + branches: + - master + +jobs: + build_and_test: + name: Build and Test + runs-on: ubuntu-latest + steps: + # checkout the repository content to github runner + - name: Checkout + uses: actions/checkout@v4 + # setup nodejs environment + - name: Setup Node.js environment + uses: ./.github/actions/setup_node + # cache the dependencies to speed up the build and then install dependencies + - name: Cache dependencies + uses: ./.github/actions/npm_install_from_cache + # build the react app + - name: Build + run: npm run build + # run tests + - name: Publish to Cloudflare Staging + uses: ./.github/actions/publish_to_cloudflare_staging From 0fc6255c2baa3ef1be803622980b3a4543a2bcdb Mon Sep 17 00:00:00 2001 From: "Ali(Ako) Hosseini" Date: Mon, 16 Oct 2023 15:12:45 +0800 Subject: [PATCH 04/12] ci: add production workflow --- .github/workflows/release-production.yml | 44 ++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 .github/workflows/release-production.yml diff --git a/.github/workflows/release-production.yml b/.github/workflows/release-production.yml new file mode 100644 index 0000000000..c0c826fe47 --- /dev/null +++ b/.github/workflows/release-production.yml @@ -0,0 +1,44 @@ +name: DSmartTrader Production Workflow +on: + push: + tags: + - production_* +jobs: + build_test_and_publish: + name: Build and Test + runs-on: ubuntu-latest + steps: + # checkout the repository content to github runner + - name: Checkout + uses: actions/checkout@v4 + # setup nodejs environment + - name: Setup Node.js environment + uses: ./.github/actions/setup_node + # cache the dependencies to speed up the build and then install dependencies + - name: Cache dependencies + uses: ./.github/actions/npm_install_from_cache + # build the react app + - name: Build + run: npm run build + # run tests + - name: Publish to Cloudflare Staging + uses: ./.github/actions/publish_to_cloudflare_production + + send_slack_notification: + name: Send Slack notification + runs-on: Runner_16cores_Deriv-app + environment: Production + if: always() + needs: [build_test_and_publish] + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Conclusion + uses: technote-space/workflow-conclusion-action@v3 + - name: Send Slack Notification + uses: "./.github/actions/send_slack_notifications" + with: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} + status: ${{ env.WORKFLOW_CONCLUSION }} + release_type: Production + version: $GITHUB_REF_NAME From 80c0fb490fe9d29bd871eb70680a3e62a28434e4 Mon Sep 17 00:00:00 2001 From: "Ali(Ako) Hosseini" Date: Mon, 16 Oct 2023 15:15:47 +0800 Subject: [PATCH 05/12] ci: update workflow name --- .github/workflows/release-production.yml | 2 +- .github/workflows/release-staging.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release-production.yml b/.github/workflows/release-production.yml index c0c826fe47..93002b7d83 100644 --- a/.github/workflows/release-production.yml +++ b/.github/workflows/release-production.yml @@ -1,4 +1,4 @@ -name: DSmartTrader Production Workflow +name: SmartTrader Production Workflow on: push: tags: diff --git a/.github/workflows/release-staging.yml b/.github/workflows/release-staging.yml index 73a210956c..b63aef010a 100644 --- a/.github/workflows/release-staging.yml +++ b/.github/workflows/release-staging.yml @@ -1,4 +1,4 @@ -name: SmartTrader Test Workflow +name: SmartTrader Staging Workflow on: push: From 8edb5ebb2aec3f6c7a71b333d67534bebe20bfea Mon Sep 17 00:00:00 2001 From: "Ali(Ako) Hosseini" Date: Mon, 16 Oct 2023 15:22:23 +0800 Subject: [PATCH 06/12] chore: rerun the ci From 7e124e6a4775a41a42cfdb81ecdcabfff60191d5 Mon Sep 17 00:00:00 2001 From: "Ali(Ako) Hosseini" Date: Mon, 16 Oct 2023 15:24:38 +0800 Subject: [PATCH 07/12] chore: rerun the workflow --- .github/workflows/release-staging.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/release-staging.yml b/.github/workflows/release-staging.yml index b63aef010a..d4844685c0 100644 --- a/.github/workflows/release-staging.yml +++ b/.github/workflows/release-staging.yml @@ -4,7 +4,6 @@ on: push: branches: - master - jobs: build_and_test: name: Build and Test From dfd503a5c49d146ec4e28587941a0152e3029644 Mon Sep 17 00:00:00 2001 From: "Ali(Ako) Hosseini" Date: Mon, 16 Oct 2023 17:00:15 +0800 Subject: [PATCH 08/12] ci: handle the npm cache --- .github/workflows/release-staging.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release-staging.yml b/.github/workflows/release-staging.yml index d4844685c0..f0728ef74e 100644 --- a/.github/workflows/release-staging.yml +++ b/.github/workflows/release-staging.yml @@ -6,7 +6,7 @@ on: - master jobs: build_and_test: - name: Build and Test + name: Build, Test and Publish to Staging runs-on: ubuntu-latest steps: # checkout the repository content to github runner @@ -15,9 +15,12 @@ jobs: # setup nodejs environment - name: Setup Node.js environment uses: ./.github/actions/setup_node - # cache the dependencies to speed up the build and then install dependencies + # install from the cache to speed up the build and if not then install dependencies - name: Cache dependencies uses: ./.github/actions/npm_install_from_cache + # save dependencies cache + - name: Save dependencies cache + uses: ./.github/actions/invalidate_master_cache # build the react app - name: Build run: npm run build From e0af983b79b849553a39f4ea45a370cac5b2a871 Mon Sep 17 00:00:00 2001 From: "Ali(Ako) Hosseini" Date: Mon, 16 Oct 2023 17:00:37 +0800 Subject: [PATCH 09/12] ci: rename the workflow --- .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 93002b7d83..0b4c1de06b 100644 --- a/.github/workflows/release-production.yml +++ b/.github/workflows/release-production.yml @@ -5,7 +5,7 @@ on: - production_* jobs: build_test_and_publish: - name: Build and Test + name: Build, Test and Publish to Production runs-on: ubuntu-latest steps: # checkout the repository content to github runner @@ -14,7 +14,7 @@ jobs: # setup nodejs environment - name: Setup Node.js environment uses: ./.github/actions/setup_node - # cache the dependencies to speed up the build and then install dependencies + # install from the cache to speed up the build and if not then install dependencies - name: Cache dependencies uses: ./.github/actions/npm_install_from_cache # build the react app From ba496c93cec3c113c7ef457db44c38e026ae19f8 Mon Sep 17 00:00:00 2001 From: "Ali(Ako) Hosseini" Date: Mon, 16 Oct 2023 17:04:22 +0800 Subject: [PATCH 10/12] ci: run tests on staging and production releases --- .github/workflows/release-production.yml | 7 ++----- .github/workflows/release-staging.yml | 8 ++------ 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/.github/workflows/release-production.yml b/.github/workflows/release-production.yml index 0b4c1de06b..3346dc4b7b 100644 --- a/.github/workflows/release-production.yml +++ b/.github/workflows/release-production.yml @@ -8,19 +8,16 @@ jobs: name: Build, Test and Publish to Production runs-on: ubuntu-latest steps: - # checkout the repository content to github runner - name: Checkout uses: actions/checkout@v4 - # setup nodejs environment - name: Setup Node.js environment uses: ./.github/actions/setup_node - # install from the cache to speed up the build and if not then install dependencies - name: Cache dependencies uses: ./.github/actions/npm_install_from_cache - # build the react app - name: Build run: npm run build - # run tests + - name: Test + run: npm run test - name: Publish to Cloudflare Staging uses: ./.github/actions/publish_to_cloudflare_production diff --git a/.github/workflows/release-staging.yml b/.github/workflows/release-staging.yml index f0728ef74e..528190cb62 100644 --- a/.github/workflows/release-staging.yml +++ b/.github/workflows/release-staging.yml @@ -9,21 +9,17 @@ jobs: name: Build, Test and Publish to Staging runs-on: ubuntu-latest steps: - # checkout the repository content to github runner - name: Checkout uses: actions/checkout@v4 - # setup nodejs environment - name: Setup Node.js environment uses: ./.github/actions/setup_node - # install from the cache to speed up the build and if not then install dependencies - name: Cache dependencies uses: ./.github/actions/npm_install_from_cache - # save dependencies cache - name: Save dependencies cache uses: ./.github/actions/invalidate_master_cache - # build the react app - name: Build run: npm run build - # run tests + - name: Test + run: npm run test - name: Publish to Cloudflare Staging uses: ./.github/actions/publish_to_cloudflare_staging From a6f28a85cfa6d3d6f11ee94b86580d42535bf5ca Mon Sep 17 00:00:00 2001 From: "Ali(Ako) Hosseini" Date: Thu, 19 Oct 2023 13:13:02 +0800 Subject: [PATCH 11/12] Update .github/actions/publish_to_pages_production/action.yml Co-authored-by: Matin shafiei --- .github/actions/publish_to_pages_production/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/publish_to_pages_production/action.yml b/.github/actions/publish_to_pages_production/action.yml index 5a58701145..dcafebedf7 100644 --- a/.github/actions/publish_to_pages_production/action.yml +++ b/.github/actions/publish_to_pages_production/action.yml @@ -17,5 +17,5 @@ runs: run: | npm i wrangler@3.1.0 npx wrangler pages deploy dist/ --project-name=deriv-smarttrader --branch=main - echo "New website - http://dsmarttrader.deriv.com" + echo "New website - https://dsmarttrader.deriv.com" shell: bash From 2e0f77bbed9826df17a689811ddc15273506d9a1 Mon Sep 17 00:00:00 2001 From: "Ali(Ako) Hosseini" Date: Thu, 19 Oct 2023 13:13:25 +0800 Subject: [PATCH 12/12] Update action.yml --- .github/actions/publish_to_pages_staging/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/publish_to_pages_staging/action.yml b/.github/actions/publish_to_pages_staging/action.yml index cd8cd66fc3..0541f5bcf5 100644 --- a/.github/actions/publish_to_pages_staging/action.yml +++ b/.github/actions/publish_to_pages_staging/action.yml @@ -17,5 +17,5 @@ runs: run: | npm i wrangler@3.1.0 npx wrangler pages deploy dist/ --project-name=deriv-smarttrader --branch=staging - echo "New staging website - http://staging-dsmarttrader.deriv.com" + echo "New staging website - https://staging-dsmarttrader.deriv.com" shell: bash