|
| 1 | +name: 'Format source code' |
| 2 | +author: 'Pete Sramek' |
| 3 | +description: 'Formats source code using dotnet format tool. Pushes changes to the current branch.' |
| 4 | +inputs: |
| 5 | +# Required |
| 6 | + project-path: |
| 7 | + description: 'Path to the project or solution file.' |
| 8 | + required: true |
| 9 | +# Optional |
| 10 | + dotnet_sdk_version: |
| 11 | + description: '.NET SDK version. Default: ''9.x''' |
| 12 | + required: false |
| 13 | + default: '9.x' |
| 14 | + format-whitespace: |
| 15 | + description: 'Format whitespace. Default: ''true''' |
| 16 | + required: false |
| 17 | + default: 'true' |
| 18 | + format-style: |
| 19 | + description: 'Format style. Default: ''true''' |
| 20 | + required: false |
| 21 | + default: 'true' |
| 22 | + format-analyzers: |
| 23 | + description: 'Format analyzers. Default: ''false''' |
| 24 | + required: false |
| 25 | + default: 'false' |
| 26 | + format-analyzers-diagnostics-parameter: |
| 27 | + description: 'Format analyzers diagnostics parameter. Default: ''''' |
| 28 | + required: false |
| 29 | + default: '' |
| 30 | + |
| 31 | +runs: |
| 32 | + using: "composite" |
| 33 | + steps: |
| 34 | + - name: 'Checkout ${{ github.head_ref || github.ref }}' |
| 35 | + uses: actions/checkout@v5 |
| 36 | + |
| 37 | + - name: 'Setup .NET ${{ inputs.dotnet_sdk_version }}' |
| 38 | + uses: actions/setup-dotnet@v4 |
| 39 | + with: |
| 40 | + dotnet-version: ${{ inputs.dotnet_sdk_version }} |
| 41 | + |
| 42 | + - name: Format whitespace |
| 43 | + if: ${{ inputs.format-whitespace == 'true' }} |
| 44 | + shell: bash |
| 45 | + run: | |
| 46 | + dotnet format whitespace |
| 47 | + working-directory: ${{ github.workspace }} |
| 48 | + |
| 49 | + - name: Format style |
| 50 | + if: ${{ inputs.format-style == 'true' }} |
| 51 | + shell: bash |
| 52 | + run: | |
| 53 | + dotnet format style |
| 54 | + working-directory: ${{ github.workspace }} |
| 55 | + |
| 56 | + - name: 'Set target branch' |
| 57 | + if: ${{ inputs.format-analyzers == 'true' && inputs.format-analyzers-diagnostics-parameter != '' }} |
| 58 | + id: set-diagnostics-parameter |
| 59 | + shell: bash |
| 60 | + run: | |
| 61 | + echo "format-analyzers-diagnostics-parameter=--diagnostics ${{ inputs.format-analyzers-diagnostics-parameter }}" >> $GITHUB_OUTPUT |
| 62 | +
|
| 63 | + - name: Format analyzers |
| 64 | + if: ${{ inputs.format-analyzers == 'true' }} |
| 65 | + shell: bash |
| 66 | + run: | |
| 67 | + dotnet format analyzers ${{ env.format-analyzers-diagnostics-parameter }} |
| 68 | + working-directory: ${{ github.workspace }} |
| 69 | + |
| 70 | + - name: 'Push changes' |
| 71 | + uses: './.github/actions/git/push-changes' |
| 72 | + with: |
| 73 | + commit-message: 'Formatted csharp files' |
0 commit comments