ENT-12601: Added workflow to automatically format shell scripts #4
Workflow file for this run
This file contains hidden or 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
| name: Check formatting on sources | ||
| on: | ||
| push: | ||
| branches: [master] | ||
| pull_request: | ||
| branches: [master] | ||
| jobs: | ||
| check: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: write | ||
| pull-request: write | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - name: Install dependencies | ||
| run: sudo apt install shfmt | ||
| - name: Configure git user | ||
| run: | | ||
| git config user.name 'GitHub' | ||
| git config user.email '<noreply@github.com>' | ||
| - name: Format shell scripts | ||
| run: | | ||
| # Recursively find all shell scripts in the build-scripts directory with a shebang | ||
| grep -Erl '^(#!/(bin|usr/bin)/(env )?(sh|bash))' build-scripts/ | while read -r file; do | ||
| if shfmt --diff --indent 4 "$file"; then | ||
| echo "No formatting needed for file '$file'" | ||
| else | ||
| echo "Formatting file '$file'..." | ||
| shfmt --write --indent 4 "$file" | ||
| git add "$file" | ||
| git commit -m "$(basename "$file"): formatted script with shfmt" | ||
| touch /tmp/create-pull-request | ||
| fi | ||
| done | ||
| - name: Create Pull Request | ||
| if: hashFiles('/tmp/create-pull-request') != '' | ||
| uses: cfengine/create-pull-request@v6 | ||
| with: | ||
| title: Reformatted shell scripts using shfmt | ||
| reviewers: | | ||
| larsewi | ||
| craigcomstock | ||
| branch: formatting-action | ||