diff --git a/.github/workflows/build-and-deploy-prod.yml b/.github/workflows/build-and-deploy-prod.yml new file mode 100644 index 00000000..e22cc861 --- /dev/null +++ b/.github/workflows/build-and-deploy-prod.yml @@ -0,0 +1,64 @@ +name: Build Production and Deploy to Cloudflare Pages + +on: + push: + tags: + - production_* + +concurrency: + group: cloudflare-pages-build-production + cancel-in-progress: true + +jobs: + build_to_cloudflare_pages: + timeout-minutes: 30 + runs-on: ubuntu-latest + environment: Production + steps: + - name: Checkout to main branch + uses: actions/checkout@v3 + + - name: Setup node + uses: actions/setup-node@v3 + with: + node-version: 20.x + cache: 'npm' + + - name: Get cached dependencies + id: cache-npm + uses: actions/cache/restore@e12d46a63a90f2fae62d114769bbf2a179198b5c + with: + path: node_modules + key: npm-${{ hashFiles('./package-lock.json') }} + + - name: Install dependencies + if: ${{ steps.cache-npm.outputs.cache-hit != 'true' }} + run: npm ci + shell: bash + + - name: Build + run: npm run build + + - name: Run tests for Eslint + run: npm run test:lint + + - name: Publish to Cloudflare Pages + uses: "deriv-com/shared-actions/.github/actions/publish_to_pages_branch@master" + with: + CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} + project_name: ${{ secrets.CLOUDFLARE_PROJECT_NAME }} + branch_name: master + output_dir: dist + cname_url: p2p.deriv.com + send_slack_success: + name: Send Release Slack notification success + runs-on: ubuntu-latest + if: success() + needs: [build_to_cloudflare_pages] + steps: + - name: Send Slack Notification + uses: "deriv-com/shared-actions/.github/actions/send_slack_notification@master" + with: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} + MESSAGE: "Production Release succeeded for p2p.deriv.com with version ${{ github.head_ref }}" diff --git a/.github/workflows/build-and-deploy-staging.yml b/.github/workflows/build-and-deploy-staging.yml index 7f0fe315..f542f847 100644 --- a/.github/workflows/build-and-deploy-staging.yml +++ b/.github/workflows/build-and-deploy-staging.yml @@ -36,7 +36,7 @@ jobs: run: npm ci shell: bash - - name: Build staging + - name: Build run: npm run build env: VITE_PROJECT_NAME: ${{ vars.VITE_PROJECT_NAME }} @@ -44,23 +44,15 @@ jobs: VITE_TRANSLATIONS_CDN_URL: ${{ vars.VITE_TRANSLATIONS_CDN_URL }} - - name: Run tests for Eslint + - name: Run tests for Eslintbuild_to_cloudflare_pages run: npm run test:lint - name: Publish to Cloudflare Pages - id: publish-to-pages - env: - CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} - CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} - HEAD_BRANCH: ${{ github.head_ref }} - run: | - echo "Installing Wrangler CLI" - npm i -g wrangler - echo "Deploying build to Cloudflare Pages" - directory='dist' - projectName=${{ secrets.CLOUDFLARE_PROJECT_NAME }} - branch=$(echo "$HEAD_BRANCH" | head -c 20 | sed 's/[\/_\.]/-/g; s/[^a-zA-Z0-9]$/1/') - cf_preview_url=$(wrangler pages deploy $directory --project-name=$projectName --branch=$branch > log.txt 2>&1; echo $?) - echo "------" - preview_url=https://$branch.$projectName.pages.dev - cat log.txt + uses: "deriv-com/shared-actions/.github/actions/publish_to_pages_branch@master" + with: + CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} + project_name: ${{ secrets.CLOUDFLARE_PROJECT_NAME }} + branch_name: staging + output_dir: dist + cname_url: staging-p2p.deriv.com