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 / idea: allow to use as a gating action (fail on non-compressed images) #61

Open
ahmadnassri opened this issue Aug 27, 2020 · 3 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@ahmadnassri
Copy link

What:

allow flags to exit as failure if the found images compress at a higher level than the declared threshold, thus indicating that the committed images were not pre-optimized.

Why:

  • large images in git will inflate the total size of the repository and make cloning slow
  • preventing large images from being stored in a git repo at the PR level

How:

  • add an input flag run-as-test (or better wording) which exists with a failure signal if the resulting compression is bigger than the defined quality setting
  • the resulting comment text should also reflect the language of "testing" vs. "results", e.g.
some images did not match the compression requirements:
| Filename        | Variance |
| --------------- | --------- |
| /path/file.jpg  | 20%       |
@benschwarz benschwarz added enhancement New feature or request help wanted Extra attention is needed labels Sep 14, 2020
@benschwarz
Copy link
Member

benschwarz commented Sep 14, 2020

@ahmadnassri, this sounds like a helpful and useful addition, but at the moment a change like this would represent a pretty significant change to image-actions.

We've some ideas for alternative run modes and configurable options, but without some work there, we're a while away from being able to add such a feature.

@tunetheweb
Copy link
Contributor

tunetheweb commented Sep 14, 2020

@benschwarz this could be an alternative way to handle forks, if people didn't want to merge uncompressed images followed by a PR to compress them like I added in #54

In fact you could do this after #54 is released with something like this:

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
    paths:
      - "**.jpg"
      - "**.jpeg"
      - "**.png"
      - "**.webp"
jobs:
  build:
    name: calibreapp/image-actions
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Repo
        uses: actions/checkout@master
      - name: Compress Images
        uses: calibreapp/image-actions@master
        with:
          githubToken: ${{ secrets.GITHUB_TOKEN }}
          compressOnly: true
      - name: Comment on PR if branch contains uncompressed images
        uses: actions/github-script@0.3.0
        if: steps.calibre.outputs.markdown != ""
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          script: |
            const { issue: { number: issue_number }, repo: { owner, repo }  } = context;
            github.issues.createComment({ issue_number, owner, repo, body: 'Warning: Images not compressed.' });

We could also fail the Action in case a comment is missed which is probably better. Imagine this would be fairly easy with one new option (failOnUncompressedImages or something snappier?). Happy to open a PR for this if you like.

@tunetheweb
Copy link
Contributor

Actually, thinking about this some more, you could do this already with the following workflow:

name: Check Images are Compressed
on:
  pull_request:
    # Run image-actions when jpg, jpeg, png or webp files are added or changed
    paths:
      - "**.jpg"
      - "**.jpeg"
      - "**.png"
      - "**.webp"
jobs:
  build:
    name: calibreapp/image-actions
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Repo
        uses: actions/checkout@master
      - name: Compress Images
        uses: calibreapp/image-actions@master
        with:
          githubToken: ${{ secrets.GITHUB_TOKEN }}
          compressOnly: true
      - name: Fail If Uncompressed Images Exist
        if: steps.calibre.outputs.markdown != ""
        run: exit 1

Not so sure it's necessary (or even a good idea) to actually add this to the Calibre code further than this, but probably would want to be able to specify the significantCompressionPercent value as discussed in #34

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

No branches or pull requests

3 participants