Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Shayan/FEQ-911/github-actions-implementation #377

Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/actions/build/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: build
description: Build all packages
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:
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
10 changes: 10 additions & 0 deletions .github/actions/invalidate_npm_cache/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
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') }}
16 changes: 16 additions & 0 deletions .github/actions/npm_install_from_cache/action.yml
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions .github/actions/publish_to_cf_pages_production/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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:
- name: Publish to cloudflare pages (production)
shayan-deriv marked this conversation as resolved.
Show resolved Hide resolved
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
shayan-deriv marked this conversation as resolved.
Show resolved Hide resolved
18 changes: 18 additions & 0 deletions .github/actions/publish_to_cf_pages_staging/action.yml
Original file line number Diff line number Diff line change
@@ -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)
shayan-deriv marked this conversation as resolved.
Show resolved Hide resolved
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
shayan-deriv marked this conversation as resolved.
Show resolved Hide resolved
39 changes: 39 additions & 0 deletions .github/actions/send_slack_notifications/action.yml
Original file line number Diff line number Diff line change
@@ -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
shayan-deriv marked this conversation as resolved.
Show resolved Hide resolved
13 changes: 13 additions & 0 deletions .github/actions/setup_node/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Setup Node
description: 'Set up Node.js'
inputs:
node-version:
description: 'The version of Node.js to use'
required: true
runs:
using: composite
steps:
- name: Use Node.js ${{ inputs.node-version}}
uses: actions/setup-node@v3
with:
node-version: ${{ inputs.node-version}}
shayan-deriv marked this conversation as resolved.
Show resolved Hide resolved
11 changes: 11 additions & 0 deletions .github/actions/test/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: run_tests
description: Run tests
runs:
using: composite
steps:
- name: run tests
run: |
for i in {1..3}; do
npm test && break
done
shayan-deriv marked this conversation as resolved.
Show resolved Hide resolved
shell: bash
17 changes: 17 additions & 0 deletions .github/actions/versioning/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

shayan-deriv marked this conversation as resolved.
Show resolved Hide resolved
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
57 changes: 57 additions & 0 deletions .github/workflows/release_production.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Binary Bot Production Workflow
on:
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'
shayan-deriv marked this conversation as resolved.
Show resolved Hide resolved
with:
GD_API_KEY: ${{ secrets.GD_API_KEY }}
shayan-deriv marked this conversation as resolved.
Show resolved Hide resolved
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()
shayan-deriv marked this conversation as resolved.
Show resolved Hide resolved
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}}
shayan-deriv marked this conversation as resolved.
Show resolved Hide resolved
36 changes: 36 additions & 0 deletions .github/workflows/release_staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: deriv-com/binary-bot/release-staging
on:
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: Versioning
uses: './.github/actions/versioning'
with:
RELEASE_TYPE: staging
shayan-deriv marked this conversation as resolved.
Show resolved Hide resolved
- 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 }}
shayan-deriv marked this conversation as resolved.
Show resolved Hide resolved
25 changes: 25 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: deriv-com/binary-bot/test
on:
pull_request:
branches:
- 'master'
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/[email protected]
- name: Setup Node
uses: './.github/actions/setup_node'
with:
node-version: '18.x'
- name: Git Cleanup
shayan-deriv marked this conversation as resolved.
Show resolved Hide resolved
run: git gc
shell: bash
- 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'