Update README.md (#67) #5
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
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 }} |