Coder Social home page Coder Social logo

namoscato / action-tinify Goto Github PK

View Code? Open in Web Editor NEW
31.0 3.0 5.0 2.42 MB

GitHub Action to compress and resize images with the Tinify API

Home Page: https://github.com/marketplace/actions/tinify-image-action

License: MIT License

TypeScript 94.06% JavaScript 0.96% Dockerfile 4.98%
github-actions tinify tinypng tinyjpg compression optimization image

action-tinify's Introduction

ci docker

Tinify Image Action

GitHub Action to compress and resize images with the Tinify API.

Example commit

Features

  • filters PNG, JPEG, and WebP files in a commit or pull request
  • optionally scales images proportionally
  • sets Exif metadata to prevent duplicate compressions
  • pushes commit with compression metrics

Usage

For example, on pull_request events with modified files inside the static directory:

name: Compress Images

on:
  pull_request:
    paths:
      - 'static/**'

jobs:
  compress:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          ref: ${{ github.head_ref }}
      - uses: namoscato/action-tinify@v1
        with:
          api_key: ${{ secrets.TINIFY_API_KEY }}

Events

The following webhook events are supported:

  • pull_request
  • push

Important

In pull request contexts, actions/checkout checkouts a merge commit by default. You must checkout the pull request HEAD commit by overriding the ref input as illustrated above and as noted in their documentation.

Commit Behavior

Events triggered by a default GITHUB_TOKEN commit will not create a new workflow run to prevent accidental recursion.

If you are sure that you want the compression commit to trigger a workflow run, you can configure actions/checkout with a personal access token:

- uses: actions/checkout@v4
  with:
    ref: ${{ github.head_ref }}
    token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}

Inputs

input description
api_key Required Tinify API key (create one here)
github_token Repository GITHUB_TOKEN or personal access token secret; defaults to github.token
commit_user_name Git user.name, defaults to github.actor
commit_user_email Git user.email, defaults to <github.actor>@users.noreply.github.com
commit_message Custom commit message, defaults to Compress image(s)
resize_width Maximum target image width
resize_height Maximum target image height

action-tinify's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar namoscato avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

action-tinify's Issues

Required status checks don't run after the commit containing the compressed images is added to the pull request

Our repo has multiple required status checks that must pass in order for the pull request to be allowed to be merged.

When the commit is created by the Tinify GitHub action containing the compressed image(s), the status checks do not run, and this leaves the pull request in a permanent pending state:
Screenshot 2023-12-05 at 3 56 14 PM

How can this be resolved? Is there a reason the status checks are not running again when the commit with the compressed image(s) is created?

See no yellow circle or green checkmark on the Compress image commit indicating the checks are running or complete:
Screenshot 2023-12-05 at 3 56 03 PM

I've tried several changes to try fix the issue including using a personal access token instead of the repo GITHUB_TOKEN. There are also no filters on the required status checks that would prevent them from running after the commit.

Any solutions or suggestions would be greatly appreciated.

Add support for pull_request updates

Current behavior does not set any image file state; thus, invoking this action on updates to pull requests (i.e. synchronize activity type) could re-compress the same file.

I attempted to mitigate this problem by setting an extended file attribute via fs-xattr throughout #2, but the filesystem within the context of the GitHub Action runner did not seem to support setting these. i.e. see this failed run:

[example-orig.png] Compressing image
##[error]The file system does not support extended attributes or has the feature disabled.
##[debug]Error: The file system does not support extended attributes or has the feature disabled.
##[debug]    at Object.setSync (/usr/app/node_modules/fs-xattr/index.js:66:16)

Support for pull_request_target

This action fails with

Error: Unsupported event pull_request_target (currently supported events include push, pull_request)

name: Process Images

on:
  workflow_dispatch:
  pull_request_target:
    types:
      - opened
      - reopened
      - synchronize
      - ready_for_review
      - unlocked
    branches:
      - main

jobs:
  compress:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          ref: ${{ github.event.pull_request.head.sha }}
      - name: Tinify Image Action
        uses: namoscato/[email protected]
        with:
          api_key: ${{ secrets.TINIFY_API_KEY }}
          github_token: ${{ secrets.GITHUB_TOKEN }}

pull_request_target is a new event type that allows access to the repository secrets (TINIFY_API_KEY) when the pull request is coming from a fork.

Maybe remove the event check all together and allow events like workflow_dispatch as well? GitHub Actions changes frequently.

For more information, see https://github.blog/2020-08-03-github-actions-improvements-for-fork-and-pull-request-workflows/#improvements-for-public-repository-forks

Reference specific Docker tags in action metadata

Not a huge deal, but using a specific (older) version of this action (i.e. uses: namoscato/[email protected]) will just reference the v1 Docker tag which is continuously updated. Ideally the Docker tag in action.yml is updated and synchronized with the git tag.

This will likely require updating the release algorithm, i.e.

  1. build and publish Docker image
  2. bump action.yml's runs.image Docker tag
  3. cut git release

Unfortunately, this might remove the ability to manually cut releases (flexibility that enables grouping PRs, etc)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.