Open rachmari opened 3 years ago
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?
@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 }}
``
Can confirm happens to me as well. All images in the repo are getting processed.
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}"
@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.
@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?
We having the exact same problem! Any news on this?
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:
image-actions
(without requiring other GH actions)optimiseAllRepositoryImages
(default false))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 ๐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 ๐ข
@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.
Hi @benschwarz , Is there any update on this?
Hi @benschwarz , Is there any update on this?
Nope! I'd post an update if there was one ๐
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
andpush
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.