0

I have a demo repo https://github.com/sh977218/Angular-with-Playwright to try to run playwright with Angular on GitHub's action and publish the result to GitHub Page. I'm able to achieve that, but I'd like to improve it by publish each Pull Request's playwright result to GitHub Page and they are all available at same time. Can someone guide me on how to do this? This is the github action yml file

name: Playwright Tests
on:
  push:
    branches: [main, master]
  pull_request:
    branches: [main, master]
# Grant GITHUB_TOKEN the permissions required to make a Pages deployment

jobs:
  Playwright-tests:
    timeout-minutes: 60
    runs-on: ubuntu-latest
    concurrency:
      group: ${{ github.workflow }}-${{ github.ref }}
      cancel-in-progress: true

    # Grant GITHUB_TOKEN the permissions required to make a Pages deployment
    permissions:
      actions: write
      checks: write
      contents: write
      deployments: write
      id-token: write
      issues: write
      discussions: write
      packages: write
      pages: write
      pull-requests: write
      repository-projects: write
      security-events: write
      statuses: write

    # Deploy to the github-pages environment
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: 16
      - name: Install dependencies
        run: npm ci
      - name: Install Playwright Browsers
        run: npx playwright install --with-deps
      - name: Run Playwright tests
        run: npx playwright test

      - uses: actions/upload-artifact@v3
        if: always()
        with:
          name: playwright-report
          path: playwright-report/
          retention-days: 30

      - name: Setup Pages
        uses: actions/configure-pages@v2
      - name: Upload artifact
        uses: actions/upload-pages-artifact@v1.0.7
        with:
          path: playwright-report/
      - name: Deploy Playwright result to Github Pages
        id: deployment
        uses: actions/deploy-pages@v1.2.4

 

Thanks!

Peter Huang
  • 972
  • 4
  • 12
  • 34
  • Not directly related to your question but you could have used `permissions: write-all` instead of listing all the individual items. However, you might want to revise that only to assign the required ones due to security reasons. See https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs#assigning-permissions-to-a-specific-job for more details. – Azeem Feb 10 '23 at 07:12
  • Also, your posted workflow doesn't seem right. Its indentation seems off, maybe due to copy/paste. You should validate it with https://rhysd.github.io/actionlint/. – Azeem Feb 10 '23 at 07:17
  • By "**I'd like to improve it by publish each Pull Request's playwright result to GitHub Page and they are all available at same time**" you mean that you want separate GitHub pages per PR, right? – Azeem Feb 10 '23 at 07:19
  • @Azeem I don't care if its separated GitHub Pages or all PRs' playwright result on one single page. Is there a way to do this? – Peter Huang Feb 10 '23 at 21:43
  • Right. I just looked at your failed workflow runs and those are failing with "**not allowed to deploy to github-pages due to environment protection rules**" error. Looks like you have configured only the `main` branch for deployment using environment protection rules; because, by default, all branches are allowed. You need to reconfigure that to allow deployments from all the branches. See [Deployment branches](https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment#deployment-branches) for more details. – Azeem Feb 11 '23 at 05:42
  • @Azeem Thanks for pointing out this. I have removed the environment protect rules for all branches. Now all branch/PRs have allowed to deploy anything to github page. I have created 2 PRs that deploy to github pages, one PR's action run will overwrite another PR's. My question is, is there way to not override the github pages. – Peter Huang Feb 12 '23 at 20:50
  • By this "**is there way to not override the github pages**", do you mean to have separate deployments per PR? Please update your question with this use case also. Thanks! – Azeem Feb 13 '23 at 03:45

0 Answers0