[CI] fix issue when apply format (#6019)

Fix issues hit when apply format.
1. tmp diff file is not opened binary form, don't need to encode.
2. add contents write to "Check code formatting" workflow for commit and
push change.
3. put main branch to different path to avoid issue when checkout head
branch to same path.
This commit is contained in:
Xiang Li 2023-11-16 16:27:26 -05:00 коммит произвёл GitHub
Родитель 3db94d17a8
Коммит 9dbfde5d51
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 6 добавлений и 4 удалений

8
.github/workflows/clang-format-checker.yml поставляемый
Просмотреть файл

@ -6,6 +6,7 @@ on:
types: edited
permissions:
pull-requests: write
contents: write
jobs:
code_formatter:
@ -84,23 +85,24 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 2
path: main
- name: Setup Python env
uses: actions/setup-python@v4
with:
python-version: '3.11'
cache: 'pip'
cache-dependency-path: 'utils/git/requirements_formatting.txt'
cache-dependency-path: 'main/utils/git/requirements_formatting.txt'
- name: Install python dependencies
run: pip install -r utils/git/requirements_formatting.txt
run: pip install -r main/utils/git/requirements_formatting.txt
- name: Apply code diff
env:
GITHUB_PR_NUMBER: ${{ github.event.issue.number }}
COMMENT_ID: ${{ github.event.comment.id }}
run: |
python utils/git/code-format-save-diff.py \
python main/utils/git/code-format-save-diff.py \
--token ${{ secrets.GITHUB_TOKEN }} \
--issue-number $GITHUB_PR_NUMBER \
--tmp-diff-file $TMP_DIFF_FILE \

Просмотреть файл

@ -58,7 +58,7 @@ def apply_patches(args: argparse.Namespace) -> None:
os.remove(args.tmp_diff_file)
with open(args.tmp_diff_file, 'w+') as tmp:
tmp.write(diff.encode("utf-8"))
tmp.write(diff)
tmp.flush()
tmp.close()