-
Notifications
You must be signed in to change notification settings - Fork 1
219 lines (218 loc) · 6.95 KB
/
python_docker.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# 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 & Docker
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@v4
with:
path: venv/
key: python-venv
- name: Set up Python
if: steps.cache-python-venv.outputs.cache-hit != 'true'
uses: actions/setup-python@v5
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@v4
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@v4
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@v4
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
docker:
name: Docker
needs: [lint, unittest]
if: github.ref_type == 'tag'
runs-on: ubuntu-latest
environment:
name: docker
url: https://registry.digitalservice.id/harbor/projects/82/repositories/datasae
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver: docker
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
registry: registry.digitalservice.id
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
- name: Build and push venv's image
uses: docker/build-push-action@v5
with:
platforms: linux/amd64
target: venv
context: .
cache-from: type=registry,ref=registry.digitalservice.id/datasae/datasae:venv
cache-to: type=inline
tags: registry.digitalservice.id/datasae/datasae:venv
push: true
- name: Build and push app's image
uses: docker/build-push-action@v5
with:
platforms: linux/amd64
target: app
context: .
cache-from: type=registry,ref=registry.digitalservice.id/datasae/datasae:latest
cache-to: type=inline
tags: registry.digitalservice.id/datasae/datasae:latest
push: true
- name: Push app's image with version
run: |
export IMAGE_VERSION=$(docker run --platform linux/amd64 --rm --entrypoint pip registry.digitalservice.id/datasae/datasae:latest show datasae | grep Version | awk '{print $2}')
docker tag registry.digitalservice.id/datasae/datasae:latest registry.digitalservice.id/datasae/datasae:$IMAGE_VERSION
docker push registry.digitalservice.id/datasae/datasae:$IMAGE_VERSION
- name: Show package info
run: docker run --platform linux/amd64 --rm --entrypoint pip registry.digitalservice.id/datasae/datasae:latest show datasae --verbose
docs:
name: Release Docs
needs: [pypi, docker]
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@v4
with:
fetch-depth: 0
- name: Cache venv
uses: actions/cache@v4
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@v4
- name: Upload artifact
uses: actions/upload-pages-artifact@v2
with:
path: 'docs/datasae/'
- name: Deploy to GitHub Pages
id: docs
uses: actions/deploy-pages@v3