Skip to content

Commit

Permalink
chore: refactor ./scripts/bundle-impact/
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed Aug 12, 2024
1 parent 4ebc2c2 commit d6ab3af
Show file tree
Hide file tree
Showing 8 changed files with 215 additions and 53 deletions.
12 changes: 3 additions & 9 deletions .github/workflows/bundle-impact.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ 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
Expand All @@ -23,12 +21,8 @@ jobs:
pnpm install -C scripts/bundle-impact
- name: Run Bundle Impact
uses: actions/github-script@v7
env:
RADASHI_BOT_TOKEN: ${{ secrets.RADASHI_BOT_TOKEN }}
TARGET_BRANCH: ${{ github.base_ref }}
NODE_OPTIONS: '--import ./scripts/bundle-impact/node_modules/tsx/dist/esm/index.mjs'
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const script = await import('${{ github.workspace }}/scripts/bundle-impact/pr-bundle-impact.ts')
await script.run({ github, core, context })
run: |
scripts/bundle-impact/node_modules/.bin/tsx pr-bundle-impact.ts ${{ github.event.number }}
2 changes: 1 addition & 1 deletion scripts/bundle-impact.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ if [ ! -d "scripts/release-notes/node_modules" ]; then
pnpm install -C scripts/release-notes
fi

pnpm -s tsx -e '
pnpm -s scripts/bundle-impact/node_modules/.bin/tsx -e '
import {weighChangedFunctions} from "./scripts/bundle-impact/weigh-changed.ts";
weighChangedFunctions().then(console.log)
'
4 changes: 3 additions & 1 deletion scripts/bundle-impact/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
"private": true,
"type": "module",
"dependencies": {
"@octokit/rest": "^21.0.1",
"execa": "^9.3.0",
"radashi": "12.2.0-beta.7fb6e89",
"mri": "^1.2.0",
"radashi": "link:../../src",
"tsx": "^4.17.0"
}
}
145 changes: 137 additions & 8 deletions scripts/bundle-impact/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { test, vi } from 'vitest'
import { dedent } from './dedent'
import { expect, test, vi } from 'vitest'
import { run } from './pr-bundle-impact'
import { dedent } from './src/dedent'
import { weighChangedFunctions } from './src/weigh-changed'


vi.mock('./weigh-changed', () => ({
weighChangedFunctions: vi.fn(),
}))
vi.mock('./src/weigh-changed')

test('adds the bundle impact to the PR body', async () => {
const pulls = {
const pulls: Record<string, { body: string }> = {
'radashi-org/radashi#1': {
body: dedent`
## Summary
Expand All @@ -29,7 +27,15 @@ test('adds the bundle impact to the PR body', async () => {
github: {
rest: {
pulls: {
get({ owner, repo, pull_number }) {
get({
owner,
repo,
pull_number,
}: {
owner: string
repo: string
pull_number: number
}) {
return Promise.resolve({
data: pulls[`${owner}/${repo}#${pull_number}`],
})
Expand All @@ -44,9 +50,7 @@ test('adds the bundle impact to the PR body', async () => {
},
}

const { weighChangedFunctions } = await import('./weigh-changed')

weighChangedFunctions.mockResolvedValue(
vi.mocked(weighChangedFunctions).mockResolvedValue(
dedent`
| Status | File | Size | Difference (%) |
| --- | --- | --- | --- |
Expand Down Expand Up @@ -101,7 +105,7 @@ test('adds the bundle impact to the PR body', async () => {

// Now that we've tested adding the "Bundle Impact" section, let's test
// updating that section upon a subsequent run.
weighChangedFunctions.mockResolvedValue(
vi.mocked(weighChangedFunctions).mockResolvedValue(
dedent`
| Status | File | Size | Difference (%) |
| --- | --- | --- | --- |
Expand Down
Loading

0 comments on commit d6ab3af

Please sign in to comment.