mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 11:07:44 +00:00
Merge pull request #5077 from starccy/ci-checkshell-workflow
ci: Add a new workflow to check and format shell scripts in `util` dir
This commit is contained in:
commit
1b4ef90e25
1 changed files with 74 additions and 0 deletions
74
.github/workflows/CheckScripts.yml
vendored
Normal file
74
.github/workflows/CheckScripts.yml
vendored
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
name: CheckScripts
|
||||||
|
|
||||||
|
# spell-checker:ignore ludeeus mfinelli
|
||||||
|
|
||||||
|
env:
|
||||||
|
SCRIPT_DIR: 'util'
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
paths:
|
||||||
|
- 'util/**/*.sh'
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
paths:
|
||||||
|
- 'util/**/*.sh'
|
||||||
|
|
||||||
|
# End the current execution if there is a new changeset in the PR.
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}-${{ github.ref }}
|
||||||
|
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
shell_check:
|
||||||
|
name: ShellScript/Check
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- name: Run ShellCheck
|
||||||
|
uses: ludeeus/action-shellcheck@master
|
||||||
|
env:
|
||||||
|
SHELLCHECK_OPTS: -s bash
|
||||||
|
with:
|
||||||
|
severity: warning
|
||||||
|
scandir: ${{ env.SCRIPT_DIR }}
|
||||||
|
format: tty
|
||||||
|
|
||||||
|
shell_fmt:
|
||||||
|
name: ShellScript/Format
|
||||||
|
# no need to run in pr events
|
||||||
|
# shfmt will be performed on main branch when the PR is merged
|
||||||
|
if: github.event_name != 'pull_request'
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: [ shell_check ]
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
pull-requests: write
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- name: Setup shfmt
|
||||||
|
uses: mfinelli/setup-shfmt@v2
|
||||||
|
- name: Run shfmt
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
# show differs first for every files that need to be formatted
|
||||||
|
# fmt options: bash syntax, 4 spaces indent, indent for switch-case
|
||||||
|
echo "## show the differences between formatted and original scripts..."
|
||||||
|
find ${{ env.SCRIPT_DIR }} -name "*.sh" -print0 | xargs -0 shfmt -ln=bash -i 4 -ci -d || true
|
||||||
|
# perform a shell format
|
||||||
|
echo "## perform a shell format..."
|
||||||
|
# ignore the error code because `-d` will always return false when the file has difference
|
||||||
|
find ${{ env.SCRIPT_DIR }} -name "*.sh" -print0 | xargs -0 shfmt -ln=bash -i 4 -ci -w
|
||||||
|
- name: Commit any changes
|
||||||
|
uses: EndBug/add-and-commit@v9
|
||||||
|
with:
|
||||||
|
default_author: github_actions
|
||||||
|
message: "style: auto format by CI (shfmt)"
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue