-
Notifications
You must be signed in to change notification settings - Fork 2
126 lines (104 loc) · 3.56 KB
/
ci.yaml
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
name: CI Pipeline
on:
push:
branches:
- main
- develop
pull_request:
branches:
- main
- develop
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.10']
steps:
- name: Check out the repository
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -
export PATH="$HOME/.local/bin:$PATH"
- name: Install project with dev dependencies
run: |
poetry install --with dev
# Step to detect if the commit is a merge commit (skip CI on merge commits)
- name: Check if commit is a merge commit
id: check-merge
run: |
if git log -1 --pretty=%B | grep -q "Merge pull request"; then
echo "is-merge=true" >> $GITHUB_ENV
else
echo "is-merge=false" >> $GITHUB_ENV
fi
# Step to detect changes in pyproject.toml or poetry.lock
- name: Check for dependency changes
id: check-deps
if: env.is-merge == 'false' # Skip if it's a merge commit
run: |
if git diff --name-only HEAD~1 | grep -qE 'pyproject.toml|poetry.lock'; then
echo "dependencies-changed=true" >> $GITHUB_ENV
else
echo "dependencies-changed=false" >> $GITHUB_ENV
fi
# Step to generate requirements.txt if dependencies have changed
- name: Generate requirements.txt
if: env.is-merge == 'false' && env.dependencies-changed == 'true'
run: |
poetry export -f requirements.txt --output requirements.txt --without-hashes
# Commit and push the updated requirements.txt if dependencies have changed
- name: Commit and push updated requirements.txt
if: env.is-merge == 'false' && env.dependencies-changed == 'true'
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git add requirements.txt
git commit -m "Update requirements.txt [skip ci]"
git push
# Run Black (auto-reformat) using Poetry
- name: Run Black (auto-reformat)
if: env.is-merge == 'false' # Skip if it's a merge commit
run: |
poetry run black .
# Run isort (auto-reformat) using Poetry
- name: Run isort (auto-reformat)
if: env.is-merge == 'false' # Skip if it's a merge commit
run: |
poetry run isort .
# Run pytest using Poetry
- name: Run pytest
if: env.is-merge == 'false' # Skip if it's a merge commit
run: |
poetry run pytest
docs:
runs-on: ubuntu-latest
steps:
- name: Check out the repository
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
# Install Poetry
- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -
export PATH="$HOME/.local/bin:$PATH"
# Install project with dev dependencies
- name: Install project with dev dependencies
run: |
poetry install --with dev
# Generate Sphinx Documentation with sphinx-apidoc
- name: Generate API Documentation with Sphinx
run: |
poetry run sphinx-apidoc -o docs/source codes
# Build HTML using Sphinx and output directly to docs/_build
- name: Build HTML with Sphinx
run: |
poetry run sphinx-build -b html docs/source docs/_build