Git Product home page Git Product logo

prettier_action's People

Contributors

adammartincote avatar andya avatar animeallstar avatar anselmoo avatar bercos avatar creyd avatar fschoenfeldt avatar fsz-codeshop avatar hans5958 avatar hpedrorodrigues avatar infotexture avatar insyri avatar j-fields avatar jlhasson avatar jorenbroekema avatar jsoref avatar juanda237 avatar sebkolind avatar seven1m avatar sksat avatar spawnia avatar stemount avatar stephenlacy avatar suda avatar tombarta avatar tropictim avatar wesleyyue 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

prettier_action's Issues

GITHUB_TOKEN: parameter not set in entrypoint.sh

It's missing the GITHUB_TOKEN variable. According to the GitHub Docs this is automatically set in a repository. But somehow I get this error:

index.js 43ms
file2.js 8ms
file3.js 5ms
/entrypoint.sh: 7: /entrypoint.sh: GITHUB_TOKEN: parameter not set
Commiting and pushing changes...
##[error]Docker run failed with exit code 2

Screenshot

Am I missing something?

Commit with github actions bot

Is there an option to commit from the github actions[bot] user.
So not every commit will be from my account?

I will use this settings to commit. But don't know how to set it in you action.

git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'

[BUG] Checkout: Error search process (Using a fork).

What exactly happened?

  1. Go to your fork, or create it from the main repository.

  2. In the fork, create a new branch whose name does not exist in the main repository.
    For example feature_534.

  3. We finish work in our fork in the feature_534 branch, make a commit and make a pull request to the main repository - we get a prettier action error:
    /usr/bin/git -c protocol.version=2 fetch --no-tags --prune --progress --no-recurse-submodules --depth=1 origin +refs/heads/feature_534*:refs/remotes/origin/feature_534* +refs/tags/feature_534*:refs/tags/feature_534*
    The process '/usr/bin/git' - failed with exit code 1

  4. We don't get an error if we use the branch name in our fork, which is in the main repository.
    for example:
    the main repository exists: feature_123.
    In the fork we create feature_123 branch and do pull request in main repo - Prettier work done.

What should've happened?
The pretter action should work correctly, provided that the pull request is made from an external fork and a branch that does not exist in the main repository.

