Skip to content

Commit 8def4c2

Browse files
Add bundle size reports to the PR description (#5280)
1 parent 9a24fda commit 8def4c2

File tree

2 files changed

+41
-13
lines changed

2 files changed

+41
-13
lines changed

.github/workflows/ci.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[ci.yml](./ci.yml) contains the [GitHub workflow](https://docs.github.com/en/get-started/getting-started-with-git/git-workflows) definition for presubmit tests in this repository.
44

5-
All Pull Requests in this repository must pass the checks in this workflow before being merged into the `main` branch. The checks are distributed across several jobs. Each job runs on a seprate build agent. Most of them can run concurrently.
5+
All Pull Requests in this repository must pass the checks in this workflow before being merged into the `main` branch. The checks are distributed across several jobs. Each job runs on a separate build agent. Most of them can run concurrently.
66

77
Many of checks build and test the library code in both the [`beta` and `stable` build flavors](../../docs/references/beta-only-features.md). For such jobs, we use a [job matrix](https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs) to run an instance of the job for each build flavor. The following high-level description of the checks calls out which checks are build-flavor aware.
88

@@ -38,6 +38,6 @@ Many of checks build and test the library code in both the [`beta` and `stable`
3838

3939
- Informational jobs to track jest tests coverage (`compare_jest_tests_coverage`, `update_jest_coverage_report`): These jobs track the jest tests coverage (lines, functions, statements, branches) for `@azure/communication-react` built in the previous steps. Any differences in the coverage are reported as Pull Request comments, _but do not block Pull Request from being merged_. This jobs are build flavor aware.
4040

41-
- Informational jobs to track sample bundle size (`compare_base_bundle_stats`, `update_base_bundle_report`): These jobs track the expected bundle size of the sample applications built in the previous steps. Any differences in the size are reported as Pull Request comments, _but do not block Pull Request from being merged_. This job is not build flavor aware.
41+
- Informational jobs to track sample bundle size (`compare_base_bundle_stats`, `update_base_bundle_report`): These jobs track the expected bundle size of the sample applications built in the previous steps. Any differences in the size are reported as Pull Request comments. If the differences are above a threshold, it will block the Pull Request from being merged. Pull Request owners can add a `significant bundle size change` tag to unblock the merge. This job is not build flavor aware.
4242

4343
- `check_failure`: This is a meta-job that only applies to _post-submit_ workflow run (which re-uses the same `ci.yml` definition). It opens a new GitHub issue in the repository if any fundamental step in the jobs above fails on post-submit workflow run, because it indicates a problem with the CI infrastructure or a bug in the product on `main`. This job is not build flavor aware.

.github/workflows/ci.yml

+39-11
Original file line numberDiff line numberDiff line change
@@ -817,18 +817,46 @@ jobs:
817817
issue-number: ${{ github.event.pull_request.number }}
818818
comment-author: 'github-actions[bot]'
819819
body-includes: '## ${{ matrix.app }} bundle size is'
820-
- name: Create or update comment
821-
uses: peter-evans/create-or-update-comment@v2
820+
- name: Checkout repository
821+
uses: actions/checkout@v4
822+
- name: Delete existing comment
823+
uses: actions/github-script@v4
822824
with:
823-
comment-id: ${{ steps.fc.outputs.comment-id }}
824-
issue-number: ${{ github.event.pull_request.number }}
825-
body: |
826-
## ${{ matrix.app }} bundle size is ***${{ steps.bundles.outputs.change }}***.
827-
- Current size: ${{ steps.bundles.outputs.current_size }}
828-
- Base size: ${{ steps.bundles.outputs.base_size}}
829-
- Diff size: ${{ steps.bundles.outputs.diff}}
830-
edit-mode: replace
831-
825+
github-token: ${{ secrets.GITHUB_TOKEN }}
826+
script: |
827+
const commentId = '${{ steps.fc.outputs.comment-id }}'
828+
if (commentId) {
829+
await github.issues.deleteComment({
830+
owner: context.repo.owner,
831+
repo: context.repo.repo,
832+
comment_id: commentId
833+
})
834+
}
835+
- name: Post new comment
836+
uses: actions/github-script@v4
837+
with:
838+
github-token: ${{ secrets.GITHUB_TOKEN }}
839+
script: |
840+
await github.issues.createComment({
841+
owner: context.repo.owner,
842+
repo: context.repo.repo,
843+
issue_number: context.issue.number,
844+
body: `## ${{ matrix.app }} bundle size is ***${{ steps.bundles.outputs.change }}***.
845+
- Current size: ${{ steps.bundles.outputs.current_size }}
846+
- Base size: ${{ steps.bundles.outputs.base_size }}
847+
- Diff size: ${{ steps.bundles.outputs.diff }}`
848+
});
849+
- name: Check whether the bundle size is increased significantly
850+
if: ${{ github.event_name == 'pull_request' && !contains( github.event.pull_request.labels.*.name, 'significant bundle size change') }}
851+
run: |
852+
significantBundleSizeThreshold=800
853+
app="${{ matrix.app }}"
854+
bundleSizeDiff="${{ steps.bundles.outputs.diff }}"
855+
if [ "$bundleSizeDiff" -ge "$significantBundleSizeThreshold" ]; then
856+
echo "The bundle size diff for $app is greater than the threshold of $significantBundleSizeThreshold kb! If the bundle size increase is intended, please add \`significant bundle size change\` label to the PR." >&2
857+
exit 1
858+
fi
859+
echo "Bundle size diff for $app is below the threshold of $significantBundleSizeThreshold. All is good!"
832860
update_base_bundle_report:
833861
runs-on: ubuntu-latest
834862
name: Upload bundle size report to gist - ${{ matrix.app }}

0 commit comments

Comments
 (0)