Check Style on 591d1c93db681f7b0557c58f457df2a965ce8378 #18
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: Style-Check | |
run-name: Check Style on ${{ github.sha }} | |
on: | |
push: | |
branches: | |
- master | |
paths: | |
- 'docker/release/**' | |
- 'helper_tools/**' | |
- '.github/**' | |
- '!.github/workflows/resources/*' | |
- '!.github/workflows/build-test.yml' | |
- '.clang-format' | |
- '.yamllint' | |
workflow_call: | |
inputs: | |
trigger: | |
type: string | |
required: false | |
jobs: | |
Style-Check: | |
runs-on: ubuntu-latest | |
timeout-minutes: 5 | |
permissions: | |
contents: write | |
pull-requests: write | |
steps: | |
- name: Check out repository code | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.ref }} | |
- name: Install tools | |
run: | | |
echo "set man-db/auto-update false" | sudo debconf-communicate && sudo dpkg-reconfigure man-db -f noninteractive | |
sudo apt-get update && sudo apt-get install -y --no-install-recommends cpplint shfmt yamllint clang-format | |
sudo wget https://github.com/hadolint/hadolint/releases/download/v2.12.0/hadolint-Linux-x86_64 -O /bin/hadolint | |
sudo chmod +x /bin/hadolint | |
- name: Set environment | |
run: | | |
echo EVENT="${{ inputs.trigger || github.event_name }}" >> $GITHUB_ENV | |
- name: Check Dockerfiles | |
run: | | |
find . -type f -name 'Dockerfile*' -print0 | \ | |
xargs -0 hadolint --ignore DL3008 --ignore DL3040 --ignore DL3041 -t warning | |
- name: Check yaml style | |
if: ${{ success() || failure() }} | |
run: yamllint . | |
- name: Check C code style | |
if: ${{ success() || failure() }} | |
run: | | |
cpplint --linelength=120 --filter=-runtime/int,-runtime/arrays,-readability/casting,-legal/copyright \ | |
--extensions=c,h,m,cc,hh,cpp,hpp,c++,h++,cxx,hxx --root=src --exclude='build/' --recursive . | |
- name: Check shell script style | |
if: ${{ success() || failure() }} | |
run: find . -type f -name '*.sh' -print0 | xargs -0 shfmt -d -s -i 4 -ci | |
- name: Check powershell script style | |
if: ${{ success() || failure() }} | |
run: pwsh -Command 'Invoke-ScriptAnalyzer -EnableExit -Recurse -Path .' | |
- name: Format C code and bash scripts | |
if: ${{ (env.EVENT == 'push') && (success() || failure()) }} | |
run: | | |
find . -type f \( -name '*.c' -o -name '*.h' -o -name '*.m' \) -print0 | \ | |
xargs -0 clang-format -i --Wno-error=unknown | |
find . -type f -name '*.sh' -print0 | xargs -0 shfmt -w -s -i 4 -ci | |
- name: Creat pull request | |
if: ${{ (env.EVENT == 'push') && (success() || failure()) }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
[[ -z "$(git status -s)" ]] && echo No changes && exit 0 | |
curr_branch="${{ github.ref_name }}" | |
new_branch="auto-format-$(git rev-parse HEAD | head -c 8)" | |
author_name="$(git log -1 --pretty=format:'%an')" | |
author_email="$(git log -1 --pretty=format:'%ae')" | |
git checkout -b "$new_branch" && git merge "$curr_branch" | |
git config user.name "$author_name" | |
git config user.email "$author_email" | |
git remote set-url origin "https://github.com/${{ github.repository }}" | |
git commit -am 'Apply formatting automatically from actions' | |
git push origin "$new_branch" | |
gh pr create -B "$curr_branch" -H "$new_branch" --title "Merge \`$new_branch\` into \`$curr_branch\`" \ | |
--body 'Apply code formatting [generated automatically]' |