creyD / prettier_action

GitHub action for running prettier on your projects pull requests
MIT License
269 stars 87 forks source link

[FEATURE] Show diff after failure #96

Open jakeboone02 opened 2 years ago

jakeboone02 commented 2 years ago

What would you like to change about the program? I'm running this GHA on my react-querybuilder repository. When I run Prettier on my local machines (yarn pretty-print), it makes no changes. But when I push a commit to PR react-querybuilder/react-querybuilder#370 and it runs the Prettier action (which I assumed was running Prettier with the same options/config), I get the following output:

Run creyD/prettier_action@v4.[2](https://github.com/react-querybuilder/react-querybuilder/actions/runs/3056800420/jobs/4931305676#step:5:2)
  with:
    dry: true
    prettier_options: --check *.js examples/**/* packages/*/src/** packages/*/dev/** website/*.js website/{docs,src,versioned_docs,versioned_sidebars}/**
    prettier_version: 2.7.1
    prettier_plugins: prettier-plugin-organize-imports
    commit_message: Prettified Code!
    same_commit: false
    file_pattern: *
    working_directory: false
    only_changed: false
    github_token: ***
  env:
    npm_config_cache: /home/runner/.npm
    GITHUB_TOKEN: ***
Run PATH=$(cd $GITHUB_ACTION_PATH; npm bin):$PATH /home/runner/work/_actions/creyD/prettier_action/v4.2/entrypoint.sh
Installing prettier...
Checking plugin: prettier-plugin-organize-imports
Prettifying files...
Files:
Checking formatting...
[warn] website/src/components/HomepageFeatures.tsx
[warn] website/src/components/QueryBuilderEmbed.tsx
[warn] website/src/pages/index.tsx
[warn] Code style issues found in [3](https://github.com/react-querybuilder/react-querybuilder/actions/runs/3056800420/jobs/4931305676#step:5:3) files. Forgot to run Prettier?
Problem running prettier with --check *.js examples/**/* packages/*/src/** packages/*/dev/** website/*.js website/{docs,src,versioned_docs,versioned_sidebars}/**
Error: Process completed with exit code 1.

I can see that 3 files were changed, but I don't know what was changed. Is there a good way to run git diff after a failed run of this GHA?

Why do you think this is a cool idea? This may be more of a general GHA question (it's fairly easy to continue to the next step after error) than specific to this action, but it does seem like a useful feature. Maybe a show-changes: true option or something.

Edit: I ended up just running Prettier directly, but I can't figure out what the difference was between that method and running this GHA.

AlecRust commented 1 year ago

Seems this is a feature missing in Prettier itself https://github.com/prettier/prettier/issues/6885

creyD commented 1 year ago

That's actually strange, maybe some config wasn't picked up by the action? @jakeboone02

Anyways I am not aware of a function like this, but maybe we could add something like this? Either a debug variable or maybe we could run this if prettier fails? Problem at the moment would be that we already stop the action as soon as prettier fails.

jakeboone02 commented 1 year ago

Thanks, @creyD. As I mentioned in the issue description, I think something like show-changes: true or debug-mode: true would be useful. Would you want any assistance? Not sure how much I can do but I'll take a look if you want.

creyD commented 1 year ago

@jakeboone02 Thanks for the offer! Always open for PRs or any help, will do my best to respond in a timely manner.