-
Notifications
You must be signed in to change notification settings - Fork 15
166 lines (153 loc) · 5.59 KB
/
Copy pathcmake-format-check.yaml
File metadata and controls
166 lines (153 loc) · 5.59 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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
name: CMake Format Check
run-name: "${{ github.actor }} checking CMake format"
permissions:
contents: read
pull-requests: read
"on":
pull_request:
workflow_dispatch:
inputs:
ref:
description: "The branch, ref, or SHA to checkout. Defaults to the repository's default branch."
required: false
type: string
workflow_call:
inputs:
checkout-path:
description: "Path to check out code to"
required: false
type: string
skip-relevance-check:
description: "Bypass relevance check"
required: false
type: boolean
default: false
pr-base-sha:
description: "Base SHA of the PR for relevance check"
required: false
type: string
pr-head-sha:
description: "Head SHA of the PR for relevance check"
required: false
type: string
ref:
description: "The branch, ref, or SHA to checkout"
required: false
type: string
repo:
description: "The repository to checkout from"
required: false
type: string
env:
local_checkout_path:
${{ (github.event_name == 'workflow_call' && inputs.checkout-path) || format('{0}-src',
github.event.repository.name) }}
jobs:
pre-check:
runs-on: ubuntu-latest
outputs:
is_act: ${{ steps.prepare.outputs.is_act }}
ref: ${{ steps.prepare.outputs.ref }}
repo: ${{ steps.prepare.outputs.repo }}
base_sha: ${{ steps.prepare.outputs.base_sha }}
pr_number: ${{ steps.prepare.outputs.pr_number }}
steps:
- name: Prepare outputs
id: prepare
uses: Framework-R-D/phlex/.github/actions/prepare-check-outputs@main
with:
ref: ${{ inputs.ref }}
repo: ${{ inputs.repo }}
pr-base-sha: ${{ inputs.pr-base-sha }}
detect-changes:
needs: pre-check
if: >
github.event_name != 'workflow_dispatch' && (
github.event_name != 'workflow_call' ||
(inputs.skip-relevance-check != 'true' && github.event.inputs == null && github.event.comment == null)
) && needs.pre-check.outputs.is_act != 'true'
runs-on: ubuntu-latest
permissions:
contents: read
packages: read
outputs:
has_changes: ${{ steps.filter.outputs.matched }}
steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
path: ${{ env.local_checkout_path }}
ref: ${{ needs.pre-check.outputs.ref }}
repository: ${{ needs.pre-check.outputs.repo }}
- name: Detect relevant changes
id: filter
uses: Framework-R-D/phlex/.github/actions/detect-relevant-changes@main
with:
repo-path: ${{ env.local_checkout_path }}
base-ref: ${{ needs.pre-check.outputs.base_sha }}
head-ref: ${{ (github.event_name == 'workflow_call' && inputs.pr-head-sha) || needs.pre-check.outputs.ref }}
file-type: cmake
- name: Report detection outcome
run: |
if [ "${{ steps.filter.outputs.matched }}" != "true" ]; then
echo "::notice::No CMake-related changes detected; formatting check will be skipped."
else
echo "::group::CMake-related files"
printf '%s\n' "${{ steps.filter.outputs.matched_files }}"
echo "::endgroup::"
fi
cmake-format-check:
needs: [pre-check, detect-changes]
if: >
always() && (
needs.detect-changes.result == 'skipped' ||
(
needs.detect-changes.result == 'success' &&
needs.detect-changes.outputs.has_changes == 'true'
)
)
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: ${{ needs.pre-check.outputs.ref }}
path: ${{ env.local_checkout_path }}
repository: ${{ needs.pre-check.outputs.repo }}
- name: Set up Python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: "3.x"
- name: Install gersemi
run: pip install gersemi
- name: Check CMake formatting
id: lint
run: |
echo "➡️ Checking CMake file formatting..."
gersemi --check ${{ env.local_checkout_path }}
continue-on-error: true
- name: Evaluate CMake formatting result
if: always() && steps.lint.outcome != 'skipped'
# yamllint disable rule:line-length
run: |
if [ "${{ steps.lint.outcome }}" = 'success' ]; then
echo "✅ All CMake files are properly formatted."
else
echo "::error::Found files with formatting issues."
echo "::error::Run 'gersemi -i <file>' locally or comment '@${{ github.event.repository.name }}bot format' on the PR to auto-fix."
exit 1
fi
# yamllint enable
cmake-format-check-skipped:
needs: [pre-check, detect-changes]
if: >
needs.pre-check.result == 'success' && github.event_name != 'workflow_dispatch' && (
github.event_name != 'workflow_call' ||
(inputs.skip-relevance-check != 'true' && github.event.inputs == null && github.event.comment == null)
) && needs.pre-check.outputs.is_act != 'true' && (needs.detect-changes.result == 'success' &&
needs.detect-changes.outputs.has_changes != 'true')
runs-on: ubuntu-latest
steps:
- name: No relevant CMake changes detected
run: echo "::notice::No CMake-related changes detected; cmake-format check skipped."