-
-
Notifications
You must be signed in to change notification settings - Fork 0
49 lines (46 loc) · 1.49 KB
/
shell-format.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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 }}