Skip to content

Latest commit

 

History

History
71 lines (51 loc) · 2.26 KB

README.md

File metadata and controls

71 lines (51 loc) · 2.26 KB

image-deleter

There's only one script in the repo. It marks images (PNG, JPG, JPEG) for deletion using git rm based on whether or not they are referenced anywhere in the repo. There are multiple ways to run this script.

Additional documentation is available on my blog: https://www.stevemar.net/github-actions-rm-images/

Run in a container

There is a containerized version of the script available on Docker Hub. run this command from your project root:

docker run -v `pwd`:/source stevemar/image-deleter:latest

Run as a GitHub Action

The script is also available as a GitHub Action. See this repo as an example. To use it in your repository perform the following:

  1. Create a GitHub Secret with the key name GH_TOKEN and it's value be a GitHub API key.

  2. Create a file in .github/workflows/ and paste the following code:

    on:
      push:
        branches:    
          - master
    
    jobs:
      rm_old_images:
        runs-on: ubuntu-latest
        name: A job to remove images
        steps:
          - name: Checking out our code
            uses: actions/checkout@master
          - name: Remove the images
            uses: stevemar/[email protected]
          - name: Create Pull Request
            uses: peter-evans/create-pull-request@v3
            with:
              token: ${{ secrets.GH_TOKEN }}
              commit-message: Remove unused images
              title: '[Automated PR] Remove unused images'
              body: |
                Found a few images that can be removed
    
                [1]: https://github.com/stevemar/image-deleter
          - name: Check outputs
            run: |
              echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
              echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"

Run locally

Just clone the repo, or copy and paste the code, and run it.

./rm-images.sh

Tips

If you want to re-build this with debug logs, just add this line to the Dockerfile:

ENV DEBUG=true

Re-build it locally and run it.