How did it look?
изображение

  • OS: [iOS, Win10, Linux]
  • Repo: [https://github.com/imega-webrx/frontend]
  • Version [v.3.3]

[BUG] Other GitHub actions freeze if prettier job adds new commit

What exactly happened?
If prettier job successfully runs and adds commit with lint changes, other GitHub actions freeze and do not complete.

Steps to reproduce the behavior:

  1. Add (malformatted) staged files and submit commit
  2. Prettier job adds edited commit message
  3. GitHub action checks pause forever.

What should've happened?
Job should have successfully run and other GitHub actions should not have halted.

No parser and no file path given, couldn't infer a parser

Getting this error when running a CI job:

> Run creyD/[email protected]
/usr/bin/docker run --name ee6b...a3f0f --label 671ee6 --workdir /github/workspace --rm -e INPUT_COMMIT_MESSAGE -e INPUT_COMMIT_OPTIONS -e INPUT_FILE_PATTERN -e INPUT_PRETTIER_OPTIONS -e INPUT_BRANCH -e HOME -e GITHUB_REF -e GITHUB_SHA -e GITHUB_REPOSITORY -e GITHUB_ACTOR -e GITHUB_WORKFLOW -e GITHUB_HEAD_REF -e GITHUB_BASE_REF -e GITHUB_EVENT_NAME -e GITHUB_WORKSPACE -e GITHUB_ACTION -e GITHUB_EVENT_PATH -e RUNNER_OS -e RUNNER_TOOL_CACHE -e RUNNER_TEMP -e RUNNER_WORKSPACE -e ACTIONS_RUNTIME_URL -e ACTIONS_RUNTIME_TOKEN -e GITHUB_ACTIONS=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/queue/queue":"/github/workspace" 671ee6:b142...ead3  "Prettified Code!" "" "*" "" ""
Installing dependencies...
npm WARN saveError ENOENT: no such file or directory, open '/github/workspace/package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open '/github/workspace/package.json'
npm WARN workspace No description
npm WARN workspace No repository field.
npm WARN workspace No README data
npm WARN workspace No license field.

up to date in 0.561s
found 0 vulnerabilities

/usr/local/bin/prettier -> /usr/local/lib/node_modules/prettier/bin-prettier.js
+ [email protected]
added 1 package from 1 contributor in 0.404s
Prettifing files...
[error] No parser and no file path given, couldn't infer a parser.
##[error]Docker run failed with exit code 2

In the config I just use the defaults:

    steps:
      - name: Prettier Action
        uses: creyD/[email protected]

[BUG] Unexpected input(s) 'prettier_plugins' or Syntax Error

What exactly happened?
Steps to reproduce the behavior:

  1. Create a yml following the ReadMe
  2. Add prettier_plugins like the below
  3. Get warning/error below
Warning: Unexpected input(s) 'prettier_plugins', valid inputs are ['entryPoint', 'args', 'commit_message', 'same_commit', 'commit_options', 'file_pattern', 'prettier_options', 'dry', 'prettier_version', 'only_changed']
name: Continuous Integration

# This action works with pull requests
on:
  pull_request:
    branches:
    - main

jobs:
  prettier:
    runs-on: ubuntu-latest

    steps:
    - name: Checkout
      uses: actions/checkout@v2
      with:
        # Make sure the actual branch is checked out when running on pull requests
        ref: ${{ github.head_ref }}

    - name: Prettify code
      uses: creyD/[email protected]
      with:
        # This part is also where you can pass other options, for example:
        prettier_plugins: "@prettier/plugin-php"
        prettier_options: --write **/*.{php,css,js,md}
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

What should've happened?
No error. Would like to use the official prettier/prettier-php plugin.

How did it look?
image

Where did you encounter the problem?
Using Github Actions

Additional info
I understand that I should not encapsulate it in quotes, but I get another error below.
image

[FEATURE] Extended commit description

What would you like to change about the program?
As users can do in the shell, I would like to suggest an optional commit-description option:

# The equivalent of:
git commit -m "$INPUT_COMMIT_MESSAGE" -m "$INPUT_COMMIT_DESCRIPTION"

Why do you think this is a cool idea?
It feels as it is being bottlenecked with what you can do, or a simple thing that should be implemented already. (no pressure, lol.)

package-lock.json getting deleted

I'm noticing that this prettier action is deleting my package-lock.json file. (Note that runny prettier via npx doesn't do this)

My action.yml

name: Do Prettier
on: [push]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Prettify code
        uses: creyD/[email protected]
        with:
          prettier_options: --write .

my .prettierrc.json

{
  "singleQuote": true,
  "printWidth": 120
}

my .prettierignore

package-lock.json
*.html
*.min.js

Example commit where package-lock.json gets removed

[FEATURE] Dry run/ Only Show Files

What would you like to change about the program?
2 of the forked projects have implemented a system where they just check the compliance and dont automatically apply it. Let's build this here.

[BUG] Deleting a file when only_changed is enabled results in error

What exactly happened?
Steps to reproduce the behavior:

  1. Configure to prettify on push with only_changed: true
  2. Delete a file that would normally be prettified
  3. Commit & push
  4. See error: fatal: pathspec 'deletedFile.js' did not match any files

What should've happened?
Deleted files should be excluded from prettification

This should be fixable by passing --diff-filter=d to git diff

Ignore minified files

How can I ignore minified files? For example, I don't need to format *.min.js and *.min.css files.
Can I add multiple patterns? like this:

prettier_options: --write " **/*.js, **/*.!(min.js) " # Obviously not work

Or

prettier_options: --write **/*{!(.min.)css,!(.min.)js} # Not work too

We can do this by a simple .prettierignore file but is there any way to ignore these files in command? I have no idea about that

Allow to work on pull_request and master branch

Not sure if this is possible, but it would be nice to have only one step instead of these two:

- name: Prettier Action on PR
  if: github.event_name == 'pull_request'
  uses: creyD/[email protected]
  with:
    prettier_options: "--write {**/*,*}.{js,html,json,md,yml,css,scss}"
    branch: ${{ github.head_ref }}
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Prettier Action on master
  if: github.event_name == 'push' && github.ref == 'refs/heads/master'
  uses: creyD/[email protected]
  with:
    prettier_options: "--write {**/*,*}.{js,html,json,md,yml,css,scss}"
    branch: master
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Somehow it would be nice to not have to specify a branch. That is automatically would know if it's a PR or if it's just a push. If it's not available in your app than we could do something like this:

- name: Prettier Action
  uses: creyD/[email protected]
  with:
    prettier_options: "--write {**/*,*}.{js,html,json,md,yml,css,scss}"
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    event_name: ${{ github.event_name }}
    ref: ${{ github.ref }}

getting error while using prettier action

I have used below code in prettier.yml

name: Prettier

# This action works with pull requests and pushes
on:
  pull_request:
  push:
    branches:
      - master

jobs:
  prettier:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          # Make sure the actual branch is checked out when running on pull requests
          ref: ${{ github.head_ref }}

      - name: Prettify code
        uses: creyD/[email protected]
        with:
          # This part is also where you can pass other options, for example:
          prettier_options: --write **/*.{css,html,js,md}

'Error' reporting

What would you like to change about the program?
The following are currently reported as 'errors'

[error] No parser could be inferred for file: frontend/Dockerfile
[error] No parser could be inferred for file: frontend/Makefile
[error] No parser could be inferred for file: frontend/yarn.lock

Suggestion
It is disconcerting that these flag up red and are reported as an error, when it is expected behaviour. Wondering if this is neccesary.

Great action, thanks anyway.

You are not currently on a branch error on pull request push

With this config:

- name: Prettier Action on PR
  if: github.event_name == 'pull_request'
  uses: creyD/[email protected]
  with:
    prettier_version: ^2.0.5
    prettier_options: "--write {,!(static|.github)/**/}*.{js,html,json,md,yml,css,scss} static/js/**/*.js"
    commit_message: "Run prettier via GitHub Action"
    branch: ${{ github.head_ref }}
    file_pattern: "."
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

