-
Notifications
You must be signed in to change notification settings - Fork 1.5k
164 lines (148 loc) · 5.82 KB
/
Copy pathcode_analysis.yml
File metadata and controls
164 lines (148 loc) · 5.82 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
name: code analysis
on: pull_request
# push:
# branches: [ $default-branch ]
# pull_request:
# branches: [ $default-branch ]
permissions:
contents: read
jobs:
clang-format:
# For any event that is not a PR, the CI will always run. In PRs, the CI
# can be skipped if the tag [skip-ci] is written in the title.
if: |
(github.repository_owner == 'root-project' && github.event_name != 'pull_request') ||
(github.event_name == 'pull_request' && !(
contains(github.event.pull_request.title, '[skip-ci]') ||
contains(github.event.pull_request.labels.*.name, 'skip ci') ||
contains(github.event.pull_request.labels.*.name, 'skip code analysis')
))
runs-on: ubuntu-latest
env:
TRAVIS_BRANCH: ${{ github.base_ref }}
TRAVIS_PULL_REQUEST_REPO: ${{ github.event.pull_request.head.repo.html_url }}
TRAVIS_PULL_REQUEST_BRANCH: ${{ github.head_ref }}
BASE_COMMIT: ${{ github.event.pull_request.base.sha }}
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 1024
ref: ${{ github.event.pull_request.head.sha }}
- name: Fetch base sha
run: git fetch --depth=1024 origin +${{github.event.pull_request.base.sha}}:origin/base_sha
- name: Determine merge base
run: echo "MERGE_BASE=$(git merge-base ${{ github.event.pull_request.base.sha }} HEAD)" >> $GITHUB_ENV
- name: install clang-format
run: |
wget https://apt.llvm.org/llvm.sh
chmod u+x ./llvm.sh
sudo ./llvm.sh 20
sudo apt-get install -y clang-format-20
PATH=/usr/lib/llvm-20/bin:${PATH}
- name: run clang-format script
run: |
PATH=/usr/lib/llvm-20/bin:${PATH}
.ci/format_script.sh
clang-tidy:
# For any event that is not a PR, the CI will always run. In PRs, the CI
# can be skipped if the tag [skip-ci] is written in the title.
if: |
(github.repository_owner == 'root-project' && github.event_name != 'pull_request') ||
(github.event_name == 'pull_request' && !(
contains(github.event.pull_request.title, '[skip-ci]') ||
contains(github.event.pull_request.labels.*.name, 'skip ci') ||
contains(github.event.pull_request.labels.*.name, 'skip code analysis')
))
runs-on:
- self-hosted
- linux
- x64
container:
image: registry.cern.ch/root-ci/alma10:buildready
options: '--security-opt label=disable --rm'
env:
OS_APPLICATION_CREDENTIAL_ID: '7f5b64a265244623a3a933308569bdba'
OS_APPLICATION_CREDENTIAL_SECRET: ${{ secrets.OS_APPLICATION_CREDENTIAL_SECRET }}
OS_AUTH_TYPE: 'v3applicationcredential'
OS_AUTH_URL: 'https://keystone.cern.ch/v3'
OS_IDENTITY_API_VERSION: 3
OS_INTERFACE: 'public'
OS_REGION_NAME: 'cern'
PYTHONUNBUFFERED: true
env:
TRAVIS_BRANCH: ${{ github.base_ref }}
TRAVIS_PULL_REQUEST_REPO: ${{ github.event.pull_request.head.repo.html_url }}
TRAVIS_PULL_REQUEST_BRANCH: ${{ github.head_ref }}
BASE_COMMIT: ${{ github.event.pull_request.base.sha }}
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 1
ref: ${{ github.event.pull_request.head.sha }}
path: ROOT-CI/src
- name: Fetch base sha
run: cd ROOT-CI/src && git fetch --depth=1 origin +${{github.event.pull_request.base.sha}}:origin/base_sha
- name: Determine merge base
run: echo "MERGE_BASE=$(cd ROOT-CI/src && git merge-base ${{ github.event.pull_request.base.sha }} HEAD)" >> $GITHUB_ENV
- name: run clang-tidy script
run: |
ROOT-CI/src/.ci/tidy_script.sh
ruff:
if: |
(github.repository_owner == 'root-project' && github.event_name != 'pull_request') ||
(github.event_name == 'pull_request' && !(
contains(github.event.pull_request.title, '[skip-ci]') ||
contains(github.event.pull_request.labels.*.name, 'skip ci') ||
contains(github.event.pull_request.labels.*.name, 'skip code analysis')
))
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 2
- name: Get the list of changed files
id: diff
run: |
git diff --diff-filter=AMR --name-only HEAD~1 | tee changed_files.txt
- name: Install ruff
uses: astral-sh/ruff-action@v3
with:
version: "latest"
args: "--version"
- name: Lint code
run: |
files=$(grep '\.py$' changed_files.txt || echo "")
if [ -n "$files" ]; then
echo "$files" | xargs ruff check --diff || true
echo "$files" | xargs ruff check
else
echo "No python files to lint"
fi
- name: Format code
if: always()
run: |
files=$(grep '\.py$' changed_files.txt || echo "")
if [ -n "$files" ]; then
apply_command=""
failure=false
for file in $files; do
while IFS=- read -r start length; do
[ -z "$start" ] && continue
length=${length:-1}
# Skip invalid ranges
if [ "$start" -eq 0 ] || [ "$length" -eq 0 ]; then
continue
fi
end=$((start + length))
ruff format --diff --preview --range ${start}-${end} ${file} || failure=true
apply_command+="ruff format --range $start-$end $file && "
done < <(git diff --unified=0 HEAD~1 -- "$file" | grep '^@@' | sed -E 's/^@@ -[0-9]+(,[0-9]+)? \+([0-9]+)(,([0-9]+))? @@.*/\2-\4/')
done
if ${failure}; then
echo -e "::error::Formatting failed. To apply the changes locally, run the following command:\n$apply_command"
exit 123;
fi
else
echo "No python files to format"
fi