diff --git a/.github/actions/build/action.yml b/.github/actions/build/action.yml new file mode 100644 index 00000000..e4dbb33c --- /dev/null +++ b/.github/actions/build/action.yml @@ -0,0 +1,15 @@ +name: build +description: Build Docusaurus project +inputs: + NODE_ENV: + description: Node environment + required: false + default: staging +runs: + using: composite + steps: + - name: Building Docusaurus project + env: + NODE_ENV: ${{ inputs.NODE_ENV }} + run: npm run build + shell: bash diff --git a/.github/actions/invalidate_master_cache/action.yml b/.github/actions/invalidate_master_cache/action.yml new file mode 100644 index 00000000..51d88d31 --- /dev/null +++ b/.github/actions/invalidate_master_cache/action.yml @@ -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 }}-node_modules-${{ hashFiles('./package-lock.json') }} diff --git a/.github/actions/notify_slack/action.yml b/.github/actions/notify_slack/action.yml new file mode 100644 index 00000000..a416c5c3 --- /dev/null +++ b/.github/actions/notify_slack/action.yml @@ -0,0 +1,37 @@ +name: notify_slack +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 api.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 api.deriv.com with version *'"${{ inputs.VERSION }}"'*" + }' \ + ${{ inputs.SLACK_WEBHOOK_URL }} + shell: bash 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 00000000..91fe827f --- /dev/null +++ b/.github/actions/npm_install_from_cache/action.yml @@ -0,0 +1,15 @@ +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 install + shell: bash 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 00000000..ca2822f1 --- /dev/null +++ b/.github/actions/publish_to_pages_production/action.yml @@ -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 wrangler@3.10.1 + cd build + npx wrangler pages deploy . --project-name=deriv-developers-portal-pages --branch=main + echo "New website - https://api.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 00000000..63e25c8c --- /dev/null +++ b/.github/actions/publish_to_pages_staging/action.yml @@ -0,0 +1,22 @@ +name: publish_to_pages_staging +description: Publishes 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.10.1 + cd build + npx wrangler pages deploy . --project-name=deriv-developers-portal-pages --branch=staging + echo "New staging website - https://staging-api.deriv.com/" + shell: bash diff --git a/.github/actions/setup_node/action.yml b/.github/actions/setup_node/action.yml new file mode 100644 index 00000000..4b60f3cd --- /dev/null +++ b/.github/actions/setup_node/action.yml @@ -0,0 +1,9 @@ +name: Setup Node +description: Sets up Node.js +runs: + using: composite + steps: + - name: Use Node.js 16.x + uses: actions/setup-node@v3 + with: + node-version: 16.x diff --git a/.github/actions/versioning/action.yml b/.github/actions/versioning/action.yml new file mode 100644 index 00000000..1a1f6c07 --- /dev/null +++ b/.github/actions/versioning/action.yml @@ -0,0 +1,13 @@ +name: versioning +description: Generates a version for the build +inputs: + RELEASE_TYPE: + description: Release Type + required: false + default: staging +runs: + using: composite + steps: + - name: Tag build + run: echo "${{ inputs.RELEASE_TYPE }} $(date -u +'%Y-%m-%dT%H:%M:%SZ')" > build/version + shell: bash diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml deleted file mode 100755 index e08fe4af..00000000 --- a/.github/workflows/codecov.yml +++ /dev/null @@ -1,32 +0,0 @@ -name: Codecov Workflow -on: - pull_request: - branches: - - '**' - push: - branches: - - master -jobs: - build: - name: Build - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@master - - name: Use Node.js 16.x - uses: actions/setup-node@v1 - with: - node-version: 16.x - - name: install, bootstrap and make test coverage - run: | - npm ci - npm run build - npm run test - - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v3.1.1 - with: - directory: ./coverage - fail_ci_if_error: false - files: ./coverage/lcov.info - name: codecov-umbrella - verbose: true diff --git a/.github/workflows/coveralls.yml b/.github/workflows/coveralls.yml new file mode 100755 index 00000000..421bf231 --- /dev/null +++ b/.github/workflows/coveralls.yml @@ -0,0 +1,25 @@ +name: Coveralls Workflow +on: + pull_request: + branches: + - '**' + push: + branches: + - master +jobs: + build: + name: Build + runs-on: ubuntu-latest # TODO: Replace this with the appropriate runner for Deriv-Api-Docs when provided + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup Node + uses: './.github/actions/setup_node' + - name: Install dependencies + uses: './.github/actions/npm_install_from_cache' + - name: Build + uses: ./.github/actions/build + - name: Run Tests + run: npm run test -- --collectCoverage + - name: Coveralls + uses: coverallsapp/github-action@v2 diff --git a/.github/workflows/release_production.yml b/.github/workflows/release_production.yml new file mode 100644 index 00000000..dabeaae7 --- /dev/null +++ b/.github/workflows/release_production.yml @@ -0,0 +1,54 @@ +name: Deriv Api Docs Production Workflow +on: + push: + tags: + - production_v* +jobs: + build_and_publish: + name: Builds and Publishes to Cloudflare Pages Production + environment: Production + runs-on: ubuntu-latest # TODO: Replace this with the appropriate runner for Deriv-Api-Docs when provided + outputs: + RELEASE_VERSION: ${{ steps.extract_version.outputs.RELEASE_VERSION }} + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup Node + uses: ./.github/actions/setup_node + - name: Install dependencies + uses: ./.github/actions/npm_install_from_cache + - name: Build + uses: ./.github/actions/build + with: + NODE_ENV: production + - name: Versioning + uses: ./.github/actions/versioning + with: + RELEASE_TYPE: production + - name: Extract version + id: extract_version + run: echo "RELEASE_VERSION=$(cat build/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 + environment: Production + runs-on: ubuntu-latest # TODO: Replace this with the appropriate runner for Deriv-Api-Docs when provided + if: always() + needs: + - build_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/notify_slack + with: + RELEASE_TYPE: Production + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} + STATUS: ${{ env.WORKFLOW_CONCLUSION }} + version: ${{ needs.build_and_publish.outputs.RELEASE_VERSION}} diff --git a/.github/workflows/release_staging.yml b/.github/workflows/release_staging.yml new file mode 100644 index 00000000..249df8bd --- /dev/null +++ b/.github/workflows/release_staging.yml @@ -0,0 +1,28 @@ +name: Deriv Api Docs Staging Workflow +on: + push: + branches: + - master +jobs: + build_and_publish: + name: Builds and Publishes to Cloudflare Pages Staging + runs-on: ubuntu-latest # TODO: Replace this with the appropriate runner for Deriv-Api-Docs when provided + environment: Staging + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup Node + uses: ./.github/actions/setup_node + - name: Install Dependencies + uses: ./.github/actions/npm_install_from_cache + - name: Invalidate Cache + uses: ./.github/actions/invalidate_master_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 }} diff --git a/README.md b/README.md index 0066b5f3..3d9ff82c 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ This repository contains the information and code related to the Deriv API documentation. ![Prerequisite](https://img.shields.io/badge/node-%3E%3D16.16.0-blue.svg) -[![codecov](https://codecov.io/gh/binary-com/deriv-api-docs/branch/master/graph/badge.svg?token=HXCKP3ZTWP)](https://codecov.io/gh/binary-com/deriv-api-docs) +[![Coverage Status](https://coveralls.io/repos/github/binary-com/deriv-api-docs/badge.svg?branch=master)](https://coveralls.io/github/binary-com/deriv-api-docs?branch=master)