I get this error:

 file1.js 3ms
file2.js 42ms
Commiting and pushing changes...
[detached HEAD e646b5b] Run prettier via GitHub Action
 Author: *** <***>
 2 files changed, 108 insertions(+), 115 deletions(-)
fatal: You are not currently on a branch.
To push the history leading to the current (detached HEAD)
state now, use

    git push origin HEAD:<name-of-remote-branch>

I solved the issue by running prettier on my machine before pushing, but it should work of course.

Can you see what I'm doing wrong here?

[BUG] How to run only in a specific directory of a project?

What exactly happened?
I used the action like this:

      - name: prettier check
        uses: creyD/[email protected]
        with:
          dry: true
          prettier_version: ${{ env.PRETTIER_VERSION }}
          prettier_options: --no-editorconfig --check src/ internals/
          working_directory: subdir/

This didn't work and I get:

/home/ubuntu/actions-runner/_work/_actions/creyD/prettier_action/v4.2/entrypoint.sh: line 44: cd: subdir/: No such file or directory

I thought maybe I need to provide the workspace, tried with:

          working_directory: ${{ github.workspace }}/subdir/

But that gave only:

Installing prettier...
Error: Process completed with exit code 1.

No further details 🤷🏼

I then had to resorted to this:

      - name: prettier check
        uses: creyD/[email protected]
        with:
          dry: true
          prettier_version: ${{ env.PRETTIER_VERSION }}
          prettier_options: --no-editorconfig --check --ignore-path subdir/.prettierignore subdir/src/ subdir/internals/

I'd have hoped that using a working_directory it would auto-pick up the .prettierignore from there etc.

But at this point, I've no idea how working_directory works and have the impression it's used for something else.

Is it possible to install prettier and point it to a specific directory and "work from there"?

thank you 🙏🏼

Add support to override the token used to push the changes

First of all, thanks for this project. 🚀

Problem
I'm using this action in a specific project for every Pull Request, but after it pushes the changes back to the PR, I expect this push to trigger another action. However, this seems to not work.

Why
This occurs because pushes using the default environment variable GITHUB_TOKEN don't trigger a new workflow, even when configured. So as pointed in this discussion a possible solution is to create a personal token.

What I've tried
Following this idea, I've created a personal token, but as this action has no option to override the token yet, I tried to override the default env var GITHUB_TOKEN.

env:
  GITHUB_TOKEN: ${{ secrets.PERSONAL_GITHUB_TOKEN }}

However, as the docs says, if we attempt to override the value of one of the default environment variables, the assignment is ignored.

What would you like to change about the program?
I'd like to have an option to override the token used to push the changes.
It could be a new environment variable or a new parameter to the action.

Why do you think this is a cool idea?
With this change, we'll be able to trigger another workflow after the fixes have been pushed.

Idk if I'm missing something here, so please let me know.

If you think this feature makes sense, I can start working on the PR.

[BUG] Can't commit to a repo that uses git LFS

Using v3.1 on ubuntu-latest. The repo uses git LFS (though not for any files processed by prettier).
Fails to commit any changes with the error "This repository is configured for Git LFS but 'git-lfs' was not found on your path." It looks like git-lfs is not installed in the docker container, although it is on the outer GHA VM.

