philspaces / image-optimization

GNU General Public License v3.0
3 stars 0 forks source link

Always 0/0 images treated #1

Open Teyk0o opened 1 year ago

Teyk0o commented 1 year ago

Hi Evansnguyen !

I use you actions to my private project but when the action is executed the step with your actionis always 0/0. There is how i use it :

  - name: 🗜️ Compression des images
    uses: evansnguyen/image-optimization@v1.0.0
    with:
      token: ${{ github.token }}
      file: 'assets'
      branch: 'main'
      commit-branch: 'prod'    
      commit-message: 'Github Action: Auto compress images'

Any idea to fix that ?

philspaces commented 1 year ago

@Teyk0o Can you share your folder structure and GH actions log please?

Teyk0o commented 1 year ago

Yeah for sure, on the image all folder outlined in red is the folder where image are. image

And there is my GH Actions log :

Run evansnguyen/image-optimization@v1.0.0
/usr/bin/docker run --name bedb46365bb6131a84c56a948d6b15b8f09f5_bcae6a --label 5bedb4 --workdir /github/workspace --rm -e "INPUT_TOKEN" -e "INPUT_FILE" -e "INPUT_BRANCH" -e "INPUT_COMMIT-BRANCH" -e "INPUT_COMMIT-MESSAGE" -e "INPUT_COMMITTER" -e "INPUT_DRYRUN" -e "HOME" -e "GITHUB_JOB" -e "GITHUB_REF" -e "GITHUB_SHA" -e "GITHUB_REPOSITORY" -e "GITHUB_REPOSITORY_OWNER" -e "GITHUB_REPOSITORY_OWNER_ID" -e "GITHUB_RUN_ID" -e "GITHUB_RUN_NUMBER" -e "GITHUB_RETENTION_DAYS" -e "GITHUB_RUN_ATTEMPT" -e "GITHUB_REPOSITORY_ID" -e "GITHUB_ACTOR_ID" -e "GITHUB_ACTOR" -e "GITHUB_TRIGGERING_ACTOR" -e "GITHUB_WORKFLOW" -e "GITHUB_HEAD_REF" -e "GITHUB_BASE_REF" -e "GITHUB_EVENT_NAME" -e "GITHUB_SERVER_URL" -e "GITHUB_API_URL" -e "GITHUB_GRAPHQL_URL" -e "GITHUB_REF_NAME" -e "GITHUB_REF_PROTECTED" -e "GITHUB_REF_TYPE" -e "GITHUB_WORKFLOW_REF" -e "GITHUB_WORKFLOW_SHA" -e "GITHUB_WORKSPACE" -e "GITHUB_ACTION" -e "GITHUB_EVENT_PATH" -e "GITHUB_ACTION_REPOSITORY" -e "GITHUB_ACTION_REF" -e "GITHUB_PATH" -e "GITHUB_ENV" -e "GITHUB_STEP_SUMMARY" -e "GITHUB_STATE" -e "GITHUB_OUTPUT" -e "RUNNER_OS" -e "RUNNER_ARCH" -e "RUNNER_NAME" -e "RUNNER_ENVIRONMENT" -e "RUNNER_TOOL_CACHE" -e "RUNNER_TEMP" -e "RUNNER_WORKSPACE" -e "ACTIONS_RUNTIME_URL" -e "ACTIONS_RUNTIME_TOKEN" -e "ACTIONS_CACHE_URL" -e GITHUB_ACTIONS=true -e CI=true -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/_temp/_runner_file_commands":"/github/file_commands" -v "/home/runner/work/TruffAdopt/TruffAdopt":"/github/workspace" 5bedb4:6365bb6131a84c56a948d6b15b8f09f5
0/0 ✔ Squoosh results:

Committer REST API ok
Committer account (github-actions)
Using branch prod
Committer head branch status ok
philspaces commented 1 year ago

@Teyk0o

Can you please try replace the toke with this template? It looks like there is no img in assets folder on prod branch

name: Image optimization
on:
  workflow_dispatch:
  pull_request:

jobs:
  my_bot_job:
    runs-on: ubuntu-latest
    steps:
      - uses: evansnguyen/image-optimization@v1.0.0
        with:
          token: ${{ secrets.ACCESS_TOKEN }} // your secret
          file: 'assets' // try empty string to scan entire repo
          branch: 'next-release' // this should be your current branch with assets
          commit-branch: 'awesome/image-optimization'
