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

Add support for a custom .NET executable and a custom working directory. #11

Merged
merged 1 commit into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
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