Skip to content

Commit

Permalink
Merge pull request #572 from ali-hosseini-deriv/ako/add-github-actions
Browse files Browse the repository at this point in the history
Ako/add GitHub actions
  • Loading branch information
balakrishna-deriv authored Nov 7, 2023
2 parents b53cc5a + 961b9f2 commit 2a3df5b
Show file tree
Hide file tree
Showing 9 changed files with 278 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .github/actions/build/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Build
inputs:
target:
required: true
default: staging
runs:
using: composite
steps:
- name: Building dist for ${{ inputs.target }}
run: node_modules/grunt/bin/grunt releaseci --${{ inputs.target }}
shell: bash
40 changes: 40 additions & 0 deletions .github/actions/notify_slack/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: send_slack_notifications
description: Send Slack notification
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 smarttrader.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 smarttrader.deriv.com with version ${{ inputs.VERSION }}"
}' \
${{ inputs.SLACK_WEBHOOK_URL }}
shell: bash

21 changes: 21 additions & 0 deletions .github/actions/npm_install/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: npm_install
description: Install npm packages
runs:
using: composite
steps:
- name: restore_cache
uses: actions/[email protected]
with:
key: node-{{ checksum "package-lock.json" }}
path: UPDATE_ME
restore-keys: |-
node-{{ checksum "package-lock.json" }}
node-
- name: Install npm packages
run: npm ci
shell: bash
- name: save_cache
uses: actions/[email protected]
with:
path: node_modules
key: node-{{ checksum "package-lock.json" }}
19 changes: 19 additions & 0 deletions .github/actions/publish_to_pages_production/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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)
run: |-
npm i [email protected]
cd dist
npx wrangler pages deploy . --project-name=deriv-binary-static-pages --branch=main
echo "New website - http://cf-pages-deriv-binary-static.deriv.com"
shell: bash
19 changes: 19 additions & 0 deletions .github/actions/publish_to_pages_staging/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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)
run: |-
npm i [email protected]
cd dist
npx wrangler pages deploy . --project-name=deriv-binary-static-pages --branch=staging
echo "New staging website - http://staging.cf-pages-deriv-binary-static.deriv.com"
shell: bash
10 changes: 10 additions & 0 deletions .github/actions/versioning/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: versioning
inputs:
target_branch:
required: false
runs:
using: composite
steps:
- name: Tag build
run: echo "${{ inputs.target_branch }} $(date -u +'%Y-%m-%dT%H:%M:%SZ')" > dist/version
shell: bash
81 changes: 81 additions & 0 deletions .github/workflows/release_production.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: DSmartTrader Production Release
on:
push:
tags:
- production_*
jobs:
build_and_test:
name: Build and Test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v1
with:
node-version: 12.22
- name: Install dependencies
uses: "./.github/actions/npm_install"
- name: Build
uses: "./.github/actions/build"
with:
target: production
- uses: "./.github/actions/versioning"
with:
target_branch: production
- name: "Run Tests"
run: npm run test
- name: Upload Artifacts
uses: actions/upload-artifact@v3
with:
name: dist
path: dist
publish_cloudflare_production:
name: Publish to Cloudflare Production
runs-on: ubuntu-latest
needs: [build_and_test]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 20.x
- name: Download Artifacts
uses: actions/[email protected]
with:
path: dist
- name: Publish to Cloudflare
uses: "./.github/actions/publish_to_pages_production"
with:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}

notify_on_slack:
name: Notify on Slack
if: always()
runs-on: ubuntu-latest

needs: [publish_cloudflare_production, build_and_test]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 20.x
- name: Conclusion
uses: technote-space/workflow-conclusion-action@v3
- uses: actions/[email protected]
with:
path: dist
- name: Grab Version Name
id: extract_version
run: echo "RELEASE_VERSION=${version}" >> $GITHUB_ENV
- name: Send Slack Notification
uses: "./.github/actions/notify_slack"
with:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
status: ${{ env.WORKFLOW_CONCLUSION }}
release_type: Production
version: ${{ steps.extract_version.outputs.RELEASE_VERSION}}
53 changes: 53 additions & 0 deletions .github/workflows/release_staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: DSmartTrader Staging Release
on:
push:
branches:
- master
jobs:
build_and_test:
name: Build and Test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v1
with:
node-version: 12.22
- name: Install dependencies
uses: "./.github/actions/npm_install"
- name: Build Staging
uses: "./.github/actions/build"
with:
target: staging
- name: Build Translations
uses: "./.github/actions/build"
with:
target: translations
- uses: "./.github/actions/versioning"
with:
target_branch: production
- name: "Run Tests"
run: npm run test
- uses: actions/upload-artifact@v3
with:
name: dist
path: dist
publish_cloudflare_production:
name: Publish to Cloudflare Pages Production
runs-on: ubuntu-latest
needs: [build_and_test]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 20.x
- uses: actions/[email protected]
with:
path: dist
- uses: "./.github/actions/publish_to_pages_production"
with:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
24 changes: 24 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: DSmartTrader Test
on:
pull_request:
branches:
- master
jobs:
build_and_test:
name: Build and Test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v1
with:
node-version: 12.22
- name: Install dependencies
uses: "./.github/actions/npm_install"
- name: Build
uses: "./.github/actions/build"
with:
target: production
- name: "Run Tests"
run: npm run test

0 comments on commit 2a3df5b

Please sign in to comment.