Teyk0o commented 1 year ago

Ok but can you explain me how i can have my secret for ${{ secrets.ACCESS_TOKEN }} ? Im a beginner with GH Actions.

philspaces commented 1 year ago

Gh secret is where you can define variables, it is encrypted so you can share it with other services. In the example variable name is ACCESS_TOKEN. To get this token you need to generate it follow this guide: https://catalyst.zoho.com/help/tutorials/githubbot/generate-access-token.html Read more: https://docs.github.com/en/actions/security-guides/encrypted-secrets#about-encrypted-secrets

Teyk0o commented 1 year ago

Ok I tried but same problem :

Run evansnguyen/image-optimization@v1.0.0
/usr/bin/docker run --name bedb4d2994f0463ca4c479f1b0bfaa30434f8_735262 --label 5bedb4 --workdir /github/workspace --rm -e "INPUT_TOKEN" -e "INPUT_FILE" -e "INPUT_BRANCH" -e "INPUT_COMMIT-BRANCH" -e "INPUT_COMMIT-MESSAGE" -e "INPUT_COMMITTER" -e "INPUT_DRYRUN" -e "HOME" -e "GITHUB_JOB" -e "GITHUB_REF" -e "GITHUB_SHA" -e "GITHUB_REPOSITORY" -e "GITHUB_REPOSITORY_OWNER" -e "GITHUB_REPOSITORY_OWNER_ID" -e "GITHUB_RUN_ID" -e "GITHUB_RUN_NUMBER" -e "GITHUB_RETENTION_DAYS" -e "GITHUB_RUN_ATTEMPT" -e "GITHUB_REPOSITORY_ID" -e "GITHUB_ACTOR_ID" -e "GITHUB_ACTOR" -e "GITHUB_TRIGGERING_ACTOR" -e "GITHUB_WORKFLOW" -e "GITHUB_HEAD_REF" -e "GITHUB_BASE_REF" -e "GITHUB_EVENT_NAME" -e "GITHUB_SERVER_URL" -e "GITHUB_API_URL" -e "GITHUB_GRAPHQL_URL" -e "GITHUB_REF_NAME" -e "GITHUB_REF_PROTECTED" -e "GITHUB_REF_TYPE" -e "GITHUB_WORKFLOW_REF" -e "GITHUB_WORKFLOW_SHA" -e "GITHUB_WORKSPACE" -e "GITHUB_ACTION" -e "GITHUB_EVENT_PATH" -e "GITHUB_ACTION_REPOSITORY" -e "GITHUB_ACTION_REF" -e "GITHUB_PATH" -e "GITHUB_ENV" -e...
0/0 ✔ Squoosh results:
Committer REST API ok
Committer account Teyk0o
Using branch prod
Committer head branch status ok

The GH Actions :

      - name: 🗜️ Compression des images
        uses: evansnguyen/image-optimization@v1.0.0
        with:
          token: ${{ secrets.ACCESS_TOKEN }}
          file: ''
          branch: 'main'
          commit-branch: 'prod'
philspaces commented 1 year ago

@Teyk0o Sorry, I cannot look into it now. I will get back to you later this week, and give a proper setup

philspaces commented 1 year ago

@Teyk0o

I make a simple repo example, please follow steps how I set up this gh action Example repo: https://github.com/evansnguyen/example-image-gh-action

Generate access token:

Create secret:

Run workflow:

philspaces commented 1 year ago

The result after GH action "Image optimization" ran: image

Then GH action will creates PR: https://github.com/evansnguyen/example-image-gh-action/pull/1

Found 7 images but only 1 image need optimization. The assets example in my repo already optimized, but yours repo should give a better result

philspaces commented 1 year ago

@Teyk0o

I suspect there is a bug in reading nested folder structure, i'm looking into it. Can you try change file: 'assets' to 'assets/img'.

(Edited) Look like Github API limitation, it doesn't allow to download folder. That's why your assets/img folder return 0 results. https://github.com/octokit/octokit.net/issues/1950

Change to use file: 'assets/img'should work for you.

I also recommend work around for nested folder by create multiple actions, each action will optimize 1 folder. (or keep your assets folder structure flat)

philspaces commented 1 year ago

also, feel free to clone this repo, build node project and run, the code should be able to read nested folder without Github limitation.

1 steps: replace run() function image

2 steps: Put your assets in tmp/ folder image

Build and Run:

yarn install
yarn build
node .\build\src\index.js