-
Notifications
You must be signed in to change notification settings - Fork 0
102 lines (88 loc) · 3.21 KB
/
Copy pathpython-ci-main.yml
File metadata and controls
102 lines (88 loc) · 3.21 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
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
name: CI on main
env:
package-name: aplot
on:
push:
branches: ['main']
pull_request:
branches: ['main']
permissions:
contents: read
jobs:
run-tests:
runs-on: ubuntu-latest
env:
TestingOn: GitHub
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.8
uses: actions/setup-python@v3
with:
python-version: '3.8'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest pytest-cov
pip install -e .
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Test with pytest
run: |
pytest --cov=${{ env.package-name }} --cov-report=xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
token: ${{secrets.CODECOV_TOKEN}}
file: ./coverage.xml
flags: unittests
name: unit-tests-coverage
fail_ci_if_error: false
run-flake8:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
flake8 . --count --max-complexity=10 --max-line-length=127 --ignore="E731, E741, E203, E265, E226, C901, W504, W503, E704"
version-check:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Get PR branch version
id: get_pr_version
run: |
pr_version=$(grep '__version__' ${{env.package-name}}/__config__.py | cut -d'"' -f2)
echo "PR branch version: $pr_version"
echo "pr_version=$pr_version" >> "$GITHUB_OUTPUT"
- name: Get main branch version
id: get_main_version
run: |
git fetch origin
echo "Config file:"
git show origin/main:${{env.package-name}}/__config__.py
main_version=$(git show origin/main:${{env.package-name}}/__config__.py | grep '__version__' | cut -d'"' -f2)
echo "Main branch version: $main_version"
echo "main_version=$main_version" >> "$GITHUB_OUTPUT"
- name: Compare versions
run: |
echo "Main branch version: ${{ steps.get_main_version.outputs.main_version }}"
echo "PR branch version: ${{ steps.get_pr_version.outputs.pr_version }}"
if [ "${{ github.event_name }}" == "pull_request" ]; then
if [ "${{ steps.get_main_version.outputs.main_version }}" = "${{ steps.get_pr_version.outputs.pr_version }}" ]; then
echo "Error: Version is the same as on the main branch"
exit 1
else
echo "Ok: Version is different from the main branch"
fi
fi