fix(dev): tweak frontend-bundle-report

This commit is contained in:
syuilo 2026-06-22 20:49:03 +09:00
commit 6d89d479e2
2 changed files with 46 additions and 7 deletions

View file

@ -104,6 +104,9 @@ jobs:
}); });
const report = artifacts.find((artifact) => artifact.name === artifactName && !artifact.expired); const report = artifacts.find((artifact) => artifact.name === artifactName && !artifact.expired);
if (report) return { done: true, run }; if (report) return { done: true, run };
core.info(`Frontend bundle report run ${run.id} did not produce ${artifactName}.`);
return { done: true, run: null };
} }
return { done: false, run: null }; return { done: false, run: null };
@ -126,8 +129,30 @@ jobs:
core.warning(`Timed out waiting for ${artifactName} from ${workflow_id} for ${headSha}.`); core.warning(`Timed out waiting for ${artifactName} from ${workflow_id} for ${headSha}.`);
- name: Download bundle report from workflow_run - name: Find bundle report artifact
if: github.event_name == 'workflow_run' if: github.event_name == 'workflow_run'
id: find-report-artifact
uses: actions/github-script@v9
with:
script: |
const artifactName = 'frontend-bundle-report';
const { owner, repo } = context.repo;
const artifacts = await github.paginate(github.rest.actions.listWorkflowRunArtifacts, {
owner,
repo,
run_id: context.payload.workflow_run.id,
per_page: 100,
});
const report = artifacts.find((artifact) => artifact.name === artifactName && !artifact.expired);
if (report) {
core.setOutput('exists', 'true');
} else {
core.info(`Workflow run ${context.payload.workflow_run.id} did not produce ${artifactName}.`);
core.setOutput('exists', 'false');
}
- name: Download bundle report from workflow_run
if: github.event_name == 'workflow_run' && steps.find-report-artifact.outputs.exists == 'true'
uses: actions/download-artifact@v8 uses: actions/download-artifact@v8
with: with:
name: frontend-bundle-report name: frontend-bundle-report
@ -147,7 +172,7 @@ jobs:
run-id: ${{ steps.find-report-run.outputs.run-id }} run-id: ${{ steps.find-report-run.outputs.run-id }}
- name: Comment on pull request - name: Comment on pull request
if: github.event_name == 'workflow_run' || steps.find-report-run.outputs.run-id != '' if: (github.event_name == 'workflow_run' && steps.find-report-artifact.outputs.exists == 'true') || steps.find-report-run.outputs.run-id != ''
uses: actions/github-script@v9 uses: actions/github-script@v9
with: with:
github-token: ${{ secrets.FRONTEND_BUNDLE_REPORT_COMMENT_TOKEN || secrets.FRONTEND_JS_SIZE_COMMENT_TOKEN || secrets.FRONTEND_BUNDLE_VISUALIZER_COMMENT_TOKEN || github.token }} github-token: ${{ secrets.FRONTEND_BUNDLE_REPORT_COMMENT_TOKEN || secrets.FRONTEND_JS_SIZE_COMMENT_TOKEN || secrets.FRONTEND_BUNDLE_VISUALIZER_COMMENT_TOKEN || github.token }}

View file

