-
Notifications
You must be signed in to change notification settings - Fork 131
120 lines (98 loc) · 3.64 KB
/
check-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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
name: Checks - formatting
on:
pull_request:
workflow_dispatch:
issue_comment:
types: [created]
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref_name }}
cancel-in-progress: true
jobs:
format_check:
if: ${{ github.event_name != 'issue_comment' || (github.event_name == 'issue_comment' && startsWith(github.event.comment.body, '/autofix')) }}
runs-on: ubuntu-latest
container:
image: ghcr.io/llnl/sundials_spack_cache:llvm-17.0.4-h4lflucc3v2vage45opbo2didtcuigsn.spack
steps:
- name: Install git
run: |
apt update
apt install -y git python3-pip
- name: Install black
run: pip install black
- name: Print black version
run: black --version
- name: Install cmake-format
run: pip install cmakelang
- name: Print cmake-format version
run: cmake-format --version
- name: Install fprettify
run: pip install fprettify
- name: Print fprettify version
run: fprettify --version
- name: Print clang-format version
run: clang-format --version
- name: Check out repository code
if: github.event_name != 'issue_comment'
uses: actions/checkout@v4
with:
submodules: true
- name: Check out repository code
if: github.event_name == 'issue_comment'
uses: actions/checkout@v4
with:
ref: refs/pull/${{ github.event.issue.number }}/head
fetch-depth: 0
- name: Add safe directory
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
- name: Run checker on code
run: |
./scripts/format.sh CMakeLists.txt benchmarks cmake examples include src test
- name: Run git diff to see if anything changed
run: /usr/bin/git diff --name-only --exit-code
- name: Run git diff if we failed
if: failure()
run: /usr/bin/git diff > format.patch
- name: Archive diff as a patch if we failed
uses: actions/upload-artifact@v4
if: failure()
with:
name: format.patch
path: |
${{ github.workspace }}/format.patch
apply_format:
if: ${{ always() && contains(join(needs.*.result, ','), 'failure') && (github.event_name == 'issue_comment' && startsWith(github.event.comment.body, '/autofix')) }}
needs: format_check
runs-on: ubuntu-latest
steps:
# Checkout the GitHub created reference for the PR.
# The only way to do this is by using the "issue" number
# but that is really the PR number in this context.
# This is due to using an `issue_comment` event which
# is due to the GitHub Actions API that does not have
# a `pull_request_comment` event or something similar.
# This leaves us in a detached head state which is corrected
# in `apply-style/checkout.sh`
- name: Checkout repository code
uses: actions/checkout@v4
with:
ref: refs/pull/${{ github.event.issue.number }}/head
fetch-depth: 0
- name: Checkout the right git ref
run: ./.github/actions/apply-style/checkout.sh
- name: Download the git diff from format_check
uses: actions/download-artifact@v4
with:
name: format.patch
- name: Apply patch
run: |
git apply format.patch
rm format.patch
- name: Commit fixes
run: |
git config user.name "format-robot"
git config user.email "[email protected]"
if [ -n "$(git status --porcelain)" ]; then
git commit -am 'apply format updates'
git push
fi