-
-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
206fea3
commit 133e1a5
Showing
2 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: format code | ||
on: | ||
pull_request: | ||
|
||
jobs: | ||
format-code: | ||
name: Format Code | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Install dotnet-format | ||
run: dotnet tool install -g dotnet-format | ||
- name: Format Code | ||
run: dotnet format | ||
|
||
# actions/checkout fetches only a single commit in a detached HEAD state. Therefore | ||
# we need to pass the current branch, otherwise we can't commit the changes. | ||
# GITHUB_HEAD_REF is the name of the head branch. GitHub Actions only sets this for PRs. | ||
- name: Commit Formatted Code | ||
run: ./scripts/commit-formatted-code.sh $GITHUB_HEAD_REF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
|
||
GITHUB_BRANCH="${1}" | ||
|
||
if [[ $(git status) == *"nothing to commit"* ]]; then | ||
echo "Nothing to commit. All code formatted correctly." | ||
else | ||
echo "Formatted some code. Going to push the changes." | ||
git config --global user.name 'Sentry Github Bot' | ||
git config --global user.email 'bot+github-bot@sentry.io' | ||
git fetch | ||
git checkout ${GITHUB_BRANCH} | ||
git commit -am "Format code" | ||
git push --set-upstream origin ${GITHUB_BRANCH} | ||
fi |