-
Notifications
You must be signed in to change notification settings - Fork 21
181 lines (177 loc) · 6.34 KB
/
build_check.yml
File metadata and controls
181 lines (177 loc) · 6.34 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
name: Build and Check
on:
push:
branches:
- main
pull_request:
env:
CONDA_ENV_NAME: clmm
jobs:
check-formatting:
name: Code formatting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: conda-incubator/setup-miniconda@v3
with:
activate-environment: ${{ env.CONDA_ENV_NAME }}
environment-file: environment.yml
- uses: actions/cache@v4
with:
path: ${{ env.CONDA }}/pkgs
key: ${{ runner.os }}-conda-${{ env.CONDA_ENV_NAME }}
- name: Analysing the code formatting with black
shell: bash -l {0}
run: |
black --check --diff clmm
- name: Analysing the code import order with isort
shell: bash -l {0}
run: |
isort --check --diff clmm
- name: Analysing the code with pylint
shell: bash -l {0}
run: |
pylint clmm
doc-valid:
name: Documentation Validation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: conda-incubator/setup-miniconda@v3
with:
activate-environment: ${{ env.CONDA_ENV_NAME }}
environment-file: environment.yml
- uses: actions/cache@v4
with:
path: ${{ env.CONDA }}/pkgs
key: ${{ runner.os }}-conda-${{ env.CONDA_ENV_NAME }}
- name: Install the package
shell: bash -l {0}
run: |
pip install . -vv --no-deps --no-build-isolation
- name: Run the docs
shell: bash -l {0}
run: |
make -C docs/ html
build-gcc-ubuntu:
name: Unit tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: conda-incubator/setup-miniconda@v3
with:
activate-environment: ${{ env.CONDA_ENV_NAME }}
environment-file: environment.yml
- uses: actions/cache@v4
with:
path: ${{ env.CONDA }}/pkgs
key: ${{ runner.os }}-conda-${{ env.CONDA_ENV_NAME }}
- name: Install the package
shell: bash -l {0}
run: |
pip install . -vv --no-deps --no-build-isolation
- name: Run the unit tests
shell: bash -l {0}
run: |
pytest tests/ --ignore=cluster_toolkit/tests --cov=clmm/
env:
DISPLAY: test
- name: Coveralls
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash -l {0}
run: |
pip install coveralls
coveralls --service=github
check-code-version:
name: Code version number
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[^"]+' clmm/__init__.py)"
echo "CURRENT_VERSION=$CURRENT_VERSION" >> $GITHUB_ENV
# 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:clmm/__init__.py)" == *"__version__"* ]]; then
MAIN_VERSION="$(grep -oP '__version__ = "\K[^"]+' clmm/__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
# Get PR title to be updated with version
- name: Get PR title and clean version number from it
env:
TITLE: ${{ github.event.pull_request.title }}
run: |
NEW_TITLE="${TITLE% [version:*}"
echo "New title: $NEW_TITLE"
echo "NEW_TITLE=$NEW_TITLE" >> $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
- name: Check version change
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if [ "$CURRENT_VERSION" == "$MAIN_VERSION" ]; then
echo "Version at clmm/__init__.py has not been updated!"
# Use the GitHub API to update the PR title
echo "Removing version from PR 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
exit 1
fi
echo "[ok] Version has changed!"
- name: Check version update
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if [ "$(printf "%s\n%s" "$CURRENT_VERSION" "$MAIN_VERSION" | sort -V | tail -n 1)" != "$CURRENT_VERSION" ]; then
echo "Current version ($CURRENT_VERSION) < Main version ($MAIN_VERSION)"
# Use the GitHub API to update the PR title
echo "Removing version from PR 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
exit 1
fi
echo "[ok] Version increased changed!"
# Add version number to PR title
- name: Make new title for PR
run: |
NEW_TITLE="${NEW_TITLE} [version:$CURRENT_VERSION]"
echo "New title: $NEW_TITLE"
echo "NEW_TITLE=$NEW_TITLE" >> $GITHUB_ENV
- name: Update PR title
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Use the GitHub API to update the PR title
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