Skip to content

Commit

Permalink
Merge pull request deriv-com#130 from yaswanth-deriv/yaswanth/setup-g…
Browse files Browse the repository at this point in the history
…ithub-actions-sindabad

build: to migrate from circleci to github workflows
  • Loading branch information
habib-deriv authored Oct 26, 2023
2 parents 5b3104d + 97e75cb commit ec1b6d5
Show file tree
Hide file tree
Showing 9 changed files with 216 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .github/actions/build/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: Build
description: Build for release
runs:
steps:
- name: Building Application
run: npm run build
shell: bash
37 changes: 37 additions & 0 deletions .github/actions/notify_slack/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Notify slack
description: Notify Slack
inputs:
SLACK_WEBHOOK:
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 Sindabad 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 Sindabad with version *'"${{ inputs.version }}"'*"
}' \
${{ inputs.SLACK_WEBHOOK_URL }}
shell: bash
17 changes: 17 additions & 0 deletions .github/actions/npm_install_from_cache/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: npm_install_from_cache
description: Install npm packages from cache
runs:
using: composite
steps:
- name: Cache node modules
id: cache-nodemodules
uses: actions/cache/restore@v3
with:
path: node_modules
key: ${{ runner.os }}-node_modules-${{ hashFiles('./package-lock.json') }}
- name: Install npm dependencies
if: steps.cache-nodemodules.outputs.cache-hit != 'true'
run: |-
npm ci
npm run format
shell: bash
22 changes: 22 additions & 0 deletions .github/actions/publish_to_pages_production/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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 [email protected]
cd packages/core
npx wrangler pages publish . --project-name=sinbad-pages --branch=main
echo "New website - http://cf-pages-sinbad.deriv.com"
shell: bash
22 changes: 22 additions & 0 deletions .github/actions/publish_to_pages_staging/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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 [email protected]
cd public
npx wrangler pages publish . --project-name=sinbad-pages --branch=staging
echo "New staging website - http://staging.cf-pages-sinbad.deriv.com"
shell: bash
21 changes: 21 additions & 0 deletions .github/actions/tag/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Versioning
description: Versioning
inputs:
RELEASE_TYPE:
description: Release Type
required: false
outputs:
version:
description: Version
runs:
using: composite

steps:
- name: Set Version
id: 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
48 changes: 48 additions & 0 deletions .github/workflows/release_production.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Sinbad Production Workflow
on:
push:
tags:
- production_*
jobs:
build_test_and_publish:
name: Build, Test and Publish to Cloudflare Pages Production
runs-on: ubuntu-latest
outputs:
RELEASE_VERSION: ${{ steps.extract_version.outputs.RELEASE_VERSION }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install npm packages
uses: "./.github/actions/npm_install_from_cache"
- name: Build
uses: "./.github/actions/build"
with:
NODE_ENV: production
- name: Versioning
uses: "./.github/actions/tag"
with:
release_type: production
- name: Extract version
id: extract_version
run: echo "RELEASE_VERSION=${version}" >> $GITHUB_OUTPUT
- name: Publish to Cloudflare Pages Production
uses: "./.github/actions/publish_to_pages_production"
with:
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}

send_slack_notification:
name: Send Slack notification
runs-on: ubuntu-latest
if: always()
needs: [build_test_and_publish]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Send Slack Notification
uses: "./.github/actions/send_slack_notifications"
with:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
status: ${{ env.WORKFLOW_CONCLUSION }}
release_type: Production
version: ${{ needs.build_test_and_publish.outputs.RELEASE_VERSION}}
26 changes: 26 additions & 0 deletions .github/workflows/release_staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Sinbad Staging Workflow
on:
push:
branches:
- master

jobs:
build_test_and_publish:
name: Build, Test and Publish to Cloudflare Staging
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Tag
uses: "./.github/actions/tag"
- name: Install npm packages
uses: "./.github/actions/npm_install_from_cache"
- name: Build
uses: "./.github/actions/build"
with:
NODE_ENV: staging
- name: Publish to Cloudflare Pages Staging
uses: "./.github/actions/publish_to_pages_staging"
with:
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
16 changes: 16 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Sinbad Test Workflow
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: Install npm packages
uses: "./.github/actions/npm_install_from_cache"
- name: Build
uses: "./.github/actions/build"

0 comments on commit ec1b6d5

Please sign in to comment.