-
Notifications
You must be signed in to change notification settings - Fork 0
184 lines (162 loc) · 5.59 KB
/
python_linting.yml
File metadata and controls
184 lines (162 loc) · 5.59 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
182
183
184
name: Python Linting, Test and Upload
on: [push, pull_request]
jobs:
tests:
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
python-version: ["3.7", "3.10"]
steps:
- uses: actions/checkout@v2
# Setup Python
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
# Install Task
- name: Install Task
run: sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d
# Cached venv
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v2
with:
path: .venv
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
# Install pip and poetry
- name: Install and upgrade pip and poetry
run: |
python -m pip install --upgrade pip poetry
# Install dependencies through task
- name: Install Dependencies
run: |
./bin/task install
# Run our linting
- name: Lint code
run: |
./bin/task lint
# Testing
- name: Test code
run:
./bin/task test
test-publish:
# Will run after the job 'tests'
needs: [tests]
# Important, this job will run only if we tag the source
# code with `git tag -a X.X.X`.
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
# Jobs can have outputs for reuse. We want to reuse
# the version of the package.
outputs:
version: ${{ steps.extract_version.outputs.version }}
steps:
- uses: actions/checkout@v2
# This is something more advanced but a step can have
# outputs which can be used in other steps.
# We extract from the toml file the version here
# and set it in a very very odd syntax as the output.
- name: Remember version
id: extract_version
run: |
VERSION=$(cat pyproject.toml | grep -oE -m 1 "version = \"(.*)\"" | cut -f2 -d '"')
echo "Version: $VERSION"
echo "::set-output name=version::$VERSION"
# For publishing just pick a python version
- name: Set up Python 3.10
uses: actions/setup-python@v2
with:
python-version: "3.10"
- name: Install Task
run: |
sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v2
with:
path: .venv
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
- name: Install Dependencies
run: |
python -m pip install --upgrade pip poetry
./bin/task install
- name: Build packages for release
run: |
./bin/task build
# Here we actually upload to pipy. Poetry can do that on
# its own BUT we use the classic twine here.
# Why? Couse twine can skip existing which avoids any tries
# to upload multiple times.
- name: Publish distribution to Test PyPI
env:
TWINE_REPOSITORY_URL: https://test.pypi.org/legacy/
TWINE_USERNAME: __token__
TWINE_NON_INTERACTIVE: 1
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_API_TOKEN }}
run: poetry run twine upload --skip-existing --verbose 'dist/*'
test-install:
needs: [test-publish]
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
env:
VERSION: ${{ needs.test-publish.outputs.version }}
steps:
# Install python (be aware NO checkout action)
- name: Set up Python 3.10
uses: actions/setup-python@v2
with:
python-version: "3.10"
- name: Install package
run: |
python -m pip install \
--index-url https://test.pypi.org/simple/ \
--extra-index-url https://pypi.org/simple \
professional-python-exercises-2-githubcli=="$VERSION"
publish:
needs: [test-install]
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.10
uses: actions/setup-python@v2
with:
python-version: "3.10"
- name: Install Task
run: |
sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v2
with:
path: .venv
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
- name: Install Dependencies
run: |
python -m pip install --upgrade poetry pip
./bin/task install
- name: Build packages for release
run: |
./bin/task build
# Not required but this saves the distribution files
# with the package upload. You can also do this with
# e.g. log files etc. Can make debugging easier to have
# the real code available just to be sure.
- name: Save packages as artifacts
uses: actions/upload-artifact@v2
with:
name: dist
path: dist
if-no-files-found: error
# Basically the same as for test-pypi but we upload here
# to pypi itself.
- name: Publish distribution to PyPI
env:
TWINE_USERNAME: __token__
TWINE_NON_INTERACTIVE: 1
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: poetry run twine upload --skip-existing --verbose 'dist/*'
# Upload documentation to gh-pages
- name: Upload docs to the gh-pages branch
run: task docs-publish