Probably the fix is just to add git-lfs to the apk install line.

[BUG] 4.2 fails with no such file or directory

What exactly happened?
Steps to reproduce the behavior:

 - name: Run prettier on changed files
   uses: creyD/[email protected]
        with:
          only_changed: True
          dry: True
          prettier_options: --config ./api/.prettierrc --ignore-path ./api/.prettierignore --check ./api/src/**

What should've happened?

It should have succeeded or failed with a clear error message.
How did it look?

Run PATH=$(cd $GITHUB_ACTION_PATH; npm bin):$PATH /home/github/action-runner/_work/_actions/creyD/prettier_action/v4.2/entrypoint.sh
  PATH=$(cd $GITHUB_ACTION_PATH; npm bin):$PATH /home/github/action-runner/_work/_actions/creyD/prettier_action/v4.2/entrypoint.sh
  shell: bash --noprofile --norc -e -o pipefail {0}
  env:
    INPUT_COMMIT_MESSAGE: Prettified Code!
    INPUT_COMMIT_DESCRIPTION: 
    INPUT_SAME_COMMIT: false
    INPUT_COMMIT_OPTIONS: 
    INPUT_FILE_PATTERN: *
    INPUT_PRETTIER_OPTIONS: --config ./api/.prettierrc --ignore-path ./api/.prettierignore --check ./api/src/**
    INPUT_DRY: true
    INPUT_PRETTIER_VERSION: false
    INPUT_ONLY_CHANGED: true
    INPUT_PRETTIER_PLUGINS: 
    INPUT_WORKING_DIRECTORY: false
    INPUT_GITHUB_TOKEN: ***
npm info it worked if it ends with ok
npm info using [email protected]
npm info using [email protected]
npm timing npm Completed in 48ms
npm info ok 
/__w/_temp/cda1fe4d-556f-48b7-b555-744d14a51b4d.sh: line 1: /home/github/action-runner/_work/_actions/creyD/prettier_action/v4.2/entrypoint.sh: No such file or directory
Error: Process completed with exit code 127.

Where did you encounter the problem?

  • Version: 4.2

[DOCS] Improve documentation

What would you like to change about the program?
I believe the documentation needs updating or improving as I tried to use the options below and always got the message that they were unknown options?

Providing some examples of how you're meant to use these options would help. Also showing an action that uses more than one option at a time would show how to chain them in case you have to do something different.

How are you meant to use the options like --dry and --only_changed?

[warn] Ignored unknown option --dry=true.
[warn] Ignored unknown option --only_changed=true. 
[warn] Ignored unknown option --dry.
[warn] Ignored unknown option --only_changed.

Have tried both of these and always complained about unknown options.

Why do you think this is a cool idea?
The documentation needs to be more clear on the examples and how you're meant to use them. Also, I believe there is something that is required but is not mentioned as required.

Error: No parser and no file path given, couldn't infer a parser.

I get this error but no idea how to fix or what I'm missing.

Happy to update the readme file if I have the correct information!

Third example

Maybe a third example usage scenario can be included where you want to use Prettier as a CI pass/fail check rather than something that mangles commits (i.e. not using --write).

[BUG] Community plugin not recognized as valid

Hello,

First let me just say thank you for being such an active maintainer. This project looks amazing.

I'm trying to set this action up in a repository that hosts a Salesforce project. I'm trying to install prettier-plugin-apex, which is listed under the community plugins section of the official Prettier documentation.
However, the action doesn't seem to recognize this plugin as valid:

Screen Shot 2021-12-07 at 10 39 31 AM

It looks like entrypoint.sh is looking for the plugin string to contain @prettier/... although plugins named prettier-plugin-... are also valid according to Prettier's docs. Is this possible to do via this action or is it unable to install unofficial pugins?

Here is my full action for reference:

name: Prettify Code

on: [pull_request]

jobs:
  prettier:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout Repository
        uses: actions/checkout@v2
        with:
          # Incremental diffs require fetch depth to be at 0 to grab the target branch
          fetch-depth: "0"

      - name: Prettify Modified Code
        uses: creyD/[email protected]
        with:
          same_commit: true
          only_changed: true
          prettier_plugins: prettier-plugin-apex
          prettier_options: --write --config .prettierrc {html, cls, trigger, apex, cmp, page, component}

[FEATURE] Allow unofficial plugins to be installed

There are many Prettier plugins that are not official (yet), like prettier-plugin-svelte. Unfortunately, trying to install it fails with:

Checking plugin: prettier-plugin-svelte
prettier-plugin-svelte does not seem to be a valid @prettier/plugin-x plugin. Exiting.

It would be great if other plugins could be installed as well :)

[FEATURE] modify files without pushing

What would you like to change about the program?
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

I would like to be able to modify files without pushing

Why do you think this is a cool idea?
A clear and concise description of why your feature would improve the program.

for people who already have a commit and push process as part of their action, it is unnecessary to have to push twice.

[BUG] entrypoint.sh: line 123: syntax error near unexpected token `then'

What exactly happened?
Workflow with Prettier failing:
https://github.com/lambda-science/EHRoes/runs/4475783348?check_suite_focus=true

name: Format Check
on: [push, pull_request]
jobs:
  format:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          # Make sure the actual branch is checked out when running on pull requests
          ref: ${{ github.head_ref }}
          # This is important to fetch the changes to the previous commit
          fetch-depth: 0

      - name: Check files using the black formatter
        uses: rickstaa/action-black@v1
        id: action_black
        with:
          black_args: ". --check"

      - name: Prettify code
        uses: creyD/[email protected]
        with:
          prettier_options: --check **/*.{css,js}
          only_changed: True

