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

Image sizing ci #331

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open

Image sizing ci #331

wants to merge 22 commits into from

Conversation

nicolasjeong
Copy link
Contributor

No description provided.

@mattxwang
Copy link
Member

mattxwang commented May 2, 2021

@nicolasjeong is this PR ready to review? I'm not sure if we've hit all the requested items in the ticket yet!

@nicolasjeong
Copy link
Contributor Author

Oh my bad, I thought I had to submit a PR after resolving some of the comments from checkImageSize.js before moving on to fixImageSize.js. (Unless I missed something in checkImageSize.js)

@mattxwang
Copy link
Member

Oh my bad, I thought I had to submit a PR after resolving some of the comments from checkImageSize.js before moving on to fixImageSize.js. (Unless I missed something in checkImageSize.js)

Sure, in that case I can give a light review, but we shouldn't merge this until we also make a working fixImageSize.js action and resolve the issues with the CI.

Copy link
Member

@mattxwang mattxwang left a comment

Choose a reason for hiding this comment

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

Left some comments! Also cc: @vivianha534

Copy link
Contributor

@vivianha534 vivianha534 left a comment

Choose a reason for hiding this comment

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

I'm going to defer to @mattxwang because I'm not very familiar with CI, but I left a couple of comments. Adding whether or not a file is fixable, is more of a nit.

for (const file of finalFilesArray){ //Check the image size of all image files
const imageStatus = imageSizeChecker(file);
if (imageStatus.error){
console.error("Error: " + file + " -- " + imageStatus.message+ "\n");
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice to also let the person know if their error is fixable, so that way they know if they need to manually fix the issue or if they can run fixImageSize to fix it.

else if(isImageWidthLarge(imageSize)){
return errorType.LARGE_IMAGE_ERROR;
}
else if (!isAValidExtension(input)){
Copy link
Contributor

Choose a reason for hiding this comment

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

This if statement would also fail if the file had a non .jpg, .jpeg, or .png extension (ie. it would fail if they had a .svg file) However, the error message for EXTENSION_ERROR only mentions file name not having a lower case extension name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The getAllFiles() function(line 86) deals with this since it returns an array of the file names that have .jpg, jpeg, or .png. Therefore, the array won't contain any file that has a non .jpg, .jpeg, or .png extension. We will run imageSizeChecker to files that only have the .jpg, .jpeg, or .png extension.

@mattxwang mattxwang marked this pull request as draft May 10, 2021 06:19
@vivianha534
Copy link
Contributor

vivianha534 commented May 13, 2021

@reginawang99 @ellieyhcheng I'm not sure why the export/require statements are causing everything in checkImageSize.js to run instead of just the getAllFiles function.

@reginawang3495
Copy link
Contributor

reginawang3495 commented May 13, 2021

Kk I can take a look tonight

@mattxwang
Copy link
Member

Oh I can jump in here if that makes things easier, basically the entire file is being executed on interpretation (afaik how importing works with ESM/node, but I could be wrong)

I would suggest instead to separate concerns:

  • one file should just be a shared library that only exports functions
  • two individual files should just be the main routines (i.e. calling the modules from that file)

Ideally, any file you import shouldn't have any deterministic or side-effect behaviour!

@vivianha534
Copy link
Contributor

@mattxwang Oh ok, so if I'm understanding this correctly, if we had functions that we wanted to use in both checkImageSize.js and fixImageSize.js then we should define the function inside of another file like library.js or something and export the functions in there, and require library.js in checkImageSize.js and fixImageSize.js in order to use the exported functions?

@mattxwang
Copy link
Member

@mattxwang Oh ok, so if I'm understanding this correctly, if we had functions that we wanted to use in both checkImageSize.js and fixImageSize.js then we should define the function inside of another file like library.js or something and export the functions in there, and require library.js in checkImageSize.js and fixImageSize.js in order to use the exported functions?

Yup! I would also say that this is generally best practice! I would put all relevant library files in your lib.js file or similar.

Also, since we're not supporting Node 10, ESM imports/exports are probably the way to go.

Copy link
Member

@mattxwang mattxwang left a comment

Choose a reason for hiding this comment

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

Left some comments! Most of them are nitpicky, though the behaviour around failing fixes is pretty important (I think try-catch and log is probably fine in this instance).

Also, a minor nit is that we're using let very frequently when const would suffice, which helps with "defensive coding"!

I think if you address these comments, we're prob good to go. After you make the changes (tag me again, but I think this is good), you should:

  1. merge master into image-sizing-ci
  2. then, run the fixer
  3. ideally, commit that night

@nicolasjeong nicolasjeong marked this pull request as ready for review May 20, 2021 01:34
Copy link
Member

@mattxwang mattxwang left a comment

Choose a reason for hiding this comment

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

Feel free to pull the trigger on merging + autofixing!

@nicolasjeong
Copy link
Contributor Author

It seems that one of the check still fails? I'm pretty sure it's because of the non-fixable images that have errors.

@mattxwang
Copy link
Member

Just touching back to this, @reginawang99 / @vivianha534 are y'all wrapping up this ticket? Or do you want me to finish it?

@reginawang3495
Copy link
Contributor

reginawang3495 commented May 27, 2021

@vivianha534 i think we can just fix that one fixable image, and just push? and we manually fix/ask people with pictures that are too small for updated pics?

(we can probably manually fix the non-square aspect ratios)

@vivianha534
Copy link
Contributor

@mattxwang @reginawang99 Oh I was planning on manually fixing all of the images before having Nico merge it. I've already been working on fixing the images, and the last couple should be done by tonight/tomorrow latest.

@mattxwang
Copy link
Member

Just curious, what ended up happening with this PR? @vivianha534 @reginawang3495

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.

4 participants