-
Notifications
You must be signed in to change notification settings - Fork 0
145 lines (122 loc) · 4.67 KB
/
python-app.yml
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
name: Build, test and publish
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
permissions:
contents: read
jobs:
build_and_test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ "3.8", "3.9", "3.10", "3.11" ]
steps:
- name: Install libegl1
run: sudo apt-get install -y libegl1
- name: Check out repository
uses: actions/checkout@v4
- name: Set up python
id: setup-python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root
- name: Install project
run: poetry install --no-interaction
- name: Lint with isort, black and flake8
run: |
poetry run isort visprompt
poetry run isort tests
poetry run black visprompt
poetry run black tests
poetry run flake8 visprompt
poetry run flake8 tests
continue-on-error: true
- name: Test with pytest
run: |
poetry run coverage erase
poetry run coverage run -a --source=./visprompt --branch -m pytest -s -v --black --isort tests --junit-xml=junit/test-results-${{ matrix.python-version }}.xml
poetry run coverage report
poetry run coverage xml
publish:
needs: build_and_test
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
steps:
- name: Check out PR branch
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Fetch main branch
run: |
git fetch --depth=1 origin main:refs/remotes/origin/main
- name: Get version from pyproject.toml in PR
id: pr_version
run: |
PR_VERSION=$(grep -Po '(?<=version = ")[^"]*' pyproject.toml)
echo "PR version: $PR_VERSION"
echo "::set-output name=pr_version::$PR_VERSION"
- name: Get version from pyproject.toml in main
id: main_version
run: |
git checkout refs/remotes/origin/main
MAIN_VERSION=$(grep -Po '(?<=version = ")[^"]*' pyproject.toml)
echo "Main version: $MAIN_VERSION"
echo "::set-output name=main_version::$MAIN_VERSION"
- name: Compare versions and set flag
run: |
if [[ "${{ steps.pr_version.outputs.pr_version }}" != "${{ steps.main_version.outputs.main_version }}" ]]; then
echo "Version changed from ${{ steps.main_version.outputs.main_version }} to ${{ steps.pr_version.outputs.pr_version }}."
echo "::set-output name=should_publish::true"
else
echo "No version change detected."
echo "::set-output name=should_publish::false"
fi
- name: Set up python
if: steps.check_version_change.outputs.should_publish == 'true'
id: setup-python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install Poetry
if: steps.check_version_change.outputs.should_publish == 'true'
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: Load cached venv
if: steps.check_version_change.outputs.should_publish == 'true'
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-3.x-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
if: steps.check_version_change.outputs.should_publish == 'true' && steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root
- name: Install project
if: steps.check_version_change.outputs.should_publish == 'true'
run: poetry install --no-interaction
- name: Publish to PyPI
if: steps.check_version_change.outputs.should_publish == 'true'
env:
PYPI_API_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
run: |
poetry config pypi-token.pypi ${{ secrets.PYPI_API_TOKEN }}
poetry publish --build