What should've happened?
Should pass as there is not error.

Where did you encounter the problem?

[BUG] Permission denied in /entrypoint.sh: line 40

Not sure why this is happening, but if I use v1.0 this does not happen:

Run creyD/[email protected]
  with:
    prettier_options: --write {**/*,*}.{js,html,json,md,yml,css,scss} !.github/workflows/**/* !static/**/*
    commit_message: Run prettier via GitHub Action
    branch: fix-twitter-hostname
    file_pattern: .
    dry: false
  env:
    GITHUB_TOKEN: ***
/usr/bin/docker run --name *** --label d00b33 --workdir /github/workspace --rm -e GITHUB_TOKEN -e INPUT_PRETTIER_OPTIONS -e INPUT_COMMIT_MESSAGE -e INPUT_BRANCH -e INPUT_FILE_PATTERN -e INPUT_COMMIT_OPTIONS -e INPUT_DRY -e INPUT_PRETTIER_VERSION -e HOME -e GITHUB_JOB -e GITHUB_REF -e GITHUB_SHA -e GITHUB_REPOSITORY -e GITHUB_RUN_ID -e GITHUB_RUN_NUMBER -e GITHUB_ACTOR -e GITHUB_WORKFLOW -e GITHUB_HEAD_REF -e GITHUB_BASE_REF -e GITHUB_EVENT_NAME -e GITHUB_WORKSPACE -e GITHUB_ACTION -e GITHUB_EVENT_PATH -e RUNNER_OS -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/queue/queue":"/github/workspace" ***:***
/entrypoint.sh: line 40: : Permission denied
Installing prettier...
/usr/local/bin/prettier -> /usr/local/lib/node_modules/prettier/bin-prettier.js
+ [email protected]
added 1 package from 1 contributor in 0.546s
Prettifing files...
Files:
file1.js 50ms
file2.js 13ms
Nothing to commit. Exiting.

[FEATURE] Specify prettier version

What would you like to change about the program?
A way to specify the prettier version number.

Why do you think this is a cool idea?
Some node versions don't support prettier v2.x.x. I'd like to use this action with prettier v1.19.1

[BUG] Checking all files when using `only_changed` and `dry`

Hi! Thank you for maintaining this action :-)
I'm unfortunaltely experiencing what I believe is unexpected behaviour when using the config below.

What exactly happened?
Fails even though all files in changed in the latest commit are formatted properly.

Steps to reproduce the behavior:

  1. add code to a file, and format it according to the .prettierrc
  2. use the following github job:
jobs:
  prettier:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          ref: ${{ github.head_ref }}
          fetch-depth: 0
      - name: Prettify code
        uses: creyD/[email protected]
        with:
          dry: True
          only_changed: True
          prettier_options: --write **/*.{ts,js} --config ./.prettierrc
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

What should've happened?
I expected the job to pass. Other files in the repository are
not properly formatted, but I expected those to be ignored due to only_changed: True.

I'm using v3.3.

[BUG] syntax error near unexpected token `then'

I'm getting the following error when running with a standard prettier configuration

/home/runner/work/_actions/creyD/prettier_action/v4.1/entrypoint.sh: line 123: syntax error near unexpected token `then'
Error: Process completed with exit code 2.

Looks like the line was changed in commit dbdc557 any chance you can spot the error. It looks fine for me

Using the following .yml file:

name: Continuous Integration

on:
  pull_request:
    branches: [master]

jobs:
  prettier:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          # Make sure the actual branch is checked out when running on pull requests
          ref: ${{ github.head_ref }}
          # This is important to fetch the changes to the previous commit
          fetch-depth: 0

      - name: Prettify code
        uses: creyD/[email protected]
        with:
          prettier_version: '2.3.2'
          # This part is also where you can pass other options, for example:
          prettier_options: --write --config .prettierrc **/*.{js,jsx,less,ts,tsx}
          only_changed: True

[BUG] Cannot find module '@trivago/prettier-plugin-sort-imports'

What exactly happened?
Steps to reproduce the behavior:

Due to an incompatibility between 2 prettier plugins (@trivago/prettier-plugin-sort-imports and prettier-plugin-tailwindcss), I'm using a workaround as described here. This requires me to use a prettier.config.js instead of a .prettierrc with contents below:

const pluginSortImports = require('@trivago/prettier-plugin-sort-imports')
const pluginTailwindcss = require('prettier-plugin-tailwindcss')

/** @type {import("prettier").Parser}  */
const myParser = {
  ...pluginSortImports.parsers.typescript,
  parse: pluginTailwindcss.parsers.typescript.parse,
}

/** @type {import("prettier").Plugin}  */
const myPlugin = {
  parsers: {
    typescript: myParser,
  },
}

module.exports = {
  plugins: [myPlugin],
  endOfLine: 'auto',
  singleQuote: true,
  semi: false,
  importOrder: [
    '^(.*).css',
    '<THIRD_PARTY_MODULES>',
    '^@/components/(.*)$',
    '^@/constants/(.*)$',
    '^@/context/(.*)$',
    '^@/lib/(.*)$',
    '^[./]',
  ],
  importOrderSeparation: true,
  importOrderSortSpecifiers: true,
}

Here is my workflow config:

name: Lint
on:
  pull_request:
  push:
    branches:
      - main

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Prettify code
        uses: creyD/[email protected]
        with:
          prettier_options: --check src
          prettier_plugins: '@trivago/prettier-plugin-sort-imports prettier-plugin-tailwindcss'

The output complains that it can't find the @trivago/prettier-plugin-sort-imports plugin:

