Skip to content

Commit

Permalink
Add support for a custom .NET executable and a custom working directo…
Browse files Browse the repository at this point in the history
…ry. (#11)
  • Loading branch information
rolfbjarne authored Jun 2, 2023
1 parent 0dc171c commit b54991a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ uses: rolfbjarne/[email protected]
# Only consider autoformatting for files modified in the pull request.
onlyFilesModifiedInPullRequest: false
# The .NET executable to use to run 'dotnet format ...'
dotnetExecutable: 'dotnet'
# The working directory to use when running 'dotnet format ...'.
# This does not apply when using a custom script.
workingDirectory: '..'
```

[1]: https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/code-style-rule-options
Expand Down
19 changes: 15 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ inputs:
description: 'Only format files that were changed in the pull request'
required: false
default: false
dotnetExecutable:
description: 'The path to the "dotnet" executable to use'
required: false
default: 'dotnet'
workingDirectory:
description: 'The working directory when formatting using "dotnet format". This does not apply when using a custom script.'
required: false
default: '..'


runs:
using: "composite"
Expand All @@ -51,6 +60,8 @@ runs:
SCRIPT="${{ inputs.script }}"
PROJECTS=(${{ inputs.projects }})
DOTNET="${{ inputs.dotnetExecutable }}"
WORKING_DIRECTORY="${{ inputs.workingDirectory }}"
# env -0 | sort -z | tr '\0' '\n' || true
Expand All @@ -63,17 +74,17 @@ runs:
# Otherwise loop over any projects that were given to us.
DIR=$(pwd)
pushd .
cd ..
cd "$WORKING_DIRECTORY"
for PROJECT in "${PROJECTS[@]}"; do
dotnet format whitespace "$DIR/$PROJECT"
"$DOTNET" format whitespace "$DIR/$PROJECT"
done
popd
else
# format the whole repository if neither a script nor any projects were specified.
DIR=$(pwd)
pushd .
cd ..
dotnet format whitespace --folder "$DIR"
cd "$WORKING_DIRECTORY"
"$DOTNET" format whitespace --folder "$DIR"
popd
fi
Expand Down

0 comments on commit b54991a

Please sign in to comment.