Skip to content

Fix Codacy (#65)

Fix Codacy (#65) #3

Workflow file for this run

name: Shell Format
on:
push:
branches: ["master"]
permissions:
contents: write
pull-requests: write
jobs:
shell-format:
name: Shell Format (shfmt)
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Install shfmt
run: |
sudo apt-get install shfmt -y
- name: Checkout Code
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
- name: Format, Commit and Push Changes
run: |
BRANCH_NAME="fix/shfmt"
# Check if the branch exists, and switch to it, otherwise create a new branch
if git rev-parse --verify ${BRANCH_NAME}; then
git checkout ${BRANCH_NAME}
git pull origin master
else
git checkout -b ${BRANCH_NAME}
fi
# Format Shell Scripts
find . -type f -name "*.sh" -exec shfmt -w -i 4 {} \;
# Commit and Push
git diff --exit-code || (
COMMIT_MSG="Format shell scripts with shfmt"
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add .
git commit -m "${COMMIT_MSG}" # Use the commit message here
git push -f --set-upstream origin ${BRANCH_NAME}
gh pr create --title "${COMMIT_MSG}" --body "This PR formats shell scripts with shfmt."
)
env:
GH_TOKEN: ${{ secrets.WORKFLOW_TOKEN }}