@ -56,21 +56,25 @@ jobs:
path: after path: after
submodules: true submodules: true
- name: Backport visualizer tooling to base if needed - name: Check base visualizer support
id: check-base-visualizer
shell: bash shell: bash
run: | run: |
if ! grep -q 'FRONTEND_BUNDLE_VISUALIZER' before/packages/frontend/vite.config.ts; then if grep -q 'FRONTEND_BUNDLE_VISUALIZER' before/packages/frontend/vite.config.ts; then
cp after/packages/frontend/package.json before/packages/frontend/package.json echo 'supported=true' >> "$GITHUB_OUTPUT"
cp after/packages/frontend/vite.config.ts before/packages/frontend/vite.config.ts else
cp after/pnpm-lock.yaml before/pnpm-lock.yaml echo 'supported=false' >> "$GITHUB_OUTPUT"
echo 'Base commit does not support frontend bundle visualizer. Skipping frontend bundle report.' >> "$GITHUB_STEP_SUMMARY"
fi fi
- name: Setup pnpm - name: Setup pnpm
if: steps.check-base-visualizer.outputs.supported == 'true'
uses: pnpm/action-setup@v6.0.3 uses: pnpm/action-setup@v6.0.3
with: with:
package_json_file: after/package.json package_json_file: after/package.json
- name: Setup Node.js - name: Setup Node.js
if: steps.check-base-visualizer.outputs.supported == 'true'
uses: actions/setup-node@v6.4.0 uses: actions/setup-node@v6.4.0
with: with:
node-version-file: after/.node-version node-version-file: after/.node-version
@ -80,17 +84,21 @@ jobs:
after/pnpm-lock.yaml after/pnpm-lock.yaml
- name: Install dependencies for base - name: Install dependencies for base
if: steps.check-base-visualizer.outputs.supported == 'true'
working-directory: before working-directory: before
run: pnpm i --frozen-lockfile run: pnpm i --frozen-lockfile
- name: Build frontend dependencies for base - name: Build frontend dependencies for base
if: steps.check-base-visualizer.outputs.supported == 'true'
working-directory: before working-directory: before
run: pnpm --filter "frontend^..." run build run: pnpm --filter "frontend^..." run build
- name: Prepare report output - name: Prepare report output
if: steps.check-base-visualizer.outputs.supported == 'true'
run: mkdir -p "$RUNNER_TEMP/frontend-bundle-report" run: mkdir -p "$RUNNER_TEMP/frontend-bundle-report"
- name: Build frontend report for base - name: Build frontend report for base
if: steps.check-base-visualizer.outputs.supported == 'true'
working-directory: before working-directory: before
env: env:
FRONTEND_BUNDLE_VISUALIZER: 'true' FRONTEND_BUNDLE_VISUALIZER: 'true'
@ -99,14 +107,17 @@ jobs:
run: pnpm --filter frontend run build run: pnpm --filter frontend run build
- name: Install dependencies for pull request - name: Install dependencies for pull request
if: steps.check-base-visualizer.outputs.supported == 'true'
working-directory: after working-directory: after
run: pnpm i --frozen-lockfile run: pnpm i --frozen-lockfile
- name: Build frontend dependencies for pull request - name: Build frontend dependencies for pull request
if: steps.check-base-visualizer.outputs.supported == 'true'
working-directory: after working-directory: after
run: pnpm --filter "frontend^..." run build run: pnpm --filter "frontend^..." run build
- name: Build frontend report for pull request - name: Build frontend report for pull request
if: steps.check-base-visualizer.outputs.supported == 'true'
working-directory: after working-directory: after
env: env:
FRONTEND_BUNDLE_VISUALIZER: 'true' FRONTEND_BUNDLE_VISUALIZER: 'true'
@ -115,6 +126,7 @@ jobs:
run: pnpm --filter frontend run build run: pnpm --filter frontend run build
- name: Generate report markdown - name: Generate report markdown
if: steps.check-base-visualizer.outputs.supported == 'true'
shell: bash shell: bash
env: env:
BASE_SHA: ${{ github.event.pull_request.base.sha }} BASE_SHA: ${{ github.event.pull_request.base.sha }}
@ -130,6 +142,7 @@ jobs:
printf '%s\n' "${{ github.event.pull_request.html_url }}" > "$REPORT_DIR/pr-url.txt" printf '%s\n' "${{ github.event.pull_request.html_url }}" > "$REPORT_DIR/pr-url.txt"
- name: Check report - name: Check report
if: steps.check-base-visualizer.outputs.supported == 'true'
run: | run: |
REPORT_DIR="$RUNNER_TEMP/frontend-bundle-report" REPORT_DIR="$RUNNER_TEMP/frontend-bundle-report"
test -s "$REPORT_DIR/before-stats.json" test -s "$REPORT_DIR/before-stats.json"
@ -141,6 +154,7 @@ jobs:
cat "$REPORT_DIR/frontend-bundle-visualizer-report.md" >> "$GITHUB_STEP_SUMMARY" cat "$REPORT_DIR/frontend-bundle-visualizer-report.md" >> "$GITHUB_STEP_SUMMARY"
- name: Upload bundle report - name: Upload bundle report
if: steps.check-base-visualizer.outputs.supported == 'true'
uses: actions/upload-artifact@v7 uses: actions/upload-artifact@v7
with: with:
name: frontend-bundle-report name: frontend-bundle-report