message: ci(vrt): update trigger to use labeled event on pull requests
diff: name: vrt
  on:
  - workflow_run:
  - workflows: [CI]
  + pull_request:
  types:
  - - completed
  + - labeled
  concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
  -permissions:
  - contents: write
  -
  jobs:
  - pull_request:
  + update-snapshots:
  if: >
  github.repository == 'primer/react' &&
  - github.event.workflow_run.event == 'pull_request'
  - runs-on: ubuntu-latest
  - outputs:
  - labels: ${{ steps.get-pull-request.outputs.pullRequestLabels }}
  - steps:
  - - uses: potiuk/get-workflow-origin@v1_1
  - id: get-pull-request
  - with:
  - token: ${{ secrets.GITHUB_TOKEN }}
  -
  - update-snapshots:
  - needs: pull_request
  - if: contains(needs.pull_request.outputs.labels.*.name, 'update snapshots')
  + contains(github.event.pull_request.labels.*.name, 'update snapshots')
  runs-on: ubuntu-latest
  steps:
  - uses: actions/checkout@v3
  @@ -40,41 +24,9 @@ jobs:
  run: npm ci
  - name: Install browsers
  run: npx playwright install --with-deps
  - - uses: actions/github-script@v3.1.0
  - name: Download built storybook from CI
  - id: storybook-artifact
  - with:
  - script: |
  - const fs = require('fs');
  - const artifacts = await github.actions.listWorkflowRunArtifacts({
  - owner: context.repo.owner,
  - repo: context.repo.repo,
  - run_id: ${{ github.event.workflow_run.id }},
  - });
  - const [matchArtifact] = artifacts.data.artifacts.filter((artifact) => {
  - return artifact.name == "storybook"
  - });
  -
  - if (!matchArtifact) {
  - core.setOutput('status', 'not-uploaded');
  - core.warning('No storybook artifact was uploaded from the CI workflow');
  - return;
  - }
  -
  - const download = await github.actions.downloadArtifact({
  - owner: context.repo.owner,
  - repo: context.repo.repo,
  - artifact_id: matchArtifact.id,
  - archive_format: 'zip',
  - });
  -
  - fs.writeFileSync('${{github.workspace}}/storybook.zip', Buffer.from(download.data));
  - core.setOutput('status', 'uploaded');
  -
  - - run: unzip storybook.zip -d storybook-static
  - if: ${{ steps.storybook-artifact.outputs.status == 'uploaded' }}
  + - name: Build storybook
  + run: npx build-storybook
  - name: Run storybook
  - if: ${{ steps.storybook-artifact.outputs.status == 'uploaded' }}
  id: storybook
  run: |
  npx serve -l 6006 storybook-static &
  @@ -82,8 +34,10 @@ jobs:
  echo "pid=$pid" >> $GITHUB_OUTPUT
  sleep 5
  - name: Run VRT
  - if: ${{ steps.storybook-artifact.outputs.status == 'uploaded' }}
  run: npx playwright test --grep @vrt --update-snapshots
  - name: Stop storybook
  - if: ${{ steps.storybook-artifact.outputs.status == 'uploaded' }}
  + if: ${{ always() }}
  run: kill ${{ steps.storybook.outputs.pid }}
  + - uses: actions-ecosystem/action-remove-labels@v1
  + with:
  + labels: 'update snapshots'
  