-
Notifications
You must be signed in to change notification settings - Fork 1
165 lines (157 loc) · 5.38 KB
/
deploy.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# Deployment workflow
# This is a GitHub Actions workflow that tests, builds, and deploys this package.
# Workflow syntax for GitHub Actions
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions
name: Python package automatic deployment
# This workflow will run when the following conditions are met
on:
# Pushes to the main branch
push:
branches: [ "main" ]
# Pull requests that target the main branch
pull_request:
branches: [ "main" ]
release:
types: [ published ]
defaults:
run:
working-directory: ./backend/
jobs:
test-backend:
name: Test backend
# # https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources
runs-on: "ubuntu-22.04"
strategy:
fail-fast: false
matrix:
# https://devguide.python.org/versions/
python-version: ["3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install -e .[test]
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest
- name: Check command line interface
run: |
btviewer --version
build-backend:
name: Build backend
runs-on: ubuntu-22.04
needs:
- test-backend
- build-frontend
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install build tool
run: |
python -m pip install --upgrade pip
python -m pip install build --user
- name: Get frontend distributable files
uses: actions/download-artifact@v4
with:
name: frontend-dist
path: backend/btviewer/static/
- name: Copy files
run: |
cp --verbose ../README* .
cp --verbose ../LICENSE .
cp --verbose ../CITATION.cff .
- name: Build a binary wheel and a source tarball
run: python -m build . --outdir ./dist/
- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: backend/dist/
if-no-files-found: error
# Build frontend user interface
build-frontend:
name: Build frontend
runs-on: ubuntu-22.04
defaults:
run:
working-directory: ./frontend/
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '22'
- name: Clean install the npm project
run: npm ci
# TODO
#- run: npm run lint
#- run: npm test
- run: npm run build
- uses: actions/upload-artifact@v4
with:
name: frontend-dist
path: frontend/dist/
if-no-files-found: error
# OpenID Connect token that the pypi-publish actions needs to implement secretless trusted publishing to PyPI
# https://docs.pypi.org/trusted-publishers/
publish-to-test-pypi:
name: Publish to test PyPI
needs:
- build-backend
- build-frontend
runs-on: ubuntu-22.04
# https://test.pypi.org/manage/project/btviewer/settings/publishing/
environment:
name: testpypi
url: https://test.pypi.org/project/btviewer/
permissions:
# IMPORTANT: mandatory for trusted publishing
id-token: write
steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
# https://github.com/marketplace/actions/pypi-publish
- name: Publish distribution to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
# Don't complain on repeat uploads for the same package version
# https://github.com/marketplace/actions/pypi-publish#tolerating-release-package-file-duplicates
skip-existing: true
verbose: true
publish-to-pypi:
name: Publish to PyPI
# Only publish on tag pushes (releases)
if: startsWith(github.ref, 'refs/tags/')
needs:
- publish-to-test-pypi
runs-on: ubuntu-22.04
environment:
name: pypi
url: https://pypi.org/project/btviewer/
permissions:
id-token: write
steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
# https://github.com/marketplace/actions/pypi-publish
# https://stackoverflow.com/questions/72661025/github-action-publishing-to-both-testpypi-and-pypi-fails#:~:text=PyPI%20doesn't%20allow%20to,get%20File%20already%20exists%20error.&text=GitHub%20actions%20will%20upload%20the,you%20push%20to%20the%20repository.
- name: Publish distribution to PyPI
uses: pypa/gh-action-pypi-publish@release/v1