Skip to content

Commit

Permalink
format code in prs (#1166)
Browse files Browse the repository at this point in the history
  • Loading branch information
bruno-garcia authored Aug 25, 2021
1 parent 206fea3 commit 133e1a5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/format-code.yml
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
16 changes: 16 additions & 0 deletions scripts/commit-formatted-code.sh
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

0 comments on commit 133e1a5

Please sign in to comment.