-
Notifications
You must be signed in to change notification settings - Fork 0
217 lines (213 loc) · 8.04 KB
/
build_check.yml
File metadata and controls
217 lines (213 loc) · 8.04 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
name: crow-ci
on:
push:
branches:
- main
paths-ignore:
- "docs/**/*.md"
- "*.md"
pull_request:
branches:
- "*"
paths-ignore:
- "docs/**/*.md"
- "*.md"
types:
- opened
- synchronize
- reopened
- ready_for_review
env:
CONDA_ENV: crow
CACHE_VERSION: 1
jobs:
quick-validation:
name: Quick validation (Lint + Tests)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Miniconda
uses: conda-incubator/setup-miniconda@v3
with:
environment-file: environment.yml
python-version: 3.12
activate-environment: ${{ env.CONDA_ENV }}
use-mamba: true
- name: Verify environment
run: |
conda info
conda list
- name: Check code formatting with black
run: conda run -n ${{ env.CONDA_ENV }} black --check --diff crow tests
- name: Check import order with isort
run: conda run -n ${{ env.CONDA_ENV }} isort --check --diff crow tests
- name: Run tests with pytest + coverage
run: |
conda run -n ${{ env.CONDA_ENV }} pip install coverage
conda run -n ${{ env.CONDA_ENV }} coverage run -m pytest -v --maxfail=1 --disable-warnings
conda run -n ${{ env.CONDA_ENV }} coverage report -m
conda run -n ${{ env.CONDA_ENV }} coverage xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
files: ./coverage.xml
fail_ci_if_error: true
verbose: true
use_oidc: false
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
check-code-version:
name: Verify code version update
runs-on: ubuntu-latest
if: github.ref != 'refs/heads/main'
steps:
# Get current version
- name: Check out the code
uses: actions/checkout@v4
- name: Get version from current branch
id: current_version
run: |
CURRENT_VERSION="$(grep -oP '__version__ = "\K[^"]+' crow/__init__.py)"
echo "CURRENT_VERSION=$CURRENT_VERSION" >> $GITHUB_ENV
echo "my branch is ${{ github.ref }}"
# Get main version
- name: Checkout the main branch to get its version
uses: actions/checkout@v4
with:
ref: main
- name: Get version from main branch
id: main_version
run: |
if [[ "$(git show origin/main:crow/__init__.py)" == *"__version__"* ]]; then
MAIN_VERSION="$(grep -oP '__version__ = "\K[^"]+' crow/__init__.py)"
else
echo "No version found at main, assuming version 0.0.0"
MAIN_VERSION="0.0.0"
fi
echo "MAIN_VERSION=$MAIN_VERSION" >> $GITHUB_ENV
- name: Get PR number
id: pr_number
run: |
# Fetch the pull request number from the GitHub context
PR_NUMBER=$(echo $GITHUB_REF | sed 's/refs\/pull\/\([0-9]*\)\/merge/\1/')
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
# Compare new version number
- name: Compare new version number
run: |
IFS=. read -r C1 C2 C3 <<< "$CURRENT_VERSION"
if [ "$MAIN_VERSION" == "1.0.2-1" ]; then MAIN_VERSION="1.0.2"; fi
IFS=. read -r M1 M2 M3 <<< "$MAIN_VERSION"
if [ "$C1" != "$M1" ]; then
GOAL="$((M1 + 1)).0.0"
if [ $C1 -lt $M1 ]; then
ERROR=" - Version number should increase: $CURRENT_VERSION<$MAIN_VERSION"
elif [ "$C1" != "$((M1 + 1))" ]; then
ERROR=" - Increment should be done by 1: $GOAL"
elif [ "$CURRENT_VERSION" != "$GOAL" ]; then
ERROR=" - When major version is increased, others should be zero: $GOAL"
fi
elif [ "$C2" != "$M2" ]; then
GOAL="$C1.$((M2 + 1)).0"
if [ $C2 -lt $M2 ]; then
ERROR=" - Version number should increase: $CURRENT_VERSION<$MAIN_VERSION"
elif [ "$C2" != "$((M2 + 1))" ]; then
ERROR=" - Increments should be done by 1: $GOAL"
elif [ "$CURRENT_VERSION" != "$GOAL" ]; then
ERROR=" - When middle version is increased, last number should be zero: $GOAL"
fi
elif [ "$C3" != "$M3" ]; then
GOAL="$C1.$C2.$((M3 + 1))"
if [ $C3 -lt $M3 ]; then
ERROR=" - Version number should increase: $CURRENT_VERSION<$MAIN_VERSION"
elif [ "$CURRENT_VERSION" != "$GOAL" ]; then
ERROR=" - Increments should be done by 1: $GOAL"
fi
else
ERROR=" - Version at crow/__init__.py has not been updated!"
fi
echo "ERROR=$ERROR" >> $GITHUB_ENV
# Update PR title
- name: Get PR title and clean version number from it
env:
TITLE: ${{ github.event.pull_request.title }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
NEW_TITLE="${TITLE% [version:*}"
echo "Clean title: $NEW_TITLE"
if [ "$ERROR" == "" ]; then
NEW_TITLE="${NEW_TITLE} [version:$CURRENT_VERSION]"
echo "New title: $NEW_TITLE"
fi
echo "Updating PR #$PR_NUMBER with new title: $NEW_TITLE"
curl -s -X PATCH \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
-d "{\"title\":\"$NEW_TITLE\"}" \
"https://api.github.com/repos/${{ github.repository }}/pulls/$PR_NUMBER" > /dev/null
- name: Check version update
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if [ "$ERROR" != "" ]; then
echo "Check failed:"
echo "$ERROR"
exit 1
fi
echo "[ok] Version increased changed!"
crow-matrix:
name: (${{ matrix.os }}, py${{ matrix.python-version }})${{ matrix.coverage && ' + coverage' || '' }}
runs-on: ${{ matrix.os }}-latest
needs: quick-validation
if: >
(github.event_name == 'pull_request' && !github.event.pull_request.draft)
|| (github.event_name == 'push' && github.ref == 'refs/heads/main')
strategy:
fail-fast: false
matrix:
os: ["ubuntu", "macos"]
python-version: ["3.11", "3.12", "3.13"]
include:
- os: ubuntu
python-version: "3.12"
coverage: true
steps:
- uses: actions/checkout@v4
- name: Set up Miniconda
uses: conda-incubator/setup-miniconda@v3
with:
python-version: ${{ matrix.python-version }}
activate-environment: ${{ env.CONDA_ENV }}
use-mamba: true
environment-file: environment.yml
- name: Cache Conda env
uses: actions/cache/restore@v4
with:
path: ${{ env.CONDA }}/envs
key: conda-${{ runner.os }}-py${{ matrix.python-version }}-${{ hashFiles('environment.yml') }}-v${{ env.CACHE_VERSION }}
- name: Update environment
if: steps.cache.outputs.cache-hit != 'true'
run: conda env update -n ${{ env.CONDA_ENV }} -f environment.yml
- name: Install test dependencies
run: |
conda run -n ${{ env.CONDA_ENV }} pip install pytest-xdist pytest-cov
- name: Check code formatting with black
run: conda run -n ${{ env.CONDA_ENV }} black --check --diff crow tests
- name: Check import order with isort
run: conda run -n ${{ env.CONDA_ENV }} isort --check --diff crow tests
- name: Run tests
run: |
if [[ "${{ matrix.coverage || false }}" == "true" ]]; then
conda run -n ${{ env.CONDA_ENV }} pytest -vv --runslow --cov crow --cov-report xml --cov-branch -n auto
else
conda run -n ${{ env.CONDA_ENV }} pytest -vv --runslow -n auto
fi
- name: Upload coverage to Codecov
if: ${{ matrix.coverage == true }}
uses: codecov/codecov-action@v5
with:
files: ./coverage.xml
fail_ci_if_error: true
verbose: true
use_oidc: false
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}