forked from isl-org/Open3D
-
Notifications
You must be signed in to change notification settings - Fork 0
63 lines (60 loc) · 2.21 KB
/
style.yml
File metadata and controls
63 lines (60 loc) · 2.21 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
name: Style Check
on:
workflow_dispatch:
push:
branches:
- main
pull_request:
types: [opened, reopened, synchronize] # Rebuild on new pushes to PR
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
style-check:
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
ref: ${{ github.event.pull_request.head.sha || github.ref }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python version
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install dependencies
run: |
pip install -U -r python/requirements_style.txt
- name: Apply style formatting
if: github.event_name == 'pull_request'
run: |
python util/check_style.py --apply
- name: Check style formatting
if: github.event_name != 'pull_request'
run: |
python util/check_style.py
- name: Commit and push changes
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git add -u
if ! git diff --staged --quiet; then
git commit -m "Apply automatic code formatting"
git push || exit 1
else
echo "No formatting changes needed"
fi
- name: Check for formatting changes from fork
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository
run: |
git add -u
if ! git diff --staged --quiet; then
echo "::error::This PR requires formatting changes but is from a fork. Please run 'python util/check_style.py --apply' locally and push the changes."
exit 1
else
echo "No formatting changes needed"
fi