Skip to content

Commit

Permalink
chore: split check-pr workflow into 3 workflows
Browse files Browse the repository at this point in the history
For the "Bundle Impact" section of a PR to be updated by GitHub actions, the workflow must be triggered with the `pull_request_target` event. For security, keep using the `pull_request` event for linting and testing of PRs.
  • Loading branch information
aleclarson committed Aug 6, 2024
1 parent be83144 commit 24307ef
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 29 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/bundle-impact.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Bundle Impact

on:
pull_request_target:
branches: [main, next]
types: [opened, synchronize]

jobs:
bundle-impact:
name: Calculate Bundle Impact
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: '22.x'
cache: pnpm
- run: pnpm install
- name: Run Bundle Impact
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
console.log(process.env)
delete process.env.GITHUB_TOKEN
const script = require('./scripts/pr-bundle-impact.cjs')
await script.run({github, core, context})
29 changes: 0 additions & 29 deletions .github/workflows/check-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,6 @@ on:
types: [opened, synchronize, reopened, edited]

jobs:
test:
name: Test
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x, 20.x, 22.x]
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: pnpm
- run: pnpm install
- run: pnpm test

validate:
name: Validate
runs-on: ubuntu-latest
Expand All @@ -40,18 +23,6 @@ jobs:
- run: pnpm install
- run: pnpm install @commitlint/[email protected]

- name: Refresh Bundle Impact
uses: actions/github-script@v6
if: ${{ github.head_ref != 'next' }}
continue-on-error: true
env:
TARGET_BRANCH: ${{ github.event.pull_request.base.ref }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { run } = require('./scripts/pr-bundle-impact.cjs');
run({ github, core, context });
- name: Lint
run: pnpm lint

Expand Down
24 changes: 24 additions & 0 deletions .github/workflows/test-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Test Pull Request

on:
pull_request:
branches: [main, next]
types: [opened, synchronize]

jobs:
test:
name: Test
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x, 20.x, 22.x]
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: pnpm
- run: pnpm install
- run: pnpm test

0 comments on commit 24307ef

Please sign in to comment.