-
Notifications
You must be signed in to change notification settings - Fork 0
138 lines (114 loc) · 4.78 KB
/
lint_test_release.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
126
127
128
129
130
131
132
133
134
135
136
137
138
name: Lint, Test and Release
on: [push]
jobs:
lint:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- name: Setup Environment
id: setup
run: |
echo "python-version=$(cat .tool-versions | grep -Po '(?<=python ).*')" >> $GITHUB_OUTPUT
echo "poetry-version=$(cat .tool-versions | grep -Po '(?<=poetry ).*')" >> $GITHUB_OUTPUT
if [ $GITHUB_REF == 'refs/heads/master' ]; then echo "ENV=prod"; else echo "ENV=staging"; fi >> $GITHUB_ENV
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: ${{ steps.setup.outputs.python-version }}
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: ${{ steps.setup.outputs.poetry-version }}
virtualenvs-create: true
virtualenvs-in-project: true
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v4
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}-${{ hashFiles('**/pyproject.toml') }}-${{ hashFiles('**/.pre-commit-config.yaml') }}
- name: Install dependencies
run: poetry install
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
- name: Run linting pre-commit hooks
run: script -e -c "poetry run pre-commit run --all-files"
test:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- name: Setup Environment
id: setup
run: |
echo "python-version=$(cat .tool-versions | grep -Po '(?<=python ).*')" >> $GITHUB_OUTPUT
echo "poetry-version=$(cat .tool-versions | grep -Po '(?<=poetry ).*')" >> $GITHUB_OUTPUT
if [ $GITHUB_REF == 'refs/heads/master' ]; then echo "ENV=prod"; else echo "ENV=staging"; fi >> $GITHUB_ENV
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: ${{ steps.setup.outputs.python-version }}
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: ${{ steps.setup.outputs.poetry-version }}
virtualenvs-create: true
virtualenvs-in-project: true
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v4
with:
path: .venv
key: venv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }}-${{ hashFiles('**/pyproject.toml') }}-${{ hashFiles('**/.pre-commit-config.yaml') }}
- name: Install dependencies
run: poetry install
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
- name: Run unit tests
env:
ENV: test
run: script -e -c "poetry run python -m pytest -v example/tests"
release:
runs-on: ubuntu-20.04
needs: [lint, test]
steps:
- uses: actions/checkout@v4
- name: Bump version and push tag
uses: alexeyatbluescape/github-tag-action@bugfix/semver-empty-results
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WITH_V: true
DEFAULT_BUMP: patch
- name: Setup Environment
id: setup
run: |
echo "python-version=$(cat .tool-versions | grep -Po '(?<=python ).*')" >> $GITHUB_OUTPUT
echo "poetry-version=$(cat .tool-versions | grep -Po '(?<=poetry ).*')" >> $GITHUB_OUTPUT
if [ $GITHUB_REF == 'refs/heads/master' ]; then echo "ENV=prod"; else echo "ENV=staging"; fi >> $GITHUB_ENV
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: ${{ steps.setup.outputs.python-version }}
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: ${{ steps.setup.outputs.poetry-version }}
virtualenvs-create: true
virtualenvs-in-project: true
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v4
with:
path: .venv
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}-${{ hashFiles('**/pyproject.toml') }}-${{ hashFiles('**/.pre-commit-config.yaml') }}
# Installing twine in a separate step to prevent circular dependencies and conflicts with cache
- name: Install pip twine
run: pip install --upgrade pip twine
- name: Install dependencies
run: poetry install
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
- name: Build and publish to Pypi
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
poetry version $(git describe --tags --abbrev=0)
poetry build
twine upload dist/* --verbose