diff --git a/.github/workflows/generate-preview-link.yml b/.github/workflows/generate-preview-link.yml index a75f95f3b24..5feadffe14f 100644 --- a/.github/workflows/generate-preview-link.yml +++ b/.github/workflows/generate-preview-link.yml @@ -28,6 +28,10 @@ jobs: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' steps: + - name: Checkout to repo + uses: actions/checkout@v3 + with: + ref: ${{ github.event.workflow_run.head_sha }} - name: Download artifact id: download-artifact uses: dawidd6/action-download-artifact@v2 @@ -35,11 +39,12 @@ jobs: 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 "issue_number=$(cat ./NR)" > $GITHUB_OUTPUT + echo "issue_number=$(cat .pr/NR)" >> $GITHUB_OUTPUT - name: 'Generate action link comment' id: generate_action_url @@ -59,7 +64,6 @@ jobs: - name: Post Cloudflare Pages Preview comment uses: marocchino/sticky-pull-request-comment@v2 with: - GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} header: Cloudflare Pages Preview Comment number: ${{steps.pr_information.outputs.issue_number}} message: ${{steps.generate_action_url.outputs.comment}} @@ -72,11 +76,11 @@ jobs: user=$(cat ./USERNAME) response=$(curl -s -L \ -w "%{http_code}" \ - -o /dev/null -H "Accept: application/vnd.github+json" \ - -H "Authorization: Bearer ${{ secrets.PERSONAL_ACCESS_TOKEN }}" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - "https://api.github.com/orgs/binary-com/memberships/$user") - + -o /dev/null -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer ${{ secrets.PERSONAL_ACCESS_TOKEN }}" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + "https://api.github.com/orgs/binary-com/memberships/$user") + if [ $response != "200" ]; then echo "User is not a member of binary-com organization." exit 1 @@ -84,11 +88,6 @@ jobs: echo "User is a member of binary-com organization." echo "Proceeding to build and deploy for the pull request: https://github.com/binary-com/deriv-com/pull/$(cat ./NR)" fi - - name: Checkout to repo - uses: actions/checkout@v3 - with: - ref: ${{ github.event.workflow_run.head_sha }} - - name: Setup node uses: actions/setup-node@v2 @@ -136,15 +135,18 @@ jobs: projectName='deriv-com-preview-links' head_branch=${{github.event.workflow_run.head_branch}} branch=$(echo $head_branch | head -c 20 | sed 's/[\/_\.]/-/g; s/[^a-zA-Z0-9]$/1/') - preview_url=$(wrangler pages deploy $directory --project-name=$projectName --branch=$branch > log.txt 2>&1; echo $?) + cf_preview_url=$(wrangler pages deploy $directory --project-name=$projectName --branch=$branch > log.txt 2>&1; echo $?) echo "------" + preview_url=https://$branch.deriv-com-preview-links.pages.dev cat log.txt if grep -q "Deployment complete" log.txt; then - echo "preview_url=https://$branch.deriv-com-preview-links.pages.dev" > "$GITHUB_OUTPUT" + echo "preview_url=$preview_url" >> "$GITHUB_OUTPUT" + echo $preview_url > .pr/PREVIEW_URL else echo "Deployment to Cloudflare Pages failed." exit 1 fi + - name: 'Generate preview link comment' if: success() id: generate_preview_url @@ -184,8 +186,13 @@ jobs: if: success() || failure() uses: marocchino/sticky-pull-request-comment@v2 with: - GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} header: Cloudflare Pages Preview Comment number: ${{steps.pr_information.outputs.issue_number}} message: ${{steps.generate_preview_url.outputs.comment || steps.generate_failure_comment.outputs.comment }} recreate: true + + - name: Upload PR information to artifact + uses: actions/upload-artifact@v2 + with: + name: 'pr-${{github.run_id}}' + path: .pr diff --git a/.github/workflows/lighthouse.yml b/.github/workflows/lighthouse.yml index 61b2b9939ca..b7b69b6ef0b 100644 --- a/.github/workflows/lighthouse.yml +++ b/.github/workflows/lighthouse.yml @@ -9,35 +9,48 @@ permissions: statuses: write on: - issue_comment: - types: [created] + workflow_run: + workflows: ['Generate preview link'] + types: + - completed jobs: generate_lighthouse_audit: timeout-minutes: 30 runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion == 'success' }} steps: + - 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 "issue_number=$(cat ./pr/NR)" >> $GITHUB_OUTPUT + echo "preview_url=$(cat ./pr/PREVIEW_URL)" >> $GITHUB_OUTPUT + - name: Add comment to PR id: loading_comment_to_pr uses: marocchino/sticky-pull-request-comment@v2 with: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - number: ${{ github.event.issue.number }} + number: ${{ steps.pr_information.outputs.issue_number }} header: lighthouse message: | Running Lighthouse audit... - - name: Capture preview URL - id: capture_preview_url - uses: deriv-com/capture-url-from-issue-comment@v1.0.4 - with: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - uses: actions/checkout@v3 - name: Audit preview URL with Lighthouse id: lighthouse_audit uses: treosh/lighthouse-ci-action@v9 with: urls: | - ${{ steps.capture_preview_url.outputs.url }} + ${{ steps.pr_information.outputs.preview_url }} uploadArtifacts: true temporaryPublicStorage: true runs: 5 diff --git a/.github/workflows/smoketests.yml b/.github/workflows/smoketests.yml index dc7e6157a96..5a720b2c3e5 100644 --- a/.github/workflows/smoketests.yml +++ b/.github/workflows/smoketests.yml @@ -9,23 +9,35 @@ permissions: statuses: write on: - issue_comment: - types: [created] + workflow_run: + workflows: ['Generate preview link'] + types: + - completed jobs: cypress-run: runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion == 'success' }} strategy: fail-fast: false matrix: containers: [1, 2, 3, 4, 5] steps: - - name: Capture preview URL - id: capture_preview_url - uses: deriv-com/capture-url-from-issue-comment@v1.0.4 + - name: Download artifact + id: download-artifact + uses: dawidd6/action-download-artifact@v2 with: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + 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 "issue_number=$(cat ./pr/NR)" >> $GITHUB_OUTPUT + echo "preview_url=$(cat ./pr/PREVIEW_URL)" >> $GITHUB_OUTPUT - name: Checkout external repository with Cypress tests uses: actions/checkout@v4 @@ -50,9 +62,9 @@ jobs: # Creating a token https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} # Set Base Url from client_payload. - CYPRESS_BASE_URL: ${{ steps.capture_preview_url.outputs.url }} + CYPRESS_BASE_URL: ${{ steps.pr_information.outputs.preview_url }} # Send PR details to Cypress test run - COMMIT_INFO_MESSAGE: PR "${{ github.event.issue.number }}" in Repo "${{ github.repository }}" (v2) + COMMIT_INFO_MESSAGE: PR "${{ steps.pr_information.outputs.issue_number }}" in Repo "${{ github.repository }}" (v2) - name: Set comments message id: set_msg @@ -70,6 +82,6 @@ jobs: uses: marocchino/sticky-pull-request-comment@v2 with: header: Smoke tests status update - number: ${{ github.event.issue.number }} + number: ${{ steps.pr_information.outputs.issue_number }} message: '${{ steps.set_msg.outputs.msg }}' recreate: true