Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add args input #13

Merged
merged 3 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,13 @@ jobs:
with:
dprint-version: 0.30.3
config-path: 'dprint.json'
- name: make poorly-formatted json file
run: |
echo '{"a": 1, "b": 2}' > poorly-formatted.json
- name: Check formatting with excludes
uses: ./
with:
args: --excludes poorly-formatted.json



Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is with all this whitespace here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch

15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,21 @@ To use a specific config, specify that with the `config-path` input:
config-path: dprint-ci.json
```

### Args

To pass additional arguments to `dprint check`, pass them to the `args` input. E.g. to only check changed files:

```yml
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v45
- uses: dprint/[email protected]
with:
args: >-
--allow-no-files
${{ steps.changed-files.outputs.all_changed_files }}
Comment on lines +65 to +67
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
args: >-
--allow-no-files
${{ steps.changed-files.outputs.all_changed_files }}
args: |
--allow-no-files
${{ steps.changed-files.outputs.all_changed_files }}

I am not familiar with that yaml syntax, does a multi-line string also work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

> makes it so that lines are separated with spaces instead of newlines, such that

a: >
  b
  c

Becomes

{"a": "b c\n"}

- chomps the trailing newline.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use https://yaml-multiline.info/ ~ once per month for silly yaml features like this

Copy link
Contributor Author

@znd4 znd4 Sep 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the problem with | here is that it would end up with the command

dprint check --allow-no-files
file1 file2 ...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use yaml-multiline.info ~ once per month for silly yaml features like this

It is cool and scary at the same time that yaml supports this. Thanks for explaining!

```

## Troubleshooting

### Windows line endings
Expand Down
8 changes: 6 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ inputs:
description: 'Specific dprint config to use (ex. dprint.json)'
required: false
default: ''
args:
description: 'Additional arguments to pass to dprint check'
required: false
default: ''
runs:
using: 'composite'
steps:
Expand All @@ -21,11 +25,11 @@ runs:
- name: Check formatting
shell: bash
if: "${{ inputs.config-path == '' }}"
run: ~/.dprint/bin/dprint check
run: ~/.dprint/bin/dprint check ${{ inputs.args }}
- name: Check formatting with config
shell: bash
if: "${{ inputs.config-path != '' }}"
run: ~/.dprint/bin/dprint check --config '${{ inputs.config-path }}'
run: ~/.dprint/bin/dprint check --config '${{ inputs.config-path }}' ${{ inputs.args }}
branding:
icon: 'check-circle'
color: 'gray-dark'
Loading