├── .github └── workflows │ └── ci.yml ├── README.md ├── action.yml └── dprint.json /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | style: 7 | runs-on: ${{ matrix.os }} 8 | strategy: 9 | matrix: 10 | os: [ubuntu-latest, macOS-latest, windows-latest] 11 | steps: 12 | - name: Use LF line endings 13 | run: | 14 | git config --global core.autocrlf false 15 | git config --global core.eol lf 16 | 17 | - uses: actions/checkout@v4 18 | 19 | - name: Check formatting latest 20 | uses: ./ 21 | 22 | - name: Check formatting specific version 23 | uses: ./ 24 | with: 25 | dprint-version: 0.49.1 26 | 27 | - name: Check formatting specific config 28 | uses: ./ 29 | with: 30 | config-path: "dprint.json" 31 | 32 | - name: Check formatting specific version and config 33 | uses: ./ 34 | with: 35 | dprint-version: 0.49.1 36 | config-path: "dprint.json" 37 | 38 | - name: make poorly-formatted json file 39 | run: | 40 | echo '{"a": 1, "b": 2}' > poorly-formatted.json 41 | - name: Check formatting with excludes 42 | uses: ./ 43 | with: 44 | args: --excludes poorly-formatted.json 45 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # dprint check action 2 | 3 | This action runs `dprint check` on your source code and fails the build if something is not properly formatted. 4 | 5 | ## Usage 6 | 7 | 1. Checkout your repo. 8 | 2. Run `dprint/check` action. 9 | 10 | ```yml 11 | jobs: 12 | style: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - uses: actions/checkout@v4 16 | 17 | - uses: dprint/check@v2.3 18 | ``` 19 | 20 | If you are using a matrix, most likely you will only want to run it only on Linux. For example: 21 | 22 | ```yml 23 | - uses: dprint/check@v2.3 24 | if: runner.os == 'Linux' 25 | ``` 26 | 27 | ### Latest Version 28 | 29 | By default, `dprint/check` uses the latest version of dprint. 30 | 31 | ### Specific Version 32 | 33 | To use a specific version, specify that with the `dprint-version` input: 34 | 35 | ```yml 36 | - uses: dprint/check@v2.3 37 | with: 38 | dprint-version: 0.30.3 39 | ``` 40 | 41 | ### Config Path 42 | 43 | By default, `dprint/check` uses the auto-discovered configuration file. 44 | 45 | ### Specific Config 46 | 47 | To use a specific config, specify that with the `config-path` input: 48 | 49 | ```yml 50 | - uses: dprint/check@v2.3 51 | with: 52 | config-path: dprint-ci.json 53 | ``` 54 | 55 | ### Args 56 | 57 | To pass additional arguments to `dprint check`, pass them to the `args` input. E.g. to only check changed files: 58 | 59 | ```yml 60 | - name: Get changed files 61 | id: changed-files 62 | uses: tj-actions/changed-files@v45 63 | - uses: dprint/check@v2.3 64 | with: 65 | args: >- 66 | --allow-no-files 67 | ${{ steps.changed-files.outputs.all_changed_files }} 68 | ``` 69 | 70 | ## Troubleshooting 71 | 72 | ### Windows line endings 73 | 74 | When running on Windows, you may get a lot of messages like: 75 | 76 | ``` 77 | from D:\a\check\check\README.md: 78 | | Text differed by line endings. 79 | -- 80 | ``` 81 | 82 | This is because unfortunately git is configured in GH actions to check out line endings as CRLF (`\r\n`). 83 | 84 | You can fix this by only running the action on Linux as shown above (recommended), or to do the following before checking out the repo: 85 | 86 | ```yml 87 | - name: Ensure LF line endings for Windows 88 | run: | 89 | git config --global core.autocrlf false 90 | git config --global core.eol lf 91 | 92 | - uses: actions/checkout@v4 93 | ``` 94 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: "dprint-check-action" 2 | description: "Run `dprint check` on your source code" 3 | author: "thomaseizinger" 4 | inputs: 5 | dprint-version: 6 | description: "Specific dprint version to use (ex. 0.30.3)" 7 | required: false 8 | default: "" 9 | config-path: 10 | description: "Specific dprint config to use (ex. dprint.json)" 11 | required: false 12 | default: "" 13 | args: 14 | description: "Additional arguments to pass to dprint check" 15 | required: false 16 | default: "" 17 | runs: 18 | using: "composite" 19 | steps: 20 | - name: Install dprint 21 | shell: bash 22 | run: | 23 | curl -fsSL https://dprint.dev/install.sh | sh -s ${{ inputs.dprint-version }} > /dev/null 2>&1 24 | echo "/home/runner/.dprint/bin" >> $GITHUB_PATH 25 | - name: Check formatting 26 | shell: bash 27 | if: "${{ inputs.config-path == '' }}" 28 | run: ~/.dprint/bin/dprint check ${{ inputs.args }} 29 | - name: Check formatting with config 30 | shell: bash 31 | if: "${{ inputs.config-path != '' }}" 32 | run: ~/.dprint/bin/dprint check --config '${{ inputs.config-path }}' ${{ inputs.args }} 33 | branding: 34 | icon: "check-circle" 35 | color: "gray-dark" 36 | -------------------------------------------------------------------------------- /dprint.json: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": [ 3 | "https://plugins.dprint.dev/json-0.20.0.wasm", 4 | "https://plugins.dprint.dev/markdown-0.18.0.wasm", 5 | "https://plugins.dprint.dev/g-plane/pretty_yaml-v0.5.1.wasm" 6 | ] 7 | } 8 | --------------------------------------------------------------------------------