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 Request] Only optimized changed images #92

Open
rachmari opened this issue Feb 12, 2021 · 12 comments
Open

[Feature Request] Only optimized changed images #92

rachmari opened this issue Feb 12, 2021 · 12 comments
Labels
enhancement New feature or request

Comments

@rachmari
Copy link

Thank you for creating this well-documented action! 🙌

Also, please forgive me if I missed any documentation or settings that would solve what I'm requesting. 😅

What problem would this feature solve?

It looks like this action will optimize all images in the repo that match any selected paths. If that is true, I'd love the ability to be able to only optimize images that are part of the commit that triggered the workflow. This would speed up a potentially long process and target only changed images.

We have a very large directory of images that takes up to 5 hours to compress, but if we know that the existing images are already compressed, it'd be great to only optimize images that are added or updated.

Describe the solution you’d like to see

An input parameter that allows you to select targeting only images that are part of the commit that triggered the workflow. This would likely only be applicable to pull_request and push events.

If the input parameter is set, the action would retrieve the list of changed files and find any image files. If there are changed image files, those images will be compressed.

@rachmari rachmari added the enhancement New feature or request label Feb 12, 2021
@benschwarz
Copy link
Member

Hey @rachmari ! 👋

We have a very large directory of images that takes up to 5 hours to compress

Whoa! That's … a lot 😅

The current image-actions config (found in README) contains:

name: Compress Images
on:
  pull_request:
    # Run Image Actions when JPG, JPEG, PNG or WebP files are added or changed.
    # See https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#onpushpull_requestpaths for reference.
    paths:
      - '**.jpg'
      - '**.jpeg'
      - '**.png'
      - '**.webp'

This config means that the action will only be run when images files have been updated… but what you're asking is slightly different in that you ONLY want to process the files that have been updated, rather than the whole set.

Is that correct?

@rachmari
Copy link
Author

@benschwarz hello! 👋

This config means that the action will only be run when images files have been updated… but what you're asking is slightly different in that you ONLY want to process the files that have been updated, rather than the whole set.

Yep, exactly. I added the workflow below and then added 3 new images to that branch. I expected the workflow to only process those 3 new images, but the log output appeared to be processing all of the .png images in the repo:

name: Compress images
on:
  pull_request:
    paths:
      - '**.png'
jobs:
  build:
    name: calibreapp/image-actions
    runs-on: ubuntu-latest
    # Only run on main repo on and PRs that match the main repo.
    if: github.repository == 'github/docs-internal'
    steps:
      - name: Checkout Branch
        uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f
      - name: Compress Images
        id: calibre
        uses: calibreapp/image-actions@main
        with:
          githubToken: ${{ secrets.GITHUB_TOKEN }} 
``

@Maggi64
Copy link

Maggi64 commented Feb 15, 2021

Can confirm happens to me as well. All images in the repo are getting processed.

@tunetheweb
Copy link
Contributor

Agree this would be useful. And agree currently it does all files each time - that's working as intended at the moment btw, rather than a bug per se, though can understand why it's not what some would want.

BTW I think this should be optional, so can have some runs use this new functionality if/when it's added (maybe "on" by default for all pull request runs?) but still have the option of doing a full run to use the original (slower) full run (e.g. a timed run could be run weekly to compress everything for example in case anything was missed).

Here's how I've got the list of files for another project btw, using bash rather than JavaScript, but might be helpful as a starting off point:

    # If this is part of pull request then get list of files as those changed
    # Uses similar logic to GitHub Super Linter (https://github.com/github/super-linter/blob/master/lib/functions/buildFileList.sh)
    # First checkout main to get list of differences
    git pull --quiet
    git checkout main
    # Then get the changes, for the files needed:
    CHANGED_FILES=$(git diff --name-only "main...${COMMIT_SHA}" --diff-filter=d | egrep -i '\.jpg|\.jpeg|\.png|\.webp'
    # Then back to the pull request branch
    git checkout --progress --force "${COMMIT_SHA}"

@karlhorky
Copy link

karlhorky commented Apr 5, 2021

@bazzadp thanks for the script! Wonder if this could already be used with the paths configuration of the workflow... 🤔

Or, if not, maybe as an extra entry in the job steps below, to abort if there are no image changes in the diff...? That seems plausible...

Ah, and in case the PR has new commits since an optimization commit: ideally the optimization should run only on changes / additions since the last commit of the action.

@karlhorky
Copy link

@benschwarz would you have any input for workarounds in the meantime?

Or suggestions for how and where this should be implemented in the action, in case someone had time to work on a pull request for this?

@FabianKoestring
Copy link

We having the exact same problem! Any news on this?

@benschwarz
Copy link
Member

benschwarz commented Jul 14, 2021

No news from me on this, we're focused in other areas at the moment.

Leaving notes for future me (or someone else) who implements this:

  • It should be built-in to image-actions (without requiring other GH actions)
  • It would become the new default behaviour, with an option to turn it off (maybe optimiseAllRepositoryImages (default false))
  • At the moment, files are sourced using a glob pattern which searches for matching file extensions (.jpg, .png, .webp) within supplied directories. It'll need to compare the git head to the PR and collate a list of changed files. There's a an API method to call for that 👍

@liss-mouse
Copy link

hi! curious - any updates on it? maybe some workarounds at least 🙏
i was pretty much surprised this was reported as a feature request not a bug and still not implemented.. specifying the inclusion list of files instead (or along with) of exclusion sounds like a natural behaviour for any repo a bit larger than a demo 'hello world' one. e.g. we have a monorepo with a lot of projects and despite i like this action a lot it's completely useless in such a setup since it would process infinite number of images every time 😢

@benschwarz
Copy link
Member

@liss-mouse No, there are no updates. I'm sorry you feel that this project isn't useful for anything more than a hello world. I disagree.

While your use case is valid, your feedback isn't overly helpful and wasn't well received. If your requirements are such that the library doesn't work for you, please consider submitting a PR to amend the behavior, or search for an alternative that meets your needs. Thanks.

@paryanihitesh
Copy link

Hi @benschwarz , Is there any update on this?

@benschwarz
Copy link
Member

Hi @benschwarz , Is there any update on this?

Nope! I'd post an update if there was one 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

No branches or pull requests

8 participants