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

Add CI workflow to compute diff between files dist files #2269

Merged
merged 1 commit into from
Nov 3, 2024

Conversation

Kocal
Copy link
Member

@Kocal Kocal commented Oct 13, 2024

Q A
Bug fix? no
New feature? no
Issues Fix #...
License MIT

🚨 Before merging, we should drop the commit that modify files (in order to generate the diff table)

This PR is purely internal, and aims to display the assets/dist/*.{js,css} files diff between 2.x and a pull-request. Similar to https://github.com/marketplace/actions/pkg-size-action, but fully internal.

I wanted a tool that display dist files size diff for each pull-request, because I was a bit afraid of changes done in #2160.

When a PR is opened, it check dist files between the base branch (2.x) and the pull request, and it create a GitHub comment. The comment is created by https://github.com/marocchino/sticky-pull-request-comment, and is automatically updated depending of the check state.
If any diff between dist files, then a table is displayed, with a line per file. It shows the original size and compressed (gzip and brotli) sizes, and also a difference in %.

States

Currently not working on this repository, but you can see them on Kocal#1

Capture d’écran 2024-10-13 à 11 45 10 When opening a PR

When an issue happened

Capture d’écran 2024-10-13 à 11 45 19

When there is no difference between base and PR

Capture d’écran 2024-10-13 à 11 25 31

When there is difference between base and PR

image

@Kocal
Copy link
Member Author

Kocal commented Oct 13, 2024

It looks like there are permissions issues, even after added permissions.pull-requests: write like mentioned in the documentation:
image

Even if I use permissions: 'write-all' it does not work either:
image

I suspect a configuration at organization-level...?

@kbond do you think you can do something about that please? 🙏🏻

/cc @nicolas-grekas or maybe you Nicolas since you setup the same action on Symfony recipes repositories :)

Thanks!

@Kocal Kocal force-pushed the ci-size-limit branch 2 times, most recently from e6face5 to 4274e69 Compare October 13, 2024 11:39
@kbond
Copy link
Member

kbond commented Oct 14, 2024

Shouldn't this job only run if a dist file has been changed?

@Kocal
Copy link
Member Author

Kocal commented Oct 14, 2024

Shouldn't this job only run if a dist file has been changed?

Fixed by using the following config:

on:
  pull_request:
    paths:
      - 'src/*/assets/dist/**'
      - 'src/*/src/Bridge/*/assets/dist/**'

I will push soon, thanks

@Kocal Kocal force-pushed the ci-size-limit branch 3 times, most recently from 1e3e78c to 92bdb59 Compare October 14, 2024 21:52
@Kocal Kocal marked this pull request as draft October 14, 2024 21:52
@Kocal Kocal force-pushed the ci-size-limit branch 10 times, most recently from 6d65eb3 to 6acb472 Compare October 15, 2024 07:07
@Kocal
Copy link
Member Author

Kocal commented Oct 15, 2024

I've changed the table rendering after @javiereguiluz's comment, it now looks like this:
image

We still need to find out why there is this Resource not accessible by integration error, and we are good IMO

@javiereguiluz
Copy link
Member

@Kocal I like a lot what you are doing here. Thanks.

Some additional comments ... but I could be wrong, so feel free to ignore them:

  • I'd remove Brotli because it's just "the same as Gzip but a bit better", so it doesn't add any relevant information
  • I'd round percentages and remove decimals to make them easier to understand: -4% is better to me than -3.9% and +74% is better than +74.3%
  • I'd put the percentages first, because it's the most relevant info by far. E.g. I don't care that the new file size is 5.56 KB, I just want to quickly check that it's a -27% file size change.

Thanks!

@Kocal
Copy link
Member Author

Kocal commented Oct 15, 2024

Thanks Javier, the more we speak about Brotli and the more I think we can remove it (btw pkg-size-action can display Brotli sizes). Gzip is the most common compression standard for the moment, while Brotli is — I believe — still a "niche" thing. Brotli users know that their files will be smaller than gzipped files.

I agree for percentage rounding.

When it comes to putting percentages first, I don't really agree with you. Yes, percentage differences are important, but when the browser goes to download a resource, it's the size of the resource that matters, not the percentage difference.
If a file is reduced from 1 MB to 500 KB, we gain 50%, but more importantly we save 500 KB (and that's a really huge gain). If a file is reduced from 10 Kb to 5 Kb, you also gain 50%, but you only save 5KB (which still has an impact, but a much smaller one).
But then, your point of view is valid too and I can understand it, I think here it's two different ways of thinking :)

@Kocal
Copy link
Member Author

Kocal commented Oct 15, 2024

Thanks for your reviews, the diff table now looks like this:
image

@javiereguiluz
Copy link
Member

Looks very nice!! Thanks a lot Hugo.

@Kocal Kocal marked this pull request as ready for review October 15, 2024 15:02
@kbond
Copy link
Member

kbond commented Oct 16, 2024

This looks great!

@Kocal:

  1. Can you revert the temporary commit?
  2. The proper permissions are still todo?

@Kocal
Copy link
Member Author

Kocal commented Oct 16, 2024

@kbond yes there are still permission issues, and I can revert the temporary commit (when permissions will be fixed, otherwise we won't see the comment)

@Kocal Kocal force-pushed the ci-size-limit branch 6 times, most recently from b66b79c to ca30dc5 Compare November 3, 2024 09:15
@Kocal
Copy link
Member Author

Kocal commented Nov 3, 2024

I've reworked the workflow in two dedicated workflows, hoping for permissions issues to be gone.
We won't have comment before the diff is generated, or if a failure happened.

I reverted the commit that modify dist files for testing purposes. I'm merging ASAP

@Kocal Kocal merged commit 137fd2c into symfony:2.x Nov 3, 2024
7 of 8 checks passed
Kocal added a commit to Kocal/symfony-ux that referenced this pull request Nov 3, 2024
Kocal added a commit that referenced this pull request Nov 3, 2024
This PR was merged into the 2.x branch.

Discussion
----------

Minor adjustments after #2269

Looks like minor adjustments were needed to make the comment workflow works as expected.

Commits
-------

93d08d0 Minor adjustments after #2269
@Kocal Kocal force-pushed the ci-size-limit branch 2 times, most recently from 8d34f73 to 0558c79 Compare November 3, 2024 09:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DX Status: Needs Review Needs to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants