prettier_action
prettier_action copied to clipboard
[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 🙏🏼
@mfn You can search for working_directory
in this repo to find out how it is used. It works just like you think: It's used to cd
into that directory and that's it. Your problem may be elsewhere.
https://github.com/creyD/prettier_action/blob/6602189cf8bac1ce73ffe601925f6127ab7f21ac/entrypoint.sh#L44
@markstos thank you, good point!
But looking a few lines above, isn't the issue the the action changes into its own action directory first so working_directory
is relative to that and not to the project being checked out? https://github.com/creyD/prettier_action/blob/6602189cf8bac1ce73ffe601925f6127ab7f21ac/entrypoint.sh#L36-L44
So relative paths are relative to this action and would make sense why something like working_directory: subdir/
won't work, as GITHUB_ACTION_PATH
is documented being
The path where an action is located. This property is only supported in composite actions. You can use this path to access files located in the same repository as the action. For example, /home/runner/work/_actions/repo-owner/name-of-action-repo/v1.
vs. what this action documents (emphasis mine):
Specify a directory to cd into before installing prettier and running it, use relative file path to the repository root for example app/
Can't make sense why my version with the absolute path wouldn't work though.
I'd say that, for relative paths, at least that's unexpected / a bug somewhere?
If the "working_directory" is not resolved relative to the project root, that seems like a bug to me.
I ran into my own path-related problem with a file-not-found error that doesn't tell me which file is not found. Nice tool, but still some rough edges here.
https://github.com/creyD/prettier_action/issues/91
Desired behavior is for working_directory
to be relative to root project dir, basically wherever the .git
directory is.
Anyone who lands here, might be worth checking my comment at https://github.com/creyD/prettier_action/issues/94#issuecomment-1425765698