-
Notifications
You must be signed in to change notification settings - Fork 1
169 lines (168 loc) · 4.91 KB
/
python.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
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
# Copyright (C) Free Software Foundation, Inc. All rights reserved.
# Licensed under the AGPL-3.0-only License. See LICENSE in the project root
# for license information.
name: Python
on:
pull_request:
push:
branches: ['**']
tags:
- '[0-9]+.[0-9]+.[0-9]+'
- '[0-9]+.[0-9]+.[0-9]+-[a-z]+'
- '[0-9]+.[0-9]+.[0-9]+-[a-z]+.[0-9]+'
jobs:
venv:
name: Virtual Environment
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Cache venv
id: cache-python-venv
uses: actions/cache@v3
with:
path: venv/
key: python-venv
- name: Set up Python
if: steps.cache-python-venv.outputs.cache-hit != 'true'
uses: actions/setup-python@v4
with:
python-version: '3.8'
- name: Install dependencies
if: steps.cache-python-venv.outputs.cache-hit != 'true'
run: |
python -m venv venv/
. venv/bin/activate
pip install --upgrade pip
pip install toml build 'coverage[toml]' pdoc3 flake8 flake8-docstrings
python -c 'import toml; c = toml.load("pyproject.toml"); print("\n".join([*c["project"].get("dependencies", []), *[row for optional_dependency in c["project"].get("optional-dependencies", {}).values() for row in optional_dependency]]))' > /tmp/requirements.txt
pip install -r /tmp/requirements.txt
lint:
name: Linter Test
needs: venv
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Cache venv
uses: actions/cache@v3
with:
path: venv/
key: python-venv
- name: Lint with flake8
run: |
. venv/bin/activate
python -m flake8 --exclude build/,venv/
unittest:
name: Unit Test
needs: venv
runs-on: ubuntu-latest
permissions:
pull-requests: write
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Cache venv
uses: actions/cache@v3
with:
path: venv/
key: python-venv
- name: Activate venv
run: |
. venv/bin/activate
echo PATH=$PATH >> $GITHUB_ENV
- name: Install package
run: pip install '.[converter,gsheet,s3,sql]'
- name: Test
run: python -m coverage run -m unittest
- name: Display coverage
run: python -m coverage report -m
- name: Coverage comment
if: github.ref_type != 'tag'
uses: py-cov-action/python-coverage-comment-action@v3
with:
GITHUB_TOKEN: ${{ github.token }}
- name: Test coverage must be 100% passed!
if:
github.ref_type == 'tag' ||
github.event_name == 'pull_request' ||
contains('refs/heads/main refs/heads/develop', github.ref) ||
startsWith(github.ref, 'refs/heads/release/') ||
startsWith(github.ref, 'refs/heads/hotfix/')
run: if [ $(printf '%.0f' $(python -m coverage report | awk '$1 == "TOTAL" {print $NF+0}')) = 100 ]; then exit; else exit 1; fi
pypi:
name: PyPI
needs: [lint, unittest]
if: github.ref_type == 'tag'
runs-on: ubuntu-latest
environment:
name: python
url: https://pypi.org/project/${{ github.event.repository.name }}/
permissions:
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Cache venv
uses: actions/cache@v3
with:
path: venv/
key: python-venv
- name: Build package
run: |
. venv/bin/activate
python -m build
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
skip-existing: true
docs:
name: Release Docs
needs: pypi
runs-on: ubuntu-latest
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: pages
cancel-in-progress: false
environment:
name: github-pages
url: ${{ steps.docs.outputs.page_url }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Cache venv
uses: actions/cache@v3
with:
path: venv/
key: python-venv
- name: Generate docs
run: |
. venv/bin/activate
pip install '.[converter,gsheet,s3,sql]'
python -m pdoc \
datasae \
--html \
--force \
-o docs/
- name: Setup Pages
uses: actions/configure-pages@v3
- name: Upload artifact
uses: actions/upload-pages-artifact@v2
with:
path: 'docs/datasae/'
- name: Deploy to GitHub Pages
id: docs
uses: actions/deploy-pages@v2