Skip to content

Commit

Permalink
Merge pull request #584 from balakrishna-deriv/configure-cf-pages-tes…
Browse files Browse the repository at this point in the history
…t-links

feat: add cf pages test links
  • Loading branch information
balakrishna-deriv authored Dec 6, 2023
2 parents 56dde4f + 7ac9311 commit 09cdf73
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 0 deletions.
100 changes: 100 additions & 0 deletions .github/workflows/generate_preview_link.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: Generate preview link

permissions:
actions: write
checks: write
contents: write
deployments: write
pull-requests: write
statuses: write

on:
workflow_run:
workflows: ["Pre-generate preview link"]
types:
- completed

concurrency:
group: cloudflare-pages-build-${{ github.event.workflow_run.head_branch }}
cancel-in-progress: true

jobs:
build_and_deploy_preview_link:
runs-on: Ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.workflow_run.head_sha }}
- name: Download artifact
id: download-artifact
uses: dawidd6/action-download-artifact@v2
with:
workflow_conclusion: success
run_id: ${{ github.event.workflow_run.id }}
name: "pr-${{ github.event.workflow_run.id }}"
path: .pr

- name: Retrieve pull request
id: pr_information
run: |
echo "username=$(cat .pr/USERNAME)" >> $GITHUB_OUTPUT
echo "issue_number=$(cat .pr/NR)" >> $GITHUB_OUTPUT
- name: Post preview build comment
id: post_preview_build_comment
uses: "deriv-com/shared-actions/.github/actions/post_preview_build_comment@v1"
with:
issue_number: ${{steps.pr_information.outputs.issue_number}}
head_sha: ${{github.event.workflow_run.head_sha}}

- name: Verify user
uses: "deriv-com/shared-actions/.github/actions/verify_user_in_organization@v1"
with:
username: ${{steps.pr_information.outputs.username}}
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}

- name: Setup Node
uses: actions/setup-node@v1
with:
node-version: 12.22

- name: Install dependencies
uses: "deriv-com/shared-actions/.github/actions/npm_install@v1"

- name: Build
uses: "./.github/actions/build"
with:
target: staging

- name: Build Translations
uses: "./.github/actions/build"
with:
target: translations

- name: "Run Tests"
run: npm run test

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 20

- name: Publish to CF pages branch
id: publish_to_pages_branch
uses: "deriv-com/shared-actions/.github/actions/publish_to_pages_branch@v1"
with:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_TEST_LINKS_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_TEST_LINKS_ACCOUNT_ID }}
project_name: "smarttrader-preview"
branch_name: "pr-${{steps.pr_information.outputs.issue_number}}"
output_dir: dist

- name: "Generate preview link comment"
uses: "deriv-com/shared-actions/.github/actions/post_preview_link_comment@v1"
if: always() && steps.post_preview_build_comment.outcome == 'success'
with:
issue_number: ${{steps.pr_information.outputs.issue_number}}
check_run_id: ${{steps.post_preview_build_comment.outputs.check_run_id}}
preview_url: ${{steps.publish_to_pages_branch.outputs.cf_pages_url}}
status: ${{job.status}}
28 changes: 28 additions & 0 deletions .github/workflows/pre_generate_preview_link.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Pre-generate preview link

permissions:
pull-requests: write

on:
pull_request:
types: [opened, synchronize]

concurrency:
group: cloudflare-pages-verify-${{ github.head_ref }}
cancel-in-progress: true

jobs:
upload_pr_info:
runs-on: Ubuntu-latest
steps:
- name: Retrieve PR information
run: |
mkdir -p ./pr
echo ${{ github.event.number }} > ./pr/NR
echo ${{ github.event.pull_request.user.login }} > ./pr/USERNAME
- name: Upload PR information to artifact
uses: actions/upload-artifact@v2
with:
name: "pr-${{github.run_id}}"
path: pr/

0 comments on commit 09cdf73

Please sign in to comment.