goldendict-ng/.github/workflows/auto clang format.yml
YiFang Xiao ce08f5520a action: auto clang format
add comment if the pr is from other person
2023-05-27 18:15:32 +08:00

64 lines
2 KiB
YAML

name: "auto clang-format code"
on:
pull_request:
branches:
# - dev
# - master
- staged
paths-ignore:
- "docs/**"
# - ".github/**"
- "howto/**"
- "*.md"
- "locale/**"
jobs:
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3.5.2
with:
# check out HEAD on the branch
ref: ${{ github.head_ref }}
repository: ${{github.event.pull_request.head.repo.full_name}}
# make sure the parent commit is grabbed as well, because
# that's what will get formatted (i.e. the most recent commit)
fetch-depth: 2
# format the latest commit
- name: ubuntu install clang-format
shell: bash
run: |
sudo apt-get install git lsb-release wget software-properties-common
wget -qO - https://apt.llvm.org/llvm.sh| sudo bash
sudo apt-get update
sudo apt-get install -y clang-format
git-clang-format --style=file HEAD^
git diff > clang-format.patch
# remove file if empty
[ -s clang-format.patch ] || rm clang-format.patch
- uses: EndBug/add-and-commit@v9
if: ${{ github.event.pull_request.head.repo.full_name == 'xiaoyifang/goldendict-ng' }}
with:
default_author: github_actor
message: 🎨 apply clang-format changes
- name: Check file existence
id: check_files
uses: andstor/file-existence-action@v2
with:
files: "clang-format.patch"
- name: File not exists
if: steps.check_files.outputs.files_exists != 'true'
run: echo the file is not existed
- name: PR comment with file
uses: thollander/actions-comment-pull-request@v2
if: steps.check_files.outputs.files_exists == 'true'
with:
filePath: /home/runner/work/goldendict-ng/goldendict-ng/clang-format.patch
pr_number: ${{ github.event.number }}