-
Notifications
You must be signed in to change notification settings - Fork 536
49 lines (42 loc) · 1.57 KB
/
format.yml
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
# Automatic code formatting
name: "format"
on:
pull_request:
branches: [ master ]
types: [opened, closed, synchronize]
env:
python_version: "3.9"
jobs:
format-code:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Python ${{ env.python_version }}
uses: actions/setup-python@v3
with:
python-version: ${{ env.python_version }}
- name: Install dependencies
run: |
python3 -m pip install autopep8
- name: Grant permissions
run: |
chmod +x "${GITHUB_WORKSPACE}/.github/scripts/format-cpp.sh"
chmod +x "${GITHUB_WORKSPACE}/.github/scripts/format-py.sh"
- name: Format Codebase
run: |
git remote add upstream ${{ github.event.pull_request.base.repo.clone_url }}
git fetch upstream ${{ github.event.pull_request.base.ref }}
".github/scripts/format-cpp.sh" "upstream" "${{ github.event.pull_request.base.ref }}"
".github/scripts/format-py.sh" "upstream" "${{ github.event.pull_request.base.ref }}"
- name: Commit
run: |
HAS_CHANGES=$(git diff --staged --name-only)
if [ ${#HAS_CHANGES} -gt 0 ]; then
git checkout -B "${{ github.head_ref }}"
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
git config --global user.name "${{ github.actor }}"
git commit -m '[Automated Commit] Format Codebase'
git push origin "${{ github.head_ref }}"
fi