Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Add BundleMon action to check the build size changes #307

Open
wants to merge 10 commits into
base: development
Choose a base branch
from

Conversation

nshandra
Copy link
Contributor

@nshandra nshandra commented Jan 14, 2025

📌 References

📝 Implementation

GitHub action to monitor the build and/or resulting .zip file size.

General steps:

  1. Install BundleMon GitHub App
  2. Create .bundlemonrc via: size_limit="X MB" percent_limit="Y" yarn make-bundlemonrc or copy the .bundlemonrc_template and edit manually. This file will define the report.
  3. Create a workflow file for bundlemonrc.

Notes:

yarn build

This PR edits the build action to copy the ZIP file to the build folder. This is needed because BundleMon has trouble processing large repositories (the ZIP is in the root of the repo, this means that baseDir is '.', leading to this error).
If the ZIP file size is not monitored, this change can be discarded.

yarn make-bundlemonrc

This PR also adds a new yarn action yarn make-bundlemonrc that will create a .bundlemonrc file from the .bundlemonrc_template.
This command needs to be provided with vars to convert the template into an usable file:

  • The size limit is a string that consists of a number and unit of measurement (KB, MB...)
  • The percent limit is a number of the maximum size increase allowed (in %)

If the ZIP file size is not monitored, the $build_file_types generation can be removed.

Template and Demo

Originally the template included redundant entries as a demo, an example of how the look like can be seen here.

The template used there looks like this (this one is adapted to UEApp):

{
    "baseDir": "./build",
    "files": [
        // Monit the build ZIP file.
        {
            "path": "./$npm_package_name.zip",
            "friendlyName": "Build ZIP",
            "compression": "none",
            "maxSize": "$size_limit",
            "maxPercentIncrease": "$percent_limit"
        },
        // Monit a specific file with a "dynamic" name (eg: main.87c4a820.chunk.js)
        // If the <hash> is not specified correctly BundleMon will report the old name as a deletion and the new one as a new file.
        {
            "path": "./static/js/main.<hash>.chunk.js",
            "friendlyName": "Main",
            "compression": "none",
            "maxPercentIncrease": "$percent_limit"
        },
        // Monit all files from baseDir except ZIP type.
        // The idea is to have a list of the files so its easy to identify the offending file.
        // In practice this results in a overly verbose message or in false positives deletions due to dynamic names.
        // Its better to use the CLI to find the file.
        {
            "path": "./**/*.{$build_file_types}",
            "friendlyName": "Build Folder Files",
            "compression": "gzip"
        }
    ],
    // Monit the build folder as a whole. This is an alternative to copying the ZIP file to the build folder.
    // Note that gzip will produce slightly smaller files than zip.
    "groups": [
        {
           // Unfortunately, looks like there is no way of using a negation operator here
            "path": "./**/*.{$build_file_types}",
            "friendlyName": "Build Folder",
            "compression": "gzip",
            "maxSize": "3 MB",
            "maxPercentIncrease": 25
        }
    ],
    "reportOutput": [
        [
            "github",
            {
                "checkRun": true,
                "commitStatus": true,
                "prComment": true
            }
        ]
    ]
}

BundleMon can be executed locally in the repository via:
yarn bundlemon

If a specific config file needs to be used use the -c,--config option:
yarn bundlemon --config conf_file

This is useful to validate the config without waiting for the action to run.

Docs:

https://github.com/LironEr/bundlemon
https://github.com/LironEr/bundlemon-github-actions
https://github.com/LironEr/bundlemon-action

@nshandra nshandra requested a review from tokland January 14, 2025 14:27
@nshandra nshandra self-assigned this Jan 14, 2025
Copy link

bundlemon bot commented Jan 14, 2025

BundleMon

No change in files bundle size

Groups added (1)
Status Path Size Limits
Build Folder
./**/*
+1.69MB 2.5MB / +20%

Final result: ✅

View report in BundleMon website ➡️


Current branch size history

@nshandra nshandra marked this pull request as ready for review January 14, 2025 15:03
@nshandra nshandra requested a review from adrianq January 14, 2025 15:03
Copy link
Contributor

@tokland tokland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some comments about minor implementation details.

I tested it in skeleton-app (my fork) and it worked nicely, so it also works with vite out of the box: tokland/dhis2-app-skeleton#2

package.json Outdated Show resolved Hide resolved
.bundlemonrc_template Outdated Show resolved Hide resolved
@nshandra nshandra requested a review from tokland January 23, 2025 09:23
Copy link
Contributor

@tokland tokland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good and simple 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants