From 3f9dda646c4c7d1fba96e95aaa62edadf8e246c9 Mon Sep 17 00:00:00 2001 From: shayan khaleghparast Date: Tue, 21 Nov 2023 12:43:30 +0800 Subject: [PATCH 01/14] feat: added respected actions for circle-ci config --- .github/actions/build/action.yml | 24 +++++++ .../git_checkout_from_cache/action.yml | 33 +++++++++ .github/actions/npm_install/action.yml | 20 ++++++ .../publish_to_pages_production/action.yml | 10 +++ .../publish_to_pages_staging/action.yml | 10 +++ .../send_slack_notifications/action.yml | 39 +++++++++++ .github/actions/test/action.yml | 10 +++ .github/workflows/release.yml | 70 +++++++++++++++++++ .github/workflows/test.yml | 17 +++++ 9 files changed, 233 insertions(+) create mode 100644 .github/actions/build/action.yml create mode 100644 .github/actions/git_checkout_from_cache/action.yml create mode 100644 .github/actions/npm_install/action.yml create mode 100644 .github/actions/publish_to_pages_production/action.yml create mode 100644 .github/actions/publish_to_pages_staging/action.yml create mode 100644 .github/actions/send_slack_notifications/action.yml create mode 100644 .github/actions/test/action.yml create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/test.yml diff --git a/.github/actions/build/action.yml b/.github/actions/build/action.yml new file mode 100644 index 000000000..84dab8bf7 --- /dev/null +++ b/.github/actions/build/action.yml @@ -0,0 +1,24 @@ +name: build +inputs: + GD_API_KEY: + description: 'Google drive api key' + required: false + GD_APP_ID: + description: 'Google drive app id' + required: false + GD_CLIENT_ID: + description: 'Google drive client id' + required: false + TRACKJS_TOKEN: + description: 'trackjs token' + required: false +runs: + steps: + - name: Build all packages + env: + GD_CLIENT_ID: ${{ inputs.GD_CLIENT_ID }} + GD_API_KEY: ${{ inputs.GD_API_KEY }} + GD_APP_ID: ${{ inputs.GD_APP_ID }} + TRACKJS_TOKEN: ${{ inputs.TRACKJS_TOKEN }} + run: npm run build + shell: bash \ No newline at end of file diff --git a/.github/actions/git_checkout_from_cache/action.yml b/.github/actions/git_checkout_from_cache/action.yml new file mode 100644 index 000000000..6ada4c7a2 --- /dev/null +++ b/.github/actions/git_checkout_from_cache/action.yml @@ -0,0 +1,33 @@ +name: git_checkout_from_cache +runs: + using: composite + steps: + - name: restore_cache + uses: actions/cache@v3.3.2 + with: + key: source-v1-{{ .Branch }}-{{ .Revision }} + path: node_modules + restore-keys: |- + source-v1-{{ .Branch }}-{{ .Revision }} + source-v1-{{ .Branch }}- + source-v1- + - name: Fetch git tags + run: |- + mkdir -p ~/.ssh + ssh-keygen -F github.com || ssh-keyscan github.com >> ~/.ssh/known_hosts + echo 'github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ== ' >> ~/.ssh/known_hosts + # Fetch tags if git cache is present + if [ -e /home/circleci/project/.git ] + then + git fetch origin --tags -f + fi + shell: bash + - uses: actions/checkout@v4.1.0 + - name: Compress git objects + run: git gc + shell: bash + - name: save_cache + uses: actions/cache@v3.3.2 + with: + path: ".git" + key: source-v1-{{ .Branch }}-{{ .Revision }} \ No newline at end of file diff --git a/.github/actions/npm_install/action.yml b/.github/actions/npm_install/action.yml new file mode 100644 index 000000000..5d0965102 --- /dev/null +++ b/.github/actions/npm_install/action.yml @@ -0,0 +1,20 @@ +name: npm_install +runs: + using: composite + steps: + - name: restore_cache + uses: actions/cache@v3.3.2 + with: + key: npm-v1-{{ checksum "package.json" }} + path: node_modules + restore-keys: |- + npm-v1-{{ checksum "package.json" }} + npm-v1- + - name: Install npm modules + run: npm install + shell: bash + - name: save_cache + uses: actions/cache@v3.3.2 + with: + path: node_modules + key: npm-v1-{{ checksum "package.json" }} \ No newline at end of file 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 000000000..c03767d42 --- /dev/null +++ b/.github/actions/publish_to_pages_production/action.yml @@ -0,0 +1,10 @@ +name: publish_to_pages_production +runs: + using: composite + steps: + - name: Publish to cloudflare pages (production) + run: |- + cd www + npx wrangler pages publish . --project-name=deriv-binary-bot-pages --branch=main + echo "New website - http://cf-pages-deriv-binary-bot.deriv.com" + shell: bash \ No newline at end of file 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 000000000..eff8838ad --- /dev/null +++ b/.github/actions/publish_to_pages_staging/action.yml @@ -0,0 +1,10 @@ +name: publish_to_pages_staging +runs: + using: composite + steps: + - name: Publish to cloudflare pages (staging) + run: |- + cd www + npx wrangler pages publish . --project-name=deriv-binary-bot-pages --branch=staging + echo "New staging website - http://staging.cf-pages-deriv-binary-bot.deriv.com" + shell: bash \ No newline at end of file diff --git a/.github/actions/send_slack_notifications/action.yml b/.github/actions/send_slack_notifications/action.yml new file mode 100644 index 000000000..550c7ca48 --- /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 deriv bot 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 deriv bot with version ${{ inputs.VERSION }}" + }' \ + ${{ inputs.SLACK_WEBHOOK_URL }} + shell: bash diff --git a/.github/actions/test/action.yml b/.github/actions/test/action.yml new file mode 100644 index 000000000..882e440c8 --- /dev/null +++ b/.github/actions/test/action.yml @@ -0,0 +1,10 @@ +- name: run_tests +runs: + using: composite + steps: + - name: run tests + run: | + for i in {1..3}; do + npm test && break + done + shell: bash diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..e8b629ba7 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,70 @@ +name: deriv-com/binary-bot/release +on: + push: + branches: + - master +jobs: + release_staging: + if: # GitHub does not currently support regular expressions inside if conditions +# github.ref == 'refs/heads//^master$/' + runs-on: ubuntu-latest + container: + image: node:18.16 + steps: + - uses: actions/checkout@v4.1.0 + - uses: "./.github/actions/git_checkout_from_cache" + - uses: "./.github/actions/npm_install" +# # This item has no matching transformer +# - test: + - uses: "./.github/actions/build" + - uses: actions/upload-artifact@v3.1.3 + with: + path: www/. +# # `run` was not transformed because it is missing a `command` + - uses: "./.github/actions/notify_slack" + publish_cloudflare_staging: + if: # GitHub does not currently support regular expressions inside if conditions +# github.ref == 'refs/heads//^master$/' + runs-on: ubuntu-latest + container: + image: node:20.2.0 + needs: + - release_staging + steps: + - uses: actions/checkout@v4.1.0 + - uses: actions/download-artifact@v3.0.2 + with: + path: www + - uses: "./.github/actions/publish_to_pages_staging" + release_production: + if: # GitHub does not currently support regular expressions inside if conditions +# (github.ref == 'refs/tags//^production.*/') && (github.ref != 'refs/heads//.*/') + runs-on: ubuntu-latest + container: + image: node:18.6 + steps: + - uses: actions/checkout@v4.1.0 + - uses: "./.github/actions/git_checkout_from_cache" + - uses: "./.github/actions/npm_install" +# # This item has no matching transformer +# - test: + - uses: "./.github/actions/build" + - uses: actions/upload-artifact@v3.1.3 + with: + path: www/. +# # `run` was not transformed because it is missing a `command` + - uses: "./.github/actions/notify_slack" + publish_cloudflare_production: + if: # GitHub does not currently support regular expressions inside if conditions +# (github.ref == 'refs/tags//^production.*/') && (github.ref != 'refs/heads//.*/') + runs-on: ubuntu-latest + container: + image: node:20.2.0 + needs: + - release_production + steps: + - uses: actions/checkout@v4.1.0 + - uses: actions/download-artifact@v3.0.2 + with: + path: www + - uses: "./.github/actions/publish_to_pages_production" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 000000000..a056e5b55 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,17 @@ +name: deriv-com/binary-bot/test +on: + push: + branches: + - master +jobs: + test: + if: # GitHub does not currently support regular expressions inside if conditions +# github.ref != 'refs/heads//^master$/' + runs-on: ubuntu-latest + container: + image: node:18.16 + steps: + - uses: actions/checkout@v4.1.0 + - uses: "./.github/actions/git_checkout_from_cache" + - uses: "./.github/actions/npm_install" + - uses: "./.github/actions/test" From 6eab55dde3b1c7227a04fbd80f42526f30c47ea7 Mon Sep 17 00:00:00 2001 From: shayan khaleghparast Date: Tue, 21 Nov 2023 14:53:01 +0800 Subject: [PATCH 02/14] chore: removed unnecessary step from test workflow --- .github/workflows/test.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a056e5b55..d3912beee 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,16 +2,15 @@ name: deriv-com/binary-bot/test on: push: branches: - - master + - '*' + - '!master' jobs: test: - if: # GitHub does not currently support regular expressions inside if conditions -# github.ref != 'refs/heads//^master$/' runs-on: ubuntu-latest container: image: node:18.16 steps: - - uses: actions/checkout@v4.1.0 + # - uses: actions/checkout@v4.1.0 - uses: "./.github/actions/git_checkout_from_cache" - uses: "./.github/actions/npm_install" - uses: "./.github/actions/test" From 19e515086f7c50734756d4e3ee1bdf104dc41605 Mon Sep 17 00:00:00 2001 From: shayan khaleghparast Date: Fri, 24 Nov 2023 10:31:33 +0800 Subject: [PATCH 03/14] feat: added release flows and updated actions --- .../git_checkout_from_cache/action.yml | 3 +- .../action.yml | 10 +++- .../publish_to_cf_pages_staging/action.yml | 18 ++++++ .../publish_to_pages_staging/action.yml | 10 ---- .github/actions/setup_node/action.yml | 14 +++++ .github/versioning/action.yml | 14 +++++ .github/workflows/release_production.yml | 60 +++++++++++++++++++ .github/workflows/release_staging.yml | 41 +++++++++++++ .github/workflows/test.yml | 1 - 9 files changed, 158 insertions(+), 13 deletions(-) rename .github/actions/{publish_to_pages_production => publish_to_cf_pages_production}/action.yml (51%) create mode 100644 .github/actions/publish_to_cf_pages_staging/action.yml delete mode 100644 .github/actions/publish_to_pages_staging/action.yml create mode 100644 .github/actions/setup_node/action.yml create mode 100644 .github/versioning/action.yml create mode 100644 .github/workflows/release_production.yml create mode 100644 .github/workflows/release_staging.yml diff --git a/.github/actions/git_checkout_from_cache/action.yml b/.github/actions/git_checkout_from_cache/action.yml index 6ada4c7a2..158a3fc2a 100644 --- a/.github/actions/git_checkout_from_cache/action.yml +++ b/.github/actions/git_checkout_from_cache/action.yml @@ -5,8 +5,8 @@ runs: - name: restore_cache uses: actions/cache@v3.3.2 with: - key: source-v1-{{ .Branch }}-{{ .Revision }} path: node_modules + key: source-v1-{{ .Branch }}-{{ .Revision }} restore-keys: |- source-v1-{{ .Branch }}-{{ .Revision }} source-v1-{{ .Branch }}- @@ -22,6 +22,7 @@ runs: git fetch origin --tags -f fi shell: bash + - name: Checkout - uses: actions/checkout@v4.1.0 - name: Compress git objects run: git gc diff --git a/.github/actions/publish_to_pages_production/action.yml b/.github/actions/publish_to_cf_pages_production/action.yml similarity index 51% rename from .github/actions/publish_to_pages_production/action.yml rename to .github/actions/publish_to_cf_pages_production/action.yml index c03767d42..e1510cb02 100644 --- a/.github/actions/publish_to_pages_production/action.yml +++ b/.github/actions/publish_to_cf_pages_production/action.yml @@ -1,4 +1,12 @@ -name: publish_to_pages_production +name: publish_to_cf_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: diff --git a/.github/actions/publish_to_cf_pages_staging/action.yml b/.github/actions/publish_to_cf_pages_staging/action.yml new file mode 100644 index 000000000..b29e5cf17 --- /dev/null +++ b/.github/actions/publish_to_cf_pages_staging/action.yml @@ -0,0 +1,18 @@ +name: publish_to_cf_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) + run: |- + cd www + npx wrangler pages publish . --project-name=deriv-binary-bot-pages --branch=main + echo "New staging website - http://staging.cf-pages-deriv-binary-bot.deriv.com" + shell: bash \ No newline at end of file diff --git a/.github/actions/publish_to_pages_staging/action.yml b/.github/actions/publish_to_pages_staging/action.yml deleted file mode 100644 index eff8838ad..000000000 --- a/.github/actions/publish_to_pages_staging/action.yml +++ /dev/null @@ -1,10 +0,0 @@ -name: publish_to_pages_staging -runs: - using: composite - steps: - - name: Publish to cloudflare pages (staging) - run: |- - cd www - npx wrangler pages publish . --project-name=deriv-binary-bot-pages --branch=staging - echo "New staging website - http://staging.cf-pages-deriv-binary-bot.deriv.com" - shell: bash \ No newline at end of file diff --git a/.github/actions/setup_node/action.yml b/.github/actions/setup_node/action.yml new file mode 100644 index 000000000..82c0de123 --- /dev/null +++ b/.github/actions/setup_node/action.yml @@ -0,0 +1,14 @@ +name: Setup Node +description: 'Set up Node.js' +inputs: + node-version: + description: 'The version of Node.js to use' + required: false + default: '18.x' +runs: + using: composite + steps: + - name: Use Node.js ${{ inputs.node-version}} + uses: actions/setup-node@v3 + with: + node-version: ${{ inputs.node-version}} \ No newline at end of file diff --git a/.github/versioning/action.yml b/.github/versioning/action.yml new file mode 100644 index 000000000..9886bf904 --- /dev/null +++ b/.github/versioning/action.yml @@ -0,0 +1,14 @@ + +name: Versioning Action +description: version the release and store it in the environment variable +on: + push: + branches: + - main + +runs: + using: composite + steps: + - name: Set version + run: echo "VERSION=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_ENV + shell: bash diff --git a/.github/workflows/release_production.yml b/.github/workflows/release_production.yml new file mode 100644 index 000000000..38ee3c8e4 --- /dev/null +++ b/.github/workflows/release_production.yml @@ -0,0 +1,60 @@ +name: Binary Bot Production Workflow +on: + push: + tags: + - production.* +jobs: + release_production: + name: Build, Test and Deploy to Cloudflare Pages + runs-on: ubuntu-latest + container: + image: node:18.16 + outputs: + RELEASE_VERSION: ${{ steps.extract_version.outputs.RELEASE_VERSION }} + steps: + - name: Checkout + uses: "./.github/actions/git_checkout_from_cache" + - name: Install Dependencies + uses: "./.github/actions/npm_install" + - name: Build + uses: "./.github/actions/build" + with: + GD_API_KEY: ${{ secrets.GD_API_KEY }} + GD_APP_ID: ${{ secrets.GD_APP_ID }} + GD_CLIENT_ID: ${{ secrets.GD_CLIENT_ID }} + TRACKJS_TOKEN: ${{ secrets.TRACKJS_TOKEN }} + - name: Test + uses: "./.github/actions/test" + - name: Versioning + uses: "./.github/actions/versioning" + with: + release_type: production + - name: Extract version + id: extract_version + run: echo "RELEASE_VERSION=${VERSION}" >> $GITHUB_OUTPUT + - name: Deploy to Cloudflare Pages + uses: "./.github/actions/publish_to_cf_pages_production" + with: + CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} + send_slack_notification: + if: always() + needs: [release_production] + runs-on: ubuntu-latest + 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: ${{ needs.release_production.outputs.RELEASE_VERSION}} + + + + + diff --git a/.github/workflows/release_staging.yml b/.github/workflows/release_staging.yml new file mode 100644 index 000000000..ae5c3080b --- /dev/null +++ b/.github/workflows/release_staging.yml @@ -0,0 +1,41 @@ +name: deriv-com/binary-bot/release-staging +on: + push: + branches: + - master +jobs: + release_staging: + runs-on: ubuntu-latest + container: + image: node:18.16 + outputs: + RELEASE_VERSION: ${{ steps.extract_version.outputs.RELEASE_VERSION }} + steps: + - name: Checkout + uses: "./.github/actions/git_checkout_from_cache" + - name: Install Dependencies + uses: "./.github/actions/npm_install" + - name: Build + uses: "./.github/actions/build" + with: + GD_API_KEY: ${{ secrets.GD_API_KEY }} + GD_APP_ID: ${{ secrets.GD_APP_ID }} + GD_CLIENT_ID: ${{ secrets.GD_CLIENT_ID }} + TRACKJS_TOKEN: ${{ secrets.TRACKJS_TOKEN }} + - name: Test + uses: "./.github/actions/test" + - name: Versioning + uses: "./.github/actions/versioning" + with: + release_type: production + - name: Extract Version + id: extract_version + run: echo "RELEASE_VERSION=${VERSION}" >> $GITHUB_OUTPUT + - name: Deploy to Cloudflare Pages + uses: "./.github/actions/publish_to_cf_pages_staging" + with: + CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} + + + diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d3912beee..0c1601ab6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,7 +10,6 @@ jobs: container: image: node:18.16 steps: - # - uses: actions/checkout@v4.1.0 - uses: "./.github/actions/git_checkout_from_cache" - uses: "./.github/actions/npm_install" - uses: "./.github/actions/test" From 93ae4e4f24ffd9077142af2ba29d40a13d24db59 Mon Sep 17 00:00:00 2001 From: shayan khaleghparast Date: Fri, 24 Nov 2023 12:20:40 +0800 Subject: [PATCH 04/14] refactor: finished test workflow setup --- .../git_checkout_from_cache/action.yml | 34 --------- .../actions/invalidate_npm_cache/action.yml | 11 +++ .github/actions/npm_install/action.yml | 20 ------ .../actions/npm_install_from_cache/action.yml | 16 +++++ .github/actions/restore_cache/action.yml | 18 +++++ .github/workflows/release.yml | 70 ------------------- .github/workflows/test.yml | 26 +++---- 7 files changed, 59 insertions(+), 136 deletions(-) delete mode 100644 .github/actions/git_checkout_from_cache/action.yml create mode 100644 .github/actions/invalidate_npm_cache/action.yml delete mode 100644 .github/actions/npm_install/action.yml create mode 100644 .github/actions/npm_install_from_cache/action.yml create mode 100644 .github/actions/restore_cache/action.yml delete mode 100644 .github/workflows/release.yml diff --git a/.github/actions/git_checkout_from_cache/action.yml b/.github/actions/git_checkout_from_cache/action.yml deleted file mode 100644 index 158a3fc2a..000000000 --- a/.github/actions/git_checkout_from_cache/action.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: git_checkout_from_cache -runs: - using: composite - steps: - - name: restore_cache - uses: actions/cache@v3.3.2 - with: - path: node_modules - key: source-v1-{{ .Branch }}-{{ .Revision }} - restore-keys: |- - source-v1-{{ .Branch }}-{{ .Revision }} - source-v1-{{ .Branch }}- - source-v1- - - name: Fetch git tags - run: |- - mkdir -p ~/.ssh - ssh-keygen -F github.com || ssh-keyscan github.com >> ~/.ssh/known_hosts - echo 'github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ== ' >> ~/.ssh/known_hosts - # Fetch tags if git cache is present - if [ -e /home/circleci/project/.git ] - then - git fetch origin --tags -f - fi - shell: bash - - name: Checkout - - uses: actions/checkout@v4.1.0 - - name: Compress git objects - run: git gc - shell: bash - - name: save_cache - uses: actions/cache@v3.3.2 - with: - path: ".git" - key: source-v1-{{ .Branch }}-{{ .Revision }} \ No newline at end of file diff --git a/.github/actions/invalidate_npm_cache/action.yml b/.github/actions/invalidate_npm_cache/action.yml new file mode 100644 index 000000000..6586edc5f --- /dev/null +++ b/.github/actions/invalidate_npm_cache/action.yml @@ -0,0 +1,11 @@ +name: invalidate_npm_cache +description: Invalidate the Master NPM cache +runs: + using: composite + steps: + + - name: save_cache + uses: actions/cache/save@v3 + with: + path: node_modules + key: ${{ runner.os }}-build-master-cache-${{ hashFiles('./package-lock.json') }} \ No newline at end of file diff --git a/.github/actions/npm_install/action.yml b/.github/actions/npm_install/action.yml deleted file mode 100644 index 5d0965102..000000000 --- a/.github/actions/npm_install/action.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: npm_install -runs: - using: composite - steps: - - name: restore_cache - uses: actions/cache@v3.3.2 - with: - key: npm-v1-{{ checksum "package.json" }} - path: node_modules - restore-keys: |- - npm-v1-{{ checksum "package.json" }} - npm-v1- - - name: Install npm modules - run: npm install - shell: bash - - name: save_cache - uses: actions/cache@v3.3.2 - with: - path: node_modules - key: npm-v1-{{ checksum "package.json" }} \ No newline at end of file diff --git a/.github/actions/npm_install_from_cache/action.yml b/.github/actions/npm_install_from_cache/action.yml new file mode 100644 index 000000000..f558c40bb --- /dev/null +++ b/.github/actions/npm_install_from_cache/action.yml @@ -0,0 +1,16 @@ +name: npm_install_from_cache +description: Install npm modules from cache and if there is no cache then install them from scratch +runs: + using: composite + steps: + - name: Cache node modules + id: cache-nodemodules + uses: actions/cache/restore@v3 + with: + path: node_modules + key: ${{ runner.os }}-build-master-cache-${{ hashFiles('./package-lock.json') }} + + - name: Install npm modules + if: steps.cache-nodemodules.outputs.cache-hit != 'true' + run: npm install + shell: bash \ No newline at end of file diff --git a/.github/actions/restore_cache/action.yml b/.github/actions/restore_cache/action.yml new file mode 100644 index 000000000..ecdd2415b --- /dev/null +++ b/.github/actions/restore_cache/action.yml @@ -0,0 +1,18 @@ +name: restore_cache +description: restore cache from master +inputs: + path: + description: 'The path to restore cache from' + required: true + key: + description: 'The key to restore cache from' + required: true + +runs: + using: composite + steps: + - name: restore_cache + uses: actions/cache/restore@v3 + with: + path: node_modules + key: ${{ runner.os }}-build-master-cache-${{ hashFiles('./package-lock.json') }} \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index e8b629ba7..000000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,70 +0,0 @@ -name: deriv-com/binary-bot/release -on: - push: - branches: - - master -jobs: - release_staging: - if: # GitHub does not currently support regular expressions inside if conditions -# github.ref == 'refs/heads//^master$/' - runs-on: ubuntu-latest - container: - image: node:18.16 - steps: - - uses: actions/checkout@v4.1.0 - - uses: "./.github/actions/git_checkout_from_cache" - - uses: "./.github/actions/npm_install" -# # This item has no matching transformer -# - test: - - uses: "./.github/actions/build" - - uses: actions/upload-artifact@v3.1.3 - with: - path: www/. -# # `run` was not transformed because it is missing a `command` - - uses: "./.github/actions/notify_slack" - publish_cloudflare_staging: - if: # GitHub does not currently support regular expressions inside if conditions -# github.ref == 'refs/heads//^master$/' - runs-on: ubuntu-latest - container: - image: node:20.2.0 - needs: - - release_staging - steps: - - uses: actions/checkout@v4.1.0 - - uses: actions/download-artifact@v3.0.2 - with: - path: www - - uses: "./.github/actions/publish_to_pages_staging" - release_production: - if: # GitHub does not currently support regular expressions inside if conditions -# (github.ref == 'refs/tags//^production.*/') && (github.ref != 'refs/heads//.*/') - runs-on: ubuntu-latest - container: - image: node:18.6 - steps: - - uses: actions/checkout@v4.1.0 - - uses: "./.github/actions/git_checkout_from_cache" - - uses: "./.github/actions/npm_install" -# # This item has no matching transformer -# - test: - - uses: "./.github/actions/build" - - uses: actions/upload-artifact@v3.1.3 - with: - path: www/. -# # `run` was not transformed because it is missing a `command` - - uses: "./.github/actions/notify_slack" - publish_cloudflare_production: - if: # GitHub does not currently support regular expressions inside if conditions -# (github.ref == 'refs/tags//^production.*/') && (github.ref != 'refs/heads//.*/') - runs-on: ubuntu-latest - container: - image: node:20.2.0 - needs: - - release_production - steps: - - uses: actions/checkout@v4.1.0 - - uses: actions/download-artifact@v3.0.2 - with: - path: www - - uses: "./.github/actions/publish_to_pages_production" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0c1601ab6..ec45c7725 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,15 +1,17 @@ name: deriv-com/binary-bot/test on: - push: - branches: - - '*' - - '!master' + push: + branches: + - '*' + - '!master' jobs: - test: - runs-on: ubuntu-latest - container: - image: node:18.16 - steps: - - uses: "./.github/actions/git_checkout_from_cache" - - uses: "./.github/actions/npm_install" - - uses: "./.github/actions/test" + test: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4.1.0 + - name: Compress git objects + run: git gc + shell: bash + - uses: './.github/actions/npm_install_from_cache' + - uses: './.github/actions/test' From c979c836f46fd4ffe7cc2a1ee1e9e547271c10ea Mon Sep 17 00:00:00 2001 From: shayan khaleghparast Date: Fri, 24 Nov 2023 14:06:43 +0800 Subject: [PATCH 05/14] feat: finalized all workflows and actions --- .github/actions/build/action.yml | 26 ++-- .../actions/invalidate_npm_cache/action.yml | 11 +- .../actions/npm_install_from_cache/action.yml | 20 ++-- .../publish_to_cf_pages_production/action.yml | 16 +-- .../publish_to_cf_pages_staging/action.yml | 16 +-- .github/actions/restore_cache/action.yml | 18 --- .../send_slack_notifications/action.yml | 36 +++--- .github/actions/setup_node/action.yml | 3 +- .github/actions/test/action.yml | 3 +- .github/actions/versioning/action.yml | 17 +++ .github/versioning/action.yml | 14 --- .github/workflows/release_production.yml | 111 +++++++++--------- .github/workflows/release_staging.yml | 71 ++++++----- .github/workflows/test.yml | 20 +++- 14 files changed, 184 insertions(+), 198 deletions(-) delete mode 100644 .github/actions/restore_cache/action.yml create mode 100644 .github/actions/versioning/action.yml delete mode 100644 .github/versioning/action.yml diff --git a/.github/actions/build/action.yml b/.github/actions/build/action.yml index 84dab8bf7..11950b74f 100644 --- a/.github/actions/build/action.yml +++ b/.github/actions/build/action.yml @@ -1,24 +1,26 @@ name: build +description: Build all packages inputs: GD_API_KEY: - description: 'Google drive api key' + description: "Google drive api key" required: false GD_APP_ID: - description: 'Google drive app id' + description: "Google drive app id" required: false GD_CLIENT_ID: - description: 'Google drive client id' + description: "Google drive client id" required: false TRACKJS_TOKEN: - description: 'trackjs token' + description: "trackjs token" required: false runs: + using: composite steps: - - name: Build all packages - env: - GD_CLIENT_ID: ${{ inputs.GD_CLIENT_ID }} - GD_API_KEY: ${{ inputs.GD_API_KEY }} - GD_APP_ID: ${{ inputs.GD_APP_ID }} - TRACKJS_TOKEN: ${{ inputs.TRACKJS_TOKEN }} - run: npm run build - shell: bash \ No newline at end of file + - name: Build all packages + env: + GD_CLIENT_ID: ${{ inputs.GD_CLIENT_ID }} + GD_API_KEY: ${{ inputs.GD_API_KEY }} + GD_APP_ID: ${{ inputs.GD_APP_ID }} + TRACKJS_TOKEN: ${{ inputs.TRACKJS_TOKEN }} + run: npm run build + shell: bash diff --git a/.github/actions/invalidate_npm_cache/action.yml b/.github/actions/invalidate_npm_cache/action.yml index 6586edc5f..95365beaa 100644 --- a/.github/actions/invalidate_npm_cache/action.yml +++ b/.github/actions/invalidate_npm_cache/action.yml @@ -3,9 +3,8 @@ description: Invalidate the Master NPM cache runs: using: composite steps: - - - name: save_cache - uses: actions/cache/save@v3 - with: - path: node_modules - key: ${{ runner.os }}-build-master-cache-${{ hashFiles('./package-lock.json') }} \ No newline at end of file + - name: save_cache + uses: actions/cache/save@v3 + with: + path: node_modules + key: ${{ runner.os }}-build-master-cache-${{ hashFiles('./package-lock.json') }} diff --git a/.github/actions/npm_install_from_cache/action.yml b/.github/actions/npm_install_from_cache/action.yml index f558c40bb..f3aa51f07 100644 --- a/.github/actions/npm_install_from_cache/action.yml +++ b/.github/actions/npm_install_from_cache/action.yml @@ -3,14 +3,14 @@ description: Install npm modules from cache and if there is no cache then instal runs: using: composite steps: - - name: Cache node modules - id: cache-nodemodules - uses: actions/cache/restore@v3 - with: - path: node_modules - key: ${{ runner.os }}-build-master-cache-${{ hashFiles('./package-lock.json') }} + - name: Cache node modules + id: cache-nodemodules + uses: actions/cache/restore@v3 + with: + path: node_modules + key: ${{ runner.os }}-build-master-cache-${{ hashFiles('./package-lock.json') }} - - name: Install npm modules - if: steps.cache-nodemodules.outputs.cache-hit != 'true' - run: npm install - shell: bash \ No newline at end of file + - name: Install npm modules + if: steps.cache-nodemodules.outputs.cache-hit != 'true' + run: npm install + shell: bash diff --git a/.github/actions/publish_to_cf_pages_production/action.yml b/.github/actions/publish_to_cf_pages_production/action.yml index e1510cb02..a3d611cc2 100644 --- a/.github/actions/publish_to_cf_pages_production/action.yml +++ b/.github/actions/publish_to_cf_pages_production/action.yml @@ -2,17 +2,17 @@ name: publish_to_cf_pages_production description: publish to cloudflare pages (production) inputs: CLOUDFLARE_ACCOUNT_ID: - description: 'Cloudflare account id' + description: "Cloudflare account id" required: true CLOUDFLARE_API_TOKEN: - description: 'Cloudflare token' + description: "Cloudflare token" required: true runs: using: composite steps: - - name: Publish to cloudflare pages (production) - run: |- - cd www - npx wrangler pages publish . --project-name=deriv-binary-bot-pages --branch=main - echo "New website - http://cf-pages-deriv-binary-bot.deriv.com" - shell: bash \ No newline at end of file + - name: Publish to cloudflare pages (production) + run: |- + cd www + npx wrangler pages publish . --project-name=deriv-binary-bot-pages --branch=main + echo "New website - http://cf-pages-deriv-binary-bot.deriv.com" + shell: bash diff --git a/.github/actions/publish_to_cf_pages_staging/action.yml b/.github/actions/publish_to_cf_pages_staging/action.yml index b29e5cf17..e304ae4d7 100644 --- a/.github/actions/publish_to_cf_pages_staging/action.yml +++ b/.github/actions/publish_to_cf_pages_staging/action.yml @@ -2,17 +2,17 @@ name: publish_to_cf_pages_staging description: publish to cloudflare pages (staging) inputs: CLOUDFLARE_ACCOUNT_ID: - description: 'Cloudflare account id' + description: "Cloudflare account id" required: true CLOUDFLARE_API_TOKEN: - description: 'Cloudflare token' + description: "Cloudflare token" required: true runs: using: composite steps: - - name: Publish to cloudflare pages (staging) - run: |- - cd www - npx wrangler pages publish . --project-name=deriv-binary-bot-pages --branch=main - echo "New staging website - http://staging.cf-pages-deriv-binary-bot.deriv.com" - shell: bash \ No newline at end of file + - name: Publish to cloudflare pages (staging) + run: |- + cd www + npx wrangler pages publish . --project-name=deriv-binary-bot-pages --branch=main + echo "New staging website - http://staging.cf-pages-deriv-binary-bot.deriv.com" + shell: bash diff --git a/.github/actions/restore_cache/action.yml b/.github/actions/restore_cache/action.yml deleted file mode 100644 index ecdd2415b..000000000 --- a/.github/actions/restore_cache/action.yml +++ /dev/null @@ -1,18 +0,0 @@ -name: restore_cache -description: restore cache from master -inputs: - path: - description: 'The path to restore cache from' - required: true - key: - description: 'The key to restore cache from' - required: true - -runs: - using: composite - steps: - - name: restore_cache - uses: actions/cache/restore@v3 - with: - path: node_modules - key: ${{ runner.os }}-build-master-cache-${{ hashFiles('./package-lock.json') }} \ No newline at end of file diff --git a/.github/actions/send_slack_notifications/action.yml b/.github/actions/send_slack_notifications/action.yml index 550c7ca48..141f9b612 100644 --- a/.github/actions/send_slack_notifications/action.yml +++ b/.github/actions/send_slack_notifications/action.yml @@ -2,38 +2,38 @@ name: send_slack_notifications description: Send Slack notifications inputs: SLACK_WEBHOOK_URL: - description: 'Slack webhook URL' + description: "Slack webhook URL" required: true status: - description: 'Job status' + description: "Job status" required: true release_type: - description: 'Release type' + description: "Release type" required: true version: - description: 'Version' + description: "Version" required: true - default: 'N/A' + default: "N/A" runs: using: composite steps: - - name: Send Slack Notification on Success + - name: Send Slack Notification on Success - if: inputs.status == 'success' - run: | + if: inputs.status == 'success' + run: | curl -X POST -H 'Content-type: application/json' \ --data '{ "text": "${{ inputs.RELEASE_TYPE }} Release succeeded for deriv bot with version ${{ inputs.VERSION }}" }' \ ${{ inputs.SLACK_WEBHOOK_URL }} - shell: bash + 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 deriv bot 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 deriv bot with version ${{ inputs.VERSION }}" + }' \ + ${{ inputs.SLACK_WEBHOOK_URL }} + shell: bash diff --git a/.github/actions/setup_node/action.yml b/.github/actions/setup_node/action.yml index 82c0de123..6bf274dc3 100644 --- a/.github/actions/setup_node/action.yml +++ b/.github/actions/setup_node/action.yml @@ -3,8 +3,7 @@ description: 'Set up Node.js' inputs: node-version: description: 'The version of Node.js to use' - required: false - default: '18.x' + required: true runs: using: composite steps: diff --git a/.github/actions/test/action.yml b/.github/actions/test/action.yml index 882e440c8..b68d5ffaf 100644 --- a/.github/actions/test/action.yml +++ b/.github/actions/test/action.yml @@ -1,4 +1,5 @@ -- name: run_tests +name: run_tests +description: Run tests runs: using: composite steps: diff --git a/.github/actions/versioning/action.yml b/.github/actions/versioning/action.yml new file mode 100644 index 000000000..24f742ff2 --- /dev/null +++ b/.github/actions/versioning/action.yml @@ -0,0 +1,17 @@ + +name: Versioning Action +description: version the release and store it in the environment variable +inputs: + RELEASE_TYPE: + description: 'release type' + required: true +runs: + using: composite + steps: + - name: Set version + run: | + current_date=$(date -u +'%Y-%m-%dT%H:%M:%SZ') + version="${{ inputs.RELEASE_TYPE }}-GH_Run#:${{ github.run_number }}-Date:$current_date" + echo "Setting version to: $version" + echo "VERSION=$version" >> $GITHUB_ENV + shell: bash diff --git a/.github/versioning/action.yml b/.github/versioning/action.yml deleted file mode 100644 index 9886bf904..000000000 --- a/.github/versioning/action.yml +++ /dev/null @@ -1,14 +0,0 @@ - -name: Versioning Action -description: version the release and store it in the environment variable -on: - push: - branches: - - main - -runs: - using: composite - steps: - - name: Set version - run: echo "VERSION=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_ENV - shell: bash diff --git a/.github/workflows/release_production.yml b/.github/workflows/release_production.yml index 38ee3c8e4..2ee627453 100644 --- a/.github/workflows/release_production.yml +++ b/.github/workflows/release_production.yml @@ -1,60 +1,57 @@ name: Binary Bot Production Workflow on: - push: - tags: - - production.* + push: + tags: + - production.* jobs: - release_production: - name: Build, Test and Deploy to Cloudflare Pages - runs-on: ubuntu-latest - container: - image: node:18.16 - outputs: - RELEASE_VERSION: ${{ steps.extract_version.outputs.RELEASE_VERSION }} - steps: - - name: Checkout - uses: "./.github/actions/git_checkout_from_cache" - - name: Install Dependencies - uses: "./.github/actions/npm_install" - - name: Build - uses: "./.github/actions/build" - with: - GD_API_KEY: ${{ secrets.GD_API_KEY }} - GD_APP_ID: ${{ secrets.GD_APP_ID }} - GD_CLIENT_ID: ${{ secrets.GD_CLIENT_ID }} - TRACKJS_TOKEN: ${{ secrets.TRACKJS_TOKEN }} - - name: Test - uses: "./.github/actions/test" - - name: Versioning - uses: "./.github/actions/versioning" - with: - release_type: production - - name: Extract version - id: extract_version - run: echo "RELEASE_VERSION=${VERSION}" >> $GITHUB_OUTPUT - - name: Deploy to Cloudflare Pages - uses: "./.github/actions/publish_to_cf_pages_production" - with: - CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} - CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} - send_slack_notification: - if: always() - needs: [release_production] - runs-on: ubuntu-latest - 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: ${{ needs.release_production.outputs.RELEASE_VERSION}} - - - - - + release_production: + name: Build, Test and Deploy to Cloudflare Pages + runs-on: ubuntu-latest + outputs: + RELEASE_VERSION: ${{ steps.extract_version.outputs.RELEASE_VERSION }} + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup Node + uses: './.github/actions/setup_node' + with: + node-version: '18.x' + - name: Install Dependencies + uses: './.github/actions/npm_install_from_cache' + - name: Build + uses: './.github/actions/build' + with: + GD_API_KEY: ${{ secrets.GD_API_KEY }} + GD_APP_ID: ${{ secrets.GD_APP_ID }} + GD_CLIENT_ID: ${{ secrets.GD_CLIENT_ID }} + TRACKJS_TOKEN: ${{ secrets.TRACKJS_TOKEN }} + - name: Test + uses: './.github/actions/test' + - name: Versioning + uses: './.github/actions/versioning' + with: + RELEASE_TYPE: production + - name: Extract version + id: extract_version + run: echo "RELEASE_VERSION=${VERSION}" >> $GITHUB_OUTPUT + - name: Deploy to Cloudflare Pages + uses: './.github/actions/publish_to_cf_pages_production' + with: + CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} + send_slack_notification: + if: always() + needs: [release_production] + runs-on: ubuntu-latest + 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: ${{ needs.release_production.outputs.RELEASE_VERSION}} diff --git a/.github/workflows/release_staging.yml b/.github/workflows/release_staging.yml index ae5c3080b..a444d5e25 100644 --- a/.github/workflows/release_staging.yml +++ b/.github/workflows/release_staging.yml @@ -1,41 +1,36 @@ name: deriv-com/binary-bot/release-staging on: - push: - branches: - - master + push: + branches: + - master jobs: - release_staging: - runs-on: ubuntu-latest - container: - image: node:18.16 - outputs: - RELEASE_VERSION: ${{ steps.extract_version.outputs.RELEASE_VERSION }} - steps: - - name: Checkout - uses: "./.github/actions/git_checkout_from_cache" - - name: Install Dependencies - uses: "./.github/actions/npm_install" - - name: Build - uses: "./.github/actions/build" - with: - GD_API_KEY: ${{ secrets.GD_API_KEY }} - GD_APP_ID: ${{ secrets.GD_APP_ID }} - GD_CLIENT_ID: ${{ secrets.GD_CLIENT_ID }} - TRACKJS_TOKEN: ${{ secrets.TRACKJS_TOKEN }} - - name: Test - uses: "./.github/actions/test" - - name: Versioning - uses: "./.github/actions/versioning" - with: - release_type: production - - name: Extract Version - id: extract_version - run: echo "RELEASE_VERSION=${VERSION}" >> $GITHUB_OUTPUT - - name: Deploy to Cloudflare Pages - uses: "./.github/actions/publish_to_cf_pages_staging" - with: - CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} - CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} - - - + release_staging: + name: Build, Test and Deploy to Cloudflare Pages + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup Node + uses: './.github/actions/setup_node' + with: + node-version: '18.x' + - name: Install Dependencies + uses: './.github/actions/npm_install_from_cache' + - name: Build + uses: './.github/actions/build' + with: + GD_API_KEY: ${{ secrets.GD_API_KEY }} + GD_APP_ID: ${{ secrets.GD_APP_ID }} + GD_CLIENT_ID: ${{ secrets.GD_CLIENT_ID }} + TRACKJS_TOKEN: ${{ secrets.TRACKJS_TOKEN }} + - name: Test + uses: './.github/actions/test' + - name: Versioning + uses: './.github/actions/versioning' + with: + RELEASE_TYPE: staging + - name: Deploy to Cloudflare Pages + uses: './.github/actions/publish_to_cf_pages_staging' + with: + CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ec45c7725..cb5036b08 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,17 +1,25 @@ name: deriv-com/binary-bot/test on: - push: + pull_request: branches: - - '*' - - '!master' + - 'master' jobs: test: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4.1.0 - - name: Compress git objects + - name: Setup Node + uses: './.github/actions/setup_node' + with: + node-version: '18.x' + - name: Git Cleanup run: git gc shell: bash - - uses: './.github/actions/npm_install_from_cache' - - uses: './.github/actions/test' + - name: Install Dependencies + uses: './.github/actions/npm_install_from_cache' + - name: Invalidate NPM Cache + if: github.event_name == 'push' && github.ref == 'refs/heads/master' + uses: './.github/actions/invalidate_npm_cache' + - name: Test + uses: './.github/actions/test' From e67035cb11a0074fc38d45b0b80e952130ec789b Mon Sep 17 00:00:00 2001 From: shayan khaleghparast Date: Fri, 24 Nov 2023 14:24:58 +0800 Subject: [PATCH 06/14] fix: fixed missed EOL --- .github/actions/setup_node/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/setup_node/action.yml b/.github/actions/setup_node/action.yml index 6bf274dc3..ddb9b1fee 100644 --- a/.github/actions/setup_node/action.yml +++ b/.github/actions/setup_node/action.yml @@ -10,4 +10,4 @@ runs: - name: Use Node.js ${{ inputs.node-version}} uses: actions/setup-node@v3 with: - node-version: ${{ inputs.node-version}} \ No newline at end of file + node-version: ${{ inputs.node-version}} From da15522aa735f78edfc3872edc2a226b5c81ab4f Mon Sep 17 00:00:00 2001 From: shayan khaleghparast Date: Fri, 24 Nov 2023 14:32:56 +0800 Subject: [PATCH 07/14] fix: resolved pr comment --- .github/actions/test/action.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/actions/test/action.yml b/.github/actions/test/action.yml index b68d5ffaf..4fd0671e3 100644 --- a/.github/actions/test/action.yml +++ b/.github/actions/test/action.yml @@ -4,8 +4,5 @@ runs: using: composite steps: - name: run tests - run: | - for i in {1..3}; do - npm test && break - done + run: npm test shell: bash From 5ffbcd337c327f294748e45b6cd689b342a4df0d Mon Sep 17 00:00:00 2001 From: Shayan Khaleghparast <100833613+shayan-deriv@users.noreply.github.com> Date: Fri, 24 Nov 2023 14:34:18 +0800 Subject: [PATCH 08/14] Update .github/actions/versioning/action.yml Co-authored-by: Jim Daniels Wasswa <104334373+jim-deriv@users.noreply.github.com> --- .github/actions/versioning/action.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/actions/versioning/action.yml b/.github/actions/versioning/action.yml index 24f742ff2..12fe917ef 100644 --- a/.github/actions/versioning/action.yml +++ b/.github/actions/versioning/action.yml @@ -1,4 +1,3 @@ - name: Versioning Action description: version the release and store it in the environment variable inputs: From b7c37d807cd7e4e2c95b510323f1ba96399559ba Mon Sep 17 00:00:00 2001 From: Shayan Khaleghparast <100833613+shayan-deriv@users.noreply.github.com> Date: Fri, 24 Nov 2023 14:37:31 +0800 Subject: [PATCH 09/14] Update .github/workflows/release_staging.yml Co-authored-by: Jim Daniels Wasswa <104334373+jim-deriv@users.noreply.github.com> --- .github/workflows/release_staging.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/release_staging.yml b/.github/workflows/release_staging.yml index a444d5e25..05bde91f3 100644 --- a/.github/workflows/release_staging.yml +++ b/.github/workflows/release_staging.yml @@ -25,10 +25,6 @@ jobs: TRACKJS_TOKEN: ${{ secrets.TRACKJS_TOKEN }} - name: Test uses: './.github/actions/test' - - name: Versioning - uses: './.github/actions/versioning' - with: - RELEASE_TYPE: staging - name: Deploy to Cloudflare Pages uses: './.github/actions/publish_to_cf_pages_staging' with: From 0a9c1ef4f6a8665bc2bb935cb5893cdc6bcb28fe Mon Sep 17 00:00:00 2001 From: shayan khaleghparast Date: Fri, 24 Nov 2023 14:44:37 +0800 Subject: [PATCH 10/14] chore: changed actions/checkout version to be the same with other workflows --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cb5036b08..ca7bc56c3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,7 +8,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v4.1.0 + uses: actions/checkout@v4 - name: Setup Node uses: './.github/actions/setup_node' with: From ba011776c3da604721369111d60e1a9ef542e17e Mon Sep 17 00:00:00 2001 From: shayan khaleghparast Date: Fri, 24 Nov 2023 14:56:43 +0800 Subject: [PATCH 11/14] fix: resolved pr comments --- .github/actions/publish_to_cf_pages_production/action.yml | 3 +++ .github/actions/publish_to_cf_pages_staging/action.yml | 3 +++ .github/actions/setup_node/action.yml | 4 ++-- .github/workflows/test.yml | 3 --- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.github/actions/publish_to_cf_pages_production/action.yml b/.github/actions/publish_to_cf_pages_production/action.yml index a3d611cc2..16fe3fc5a 100644 --- a/.github/actions/publish_to_cf_pages_production/action.yml +++ b/.github/actions/publish_to_cf_pages_production/action.yml @@ -11,6 +11,9 @@ 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: |- cd www npx wrangler pages publish . --project-name=deriv-binary-bot-pages --branch=main diff --git a/.github/actions/publish_to_cf_pages_staging/action.yml b/.github/actions/publish_to_cf_pages_staging/action.yml index e304ae4d7..dbc6f517a 100644 --- a/.github/actions/publish_to_cf_pages_staging/action.yml +++ b/.github/actions/publish_to_cf_pages_staging/action.yml @@ -11,6 +11,9 @@ 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: |- cd www npx wrangler pages publish . --project-name=deriv-binary-bot-pages --branch=main diff --git a/.github/actions/setup_node/action.yml b/.github/actions/setup_node/action.yml index ddb9b1fee..8e47612a3 100644 --- a/.github/actions/setup_node/action.yml +++ b/.github/actions/setup_node/action.yml @@ -7,7 +7,7 @@ inputs: runs: using: composite steps: - - name: Use Node.js ${{ inputs.node-version}} + - name: Use Node.js ${{ inputs.node-version }} uses: actions/setup-node@v3 with: - node-version: ${{ inputs.node-version}} + node-version: ${{ inputs.node-version }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ca7bc56c3..88616fe9b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,9 +13,6 @@ jobs: uses: './.github/actions/setup_node' with: node-version: '18.x' - - name: Git Cleanup - run: git gc - shell: bash - name: Install Dependencies uses: './.github/actions/npm_install_from_cache' - name: Invalidate NPM Cache From 8013eccbc56525538f54765cf6639048d246fd9c Mon Sep 17 00:00:00 2001 From: shayan khaleghparast Date: Fri, 24 Nov 2023 15:57:59 +0800 Subject: [PATCH 12/14] fix: fixed indentation inconsistency --- .../publish_to_cf_pages_staging/action.yml | 4 +- .github/workflows/release_production.yml | 108 +++++++++--------- .github/workflows/release_staging.yml | 58 +++++----- 3 files changed, 85 insertions(+), 85 deletions(-) diff --git a/.github/actions/publish_to_cf_pages_staging/action.yml b/.github/actions/publish_to_cf_pages_staging/action.yml index dbc6f517a..053ca78ab 100644 --- a/.github/actions/publish_to_cf_pages_staging/action.yml +++ b/.github/actions/publish_to_cf_pages_staging/action.yml @@ -12,8 +12,8 @@ runs: steps: - name: Publish to cloudflare pages (staging) env: - CLOUDFLARE_ACCOUNT_ID: ${{ inputs.CLOUDFLARE_ACCOUNT_ID }} - CLOUDFLARE_API_TOKEN: ${{ inputs.CLOUDFLARE_API_TOKEN }} + CLOUDFLARE_ACCOUNT_ID: ${{ inputs.CLOUDFLARE_ACCOUNT_ID }} + CLOUDFLARE_API_TOKEN: ${{ inputs.CLOUDFLARE_API_TOKEN }} run: |- cd www npx wrangler pages publish . --project-name=deriv-binary-bot-pages --branch=main diff --git a/.github/workflows/release_production.yml b/.github/workflows/release_production.yml index 2ee627453..608cd7fd5 100644 --- a/.github/workflows/release_production.yml +++ b/.github/workflows/release_production.yml @@ -1,57 +1,57 @@ name: Binary Bot Production Workflow on: - push: - tags: - - production.* + push: + tags: + - production.* jobs: - release_production: - name: Build, Test and Deploy to Cloudflare Pages - runs-on: ubuntu-latest - outputs: - RELEASE_VERSION: ${{ steps.extract_version.outputs.RELEASE_VERSION }} - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Setup Node - uses: './.github/actions/setup_node' - with: - node-version: '18.x' - - name: Install Dependencies - uses: './.github/actions/npm_install_from_cache' - - name: Build - uses: './.github/actions/build' - with: - GD_API_KEY: ${{ secrets.GD_API_KEY }} - GD_APP_ID: ${{ secrets.GD_APP_ID }} - GD_CLIENT_ID: ${{ secrets.GD_CLIENT_ID }} - TRACKJS_TOKEN: ${{ secrets.TRACKJS_TOKEN }} - - name: Test - uses: './.github/actions/test' - - name: Versioning - uses: './.github/actions/versioning' - with: - RELEASE_TYPE: production - - name: Extract version - id: extract_version - run: echo "RELEASE_VERSION=${VERSION}" >> $GITHUB_OUTPUT - - name: Deploy to Cloudflare Pages - uses: './.github/actions/publish_to_cf_pages_production' - with: - CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} - CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} - send_slack_notification: - if: always() - needs: [release_production] - runs-on: ubuntu-latest - 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: ${{ needs.release_production.outputs.RELEASE_VERSION}} + release_production: + name: Build, Test and Deploy to Cloudflare Pages + runs-on: ubuntu-latest + outputs: + RELEASE_VERSION: ${{ steps.extract_version.outputs.RELEASE_VERSION }} + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup Node + uses: "./.github/actions/setup_node" + with: + node-version: "18.x" + - name: Install Dependencies + uses: "./.github/actions/npm_install_from_cache" + - name: Build + uses: "./.github/actions/build" + with: + GD_API_KEY: ${{ secrets.GD_API_KEY }} + GD_APP_ID: ${{ secrets.GD_APP_ID }} + GD_CLIENT_ID: ${{ secrets.GD_CLIENT_ID }} + TRACKJS_TOKEN: ${{ secrets.TRACKJS_TOKEN }} + - name: Test + uses: "./.github/actions/test" + - name: Versioning + uses: "./.github/actions/versioning" + with: + RELEASE_TYPE: production + - name: Extract version + id: extract_version + run: echo "RELEASE_VERSION=${VERSION}" >> $GITHUB_OUTPUT + - name: Deploy to Cloudflare Pages + uses: "./.github/actions/publish_to_cf_pages_production" + with: + CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} + send_slack_notification: + if: always() + needs: [release_production] + runs-on: ubuntu-latest + 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: ${{ needs.release_production.outputs.RELEASE_VERSION}} diff --git a/.github/workflows/release_staging.yml b/.github/workflows/release_staging.yml index 05bde91f3..097e05685 100644 --- a/.github/workflows/release_staging.yml +++ b/.github/workflows/release_staging.yml @@ -1,32 +1,32 @@ name: deriv-com/binary-bot/release-staging on: - push: - branches: - - master + push: + branches: + - master jobs: - release_staging: - name: Build, Test and Deploy to Cloudflare Pages - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Setup Node - uses: './.github/actions/setup_node' - with: - node-version: '18.x' - - name: Install Dependencies - uses: './.github/actions/npm_install_from_cache' - - name: Build - uses: './.github/actions/build' - with: - GD_API_KEY: ${{ secrets.GD_API_KEY }} - GD_APP_ID: ${{ secrets.GD_APP_ID }} - GD_CLIENT_ID: ${{ secrets.GD_CLIENT_ID }} - TRACKJS_TOKEN: ${{ secrets.TRACKJS_TOKEN }} - - name: Test - uses: './.github/actions/test' - - name: Deploy to Cloudflare Pages - uses: './.github/actions/publish_to_cf_pages_staging' - with: - CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} - CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} + release_staging: + name: Build, Test and Deploy to Cloudflare Pages + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup Node + uses: "./.github/actions/setup_node" + with: + node-version: "18.x" + - name: Install Dependencies + uses: "./.github/actions/npm_install_from_cache" + - name: Build + uses: "./.github/actions/build" + with: + GD_API_KEY: ${{ secrets.GD_API_KEY }} + GD_APP_ID: ${{ secrets.GD_APP_ID }} + GD_CLIENT_ID: ${{ secrets.GD_CLIENT_ID }} + TRACKJS_TOKEN: ${{ secrets.TRACKJS_TOKEN }} + - name: Test + uses: "./.github/actions/test" + - name: Deploy to Cloudflare Pages + uses: "./.github/actions/publish_to_cf_pages_staging" + with: + CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} From a741c2d67884e865e9e4270d37e8a4ed62dbc391 Mon Sep 17 00:00:00 2001 From: shayan khaleghparast Date: Fri, 24 Nov 2023 16:00:40 +0800 Subject: [PATCH 13/14] fix: fixed indentation inconsistency --- .github/workflows/test.yml | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 88616fe9b..ddb8946d2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,22 +1,22 @@ name: deriv-com/binary-bot/test on: - pull_request: - branches: - - 'master' + pull_request: + branches: + - "master" jobs: - test: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Setup Node - uses: './.github/actions/setup_node' - with: - node-version: '18.x' - - name: Install Dependencies - uses: './.github/actions/npm_install_from_cache' - - name: Invalidate NPM Cache - if: github.event_name == 'push' && github.ref == 'refs/heads/master' - uses: './.github/actions/invalidate_npm_cache' - - name: Test - uses: './.github/actions/test' + test: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup Node + uses: "./.github/actions/setup_node" + with: + node-version: "18.x" + - name: Install Dependencies + uses: "./.github/actions/npm_install_from_cache" + - name: Invalidate NPM Cache + if: github.event_name == 'push' && github.ref == 'refs/heads/master' + uses: "./.github/actions/invalidate_npm_cache" + - name: Test + uses: "./.github/actions/test" From feb0de15c78daa13c93c960d5b8d6992a4b17079 Mon Sep 17 00:00:00 2001 From: shayan khaleghparast Date: Tue, 28 Nov 2023 12:52:50 +0800 Subject: [PATCH 14/14] fix: added environment property to workflows --- .github/workflows/release_production.yml | 2 ++ .github/workflows/release_staging.yml | 1 + 2 files changed, 3 insertions(+) diff --git a/.github/workflows/release_production.yml b/.github/workflows/release_production.yml index 608cd7fd5..ce5c2e1bf 100644 --- a/.github/workflows/release_production.yml +++ b/.github/workflows/release_production.yml @@ -6,6 +6,7 @@ on: jobs: release_production: name: Build, Test and Deploy to Cloudflare Pages + environment: Production runs-on: ubuntu-latest outputs: RELEASE_VERSION: ${{ steps.extract_version.outputs.RELEASE_VERSION }} @@ -42,6 +43,7 @@ jobs: send_slack_notification: if: always() needs: [release_production] + environment: Production runs-on: ubuntu-latest steps: - name: Checkout diff --git a/.github/workflows/release_staging.yml b/.github/workflows/release_staging.yml index 097e05685..6edfb1af5 100644 --- a/.github/workflows/release_staging.yml +++ b/.github/workflows/release_staging.yml @@ -6,6 +6,7 @@ on: jobs: release_staging: name: Build, Test and Deploy to Cloudflare Pages + environment: Staging runs-on: ubuntu-latest steps: - name: Checkout