Merge pull request #1889 from craigcomstock/ENT-13212/master #14
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 | |
| workflow_dispatch: # Enables manual trigger | |
| jobs: | |
| format-shell-scripts: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: "master" | |
| - 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: Save commit hash before | |
| run: echo "COMMIT_HASH_BEFORE=$(git log -1 --format=%H)">> $GITHUB_ENV | |
| - name: Format shell scripts | |
| run: | | |
| 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" | |
| fi | |
| done | |
| - name: Save commit hash after | |
| run: echo "COMMIT_HASH_AFTER=$(git log -1 --format=%H)">> $GITHUB_ENV | |
| - name: Create Pull Request | |
| if: env.COMMIT_HASH_BEFORE != env.COMMIT_HASH_AFTER | |
| uses: cfengine/create-pull-request@v6 | |
| with: | |
| title: Reformatted shell scripts | |
| body: Reformatted shell scripts using `shfmt --write --indent 4 <FILENAME>`. | |
| reviewers: | | |
| larsewi | |
| craigcomstock | |
| branch: formatting-action | |
| branch-suffix: timestamp |