2022-08-13T17:30:51.7371612Z ##[group]Run creyD/[email protected]
2022-08-13T17:30:51.7371947Z with:
2022-08-13T17:30:51.7372289Z   prettier_options: --check src
2022-08-13T17:30:51.7372811Z   prettier_plugins: @trivago/prettier-plugin-sort-imports prettier-plugin-tailwindcss
2022-08-13T17:30:51.7373340Z   commit_message: Prettified Code!
2022-08-13T17:30:51.7373697Z   same_commit: false
2022-08-13T17:30:51.7374088Z   file_pattern: *
2022-08-13T17:30:51.7374348Z   dry: false
2022-08-13T17:30:51.7374688Z   prettier_version: false
2022-08-13T17:30:51.7375090Z   working_directory: false
2022-08-13T17:30:51.7375379Z   only_changed: false
2022-08-13T17:30:51.7376003Z   github_token: ***
2022-08-13T17:30:51.7376332Z ##[endgroup]
2022-08-13T17:30:51.7740634Z ##[group]Run PATH=$(cd $GITHUB_ACTION_PATH; npm bin):$PATH /home/runner/work/_actions/creyD/prettier_action/v4.2/entrypoint.sh
2022-08-13T17:30:51.7741594Z �[36;1mPATH=$(cd $GITHUB_ACTION_PATH; npm bin):$PATH /home/runner/work/_actions/creyD/prettier_action/v4.2/entrypoint.sh�[0m
2022-08-13T17:30:51.7809219Z shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
2022-08-13T17:30:51.7809646Z env:
2022-08-13T17:30:51.7810121Z   INPUT_COMMIT_MESSAGE: Prettified Code!
2022-08-13T17:30:51.7810518Z   INPUT_COMMIT_DESCRIPTION: 
2022-08-13T17:30:51.7810895Z   INPUT_SAME_COMMIT: false
2022-08-13T17:30:51.7811284Z   INPUT_COMMIT_OPTIONS: 
2022-08-13T17:30:51.7811678Z   INPUT_FILE_PATTERN: *
2022-08-13T17:30:51.7811997Z   INPUT_PRETTIER_OPTIONS: --check src
2022-08-13T17:30:51.7812361Z   INPUT_DRY: false
2022-08-13T17:30:51.7812735Z   INPUT_PRETTIER_VERSION: false
2022-08-13T17:30:51.7813046Z   INPUT_ONLY_CHANGED: false
2022-08-13T17:30:51.7813606Z   INPUT_PRETTIER_PLUGINS: @trivago/prettier-plugin-sort-imports prettier-plugin-tailwindcss
2022-08-13T17:30:51.7814152Z   INPUT_WORKING_DIRECTORY: false
2022-08-13T17:30:51.7814801Z   INPUT_GITHUB_TOKEN: ***
2022-08-13T17:30:51.7815105Z ##[endgroup]
2022-08-13T17:30:52.5591973Z Installing prettier...
2022-08-13T17:30:53.5976437Z Checking plugin: @trivago/prettier-plugin-sort-imports
2022-08-13T17:30:53.5999005Z Checking plugin: prettier-plugin-tailwindcss
2022-08-13T17:30:57.4439033Z Prettifying files...
2022-08-13T17:30:57.4439804Z Files:
2022-08-13T17:30:58.5565091Z Checking formatting...
2022-08-13T17:30:58.6039900Z [error] Invalid configuration file `src/App.css`: Cannot find module '@trivago/prettier-plugin-sort-imports'
2022-08-13T17:30:58.6040619Z [error] Require stack:
2022-08-13T17:30:58.6041633Z [error] - /home/runner/work/react-wordle/react-wordle/prettier.config.js
2022-08-13T17:30:58.6044618Z [error] - /home/runner/work/_actions/creyD/prettier_action/v4.2/node_modules/prettier/third-party.js
2022-08-13T17:30:58.6045469Z [error] - /home/runner/work/_actions/creyD/prettier_action/v4.2/node_modules/prettier/index.js
2022-08-13T17:30:58.6046266Z [error] - /home/runner/work/_actions/creyD/prettier_action/v4.2/node_modules/prettier/cli.js
2022-08-13T17:30:58.6047097Z [error] - /home/runner/work/_actions/creyD/prettier_action/v4.2/node_modules/prettier/bin-prettier.js
2022-08-13T17:30:58.6141363Z Problem running prettier with --check src
2022-08-13T17:30:58.6171610Z ##[error]Process completed with exit code 1.

What should've happened?
I expect the plugin files to be found and executed properly.

How did it look?
image

Where did you encounter the problem?
https://github.com/cwackerfuss/react-wordle/runs/7820780587?check_suite_focus=true

[BUG] Can't use custom config

What exactly happened?
Steps to reproduce the behavior:

  1. Run the action with prettier_options: --config ./.prettier.json --write **/*.js
  2. See error

What should've happened?
It should have used the file that's there but instead I got

Error:  Invalid configuration file `events/error.js`: ENOENT: no such file or directory, open '/github/workspace/.prettier.json'

[FEATURE] a working-directory option?

What would you like to change about the program?

We have a monorepo with multiple npm packages, and run git actions on each one depending on whether or not files were changed in said package.

We have to specify the directory 3 times in the prettier options.
I think this could be simplified by being able to provide a working-directory option that chooses where prettier gets CD'd to before running it in CI, then we wouldn't have to specify the config file either.
Why do you think this is a cool idea?

It would conslidate the commandline
from:

      - name: Frontend Prettier
        uses: creyD/[email protected]
        with:
          dry: true
          prettier_options: "--config redacted/redacted/readacted/redacted/app/.prettierrc --ignore-path redacted/redacted/readacted/redacted/app/.prettierignore  --write redacted/redacted/readacted/redacted/app/**/*.{json,md,scss,yaml,yml,js,jsx,tsx,ts}"

to:

      - name: Frontend Prettier
        uses: creyD/[email protected]
        with:
          dry: true
          working-directory: "redacted/redacted/readacted/redacted/app/"
          prettier_options: "--write **/*.{json,md,scss,yaml,yml,js,jsx,tsx,ts}"

[BUG] When doing dry run it still marks the job as DONE (green blob) even if there are ugly files in the repo

# This is a basic workflow to help you get started with Actions

name: CI

# Controls when the action will run. 
on:
  # Triggers the workflow on push or pull request events but only for the master branch
  pull_request:
    branches: [ staging ]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  prettier:
    runs-on: ubuntu-latest

    steps:
    - name: Checkout
      uses: actions/checkout@v2
      with:
        # Make sure the actual branch is checked out when running on pull requests
        ref: ${{ github.head_ref }}

    - name: Check code style
      uses: creyD/[email protected]
      with:
        # This part is also where you can pass other options, for example:
        dry: true
        prettier_options: "-c src/**/*.{ts,vue}"
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

despite warnings being printed the job doesn't fail

Prettier action is not failing on ugly files.

I have this action config

name: Tests
on:
  push:
    branches: [master]
  pull_request:
    branches: [master]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          ref: ${{ github.head_ref }}

      - name: Prettier check
        uses: creyD/[email protected]
        with:
          dry: true
          prettier_options: --check **/*.ts

      - name: Use deno
        uses: denolib/setup-deno@v2
        with:
          deno-version: v1.x

      - name: Run tests
        run: deno test

I am running a check on typescript files.

Here is the .prettierrc

{
  "semi": false,
  "trailingComma": "all",
  "singleQuote": true,
  "printWidth": 70,
  "arrowParens": "always",
  "bracketSpacing": true
}

What exactly happened?
The action passed without fail, only showing warnings.
This is the output

Installing prettier...
/entrypoint.sh: line 40: : Permission denied
/usr/local/bin/prettier -> /usr/local/lib/node_modules/prettier/bin-prettier.js
+ [email protected]
added 1 package from 1 contributor in 0.765s
Prettifing files...
Files:
Checking formatting...
[warn] specs/when.test.ts
[warn] specs/whereAll.test.ts
[warn] specs/whereAny.test.ts
[warn] specs/zipWith.test.ts
[warn] Code style issues found in the above file(s). Forgot to run Prettier?
Problem running prettier with --check **/*.ts
Nothing to commit. Exiting.

What should've happened?
It should have failed the check and so the action.

Here is the link for the run

[BUG] Prettier exits with code 1 in dry run when all files are already formatted.

What exactly happened?
Prettier exited with code 1 resulting in a failed step even when it found all files formatted correctly.

What should've happened?
Prettier should exit with code 0 (no error)

How did it look?
If applicable, add screenshots to help explain your problem.

Where did you encounter the problem?

  • OS: ubuntu-latest
  • Action Version - v4.0

The repo is private and it was running on a fork but all permissions were given, even write permissions which wouldn't be required IMO.

Screenshots
Error:
image

The configurations:
Action:
image

Prettierrc:
image

[FEATURE] Use repo prettier configuration.

What would you like to change about the program?
I would like to be able to use the repo prettier configuration, instead of putting it into the action configuration, if it is already possible, how can I do it?

Why do you think this is a cool idea?
Automate more the usage of this action.

[FEATURE] Option to install Prettier plugins

I'd like to use this action on repos that include XML files, and format them with @prettier/plugin-xml.

When I run the action as is, I get errors in the log:

[warn] Ignored unknown option { xmlWhitespaceSensitivity: "strict" }. Did you mean htmlWhitespaceSensitivity?
Error:  No parser could be inferred for file: index.dita

This works fine when I run Prettier locally, as these options are provided by plugin-xml.

Suggestion

💡 Add an option to that would allow users to specify the names of Prettier plugins to install.

I realize it would be possible to fork this action and hard-code additional plugins into the # PROGRAM section where Prettier itself is installed, but it seems like something that others might want to do too, so it might be best to support this here with an option instead.

[BUG]: Prettier refuses to commit

What exactly happened?
I executed Prettier with workflow_dispatch but it always failed while committing. It says that it can't commit since it's blocked.
Steps to reproduce the behavior:

  1. Go to my new blog repo's actions page here.
  2. Click on the Prettier PR workflow(need to change this to Prettier, so click whatever has Prettier in it).
  3. See all latest runs
  4. See error in logs

What should've happened?
Prettier should've committed the changes flawlessly, like on the repo PRs.

How did it look?
This line:
https://github.com/im-coder-lg/docusaurus-blog/runs/4991433098?check_suite_focus=true#step:5:72

Where did you encounter the problem?

[FEATURE] Show diff after failure

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.

[Feature-Request] Should be able to check only changed files during CI.

What exactly happened?
Prettier Action checks all the codebase instead of the files which were changed only on the particular commit.

Steps to reproduce the behavior:

    - name: Prettier Action
      uses: creyD/[email protected]
      with:
        prettier_version: 1.19.1
        prettier_options: --write **/*.{js,ts,tsx}

What should've happened?
Should be able to check only changed files during CI.

How did it look?
Check the whole codebase instead. Why?

Where did you encounter the problem?

  • OS: ubuntu-latest

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.