-
-
Notifications
You must be signed in to change notification settings - Fork 267
233 lines (221 loc) · 8.41 KB
/
build-and-push.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
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
name: CI & CD
# Reference:
# https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#on
on: [push, pull_request]
env:
docker_image_name: rbonghi/jetson_stats
# Reference
# https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions
jobs:
auto_style:
name: Auto style code
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install autopep8
run: |
python -m pip install --upgrade pip
pip install flake8 autopep8
- name: Auto style code with autopep8
run: autopep8 --in-place --aggressive --aggressive --recursive . --max-line-length 180
- name: Check for changes
run: |
if [[ `git status --porcelain` ]]; then
echo "There are changes after auto-styling the code."
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add .
git commit -m "Auto style code with autopep8"
git push
else
echo "No changes detected."
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build:
name: Test on python ${{ matrix.python-version }}
runs-on: ubuntu-latest
needs: [auto_style]
strategy:
# max-parallel: 1
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
steps:
- run: echo "Branch $GITHUB_REF"
- 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: |
# Make group jtop
sudo groupadd jtop
# Upgrade pip
# https://github.com/actions/setup-python/issues/225
sudo -H env "PATH=$PATH" python -m pip install --upgrade pip
# Install tox
# https://github.com/actions/setup-python/issues/225
sudo -H env "PATH=$PATH" pip install tox
- name: Display Python version
run: sudo env "PATH=$PATH" python -c "import sys; print(sys.version)"
- name: Test with tox
run: |
# https://github.com/actions/setup-python/issues/225
sudo env "PATH=$PATH" tox -e py${{ matrix.python-version }}
docker:
name: "Build Docker image develop"
runs-on: ubuntu-latest
needs: [build]
steps:
# https://github.com/docker/build-push-action/blob/master/docs/advanced/tags-labels.md
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
# https://github.com/docker/metadata-action/issues/123
github-token: ${{ secrets.GITHUB_TOKEN }}
images: ${{ env.docker_image_name }}
# generate Docker tags based on the following events/attributes
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=ref,event=tag
type=ref,event=pr
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
if: |
github.actor != 'dependabot[bot]' &&
github.event_name != 'pull_request' &&
!startsWith(github.ref, 'refs/heads/feature/') &&
!contains(github.ref, '.dev') &&
!contains(github.ref, 'rc')
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
id: docker_build
uses: docker/[email protected]
with:
push: |
${{ github.actor != 'dependabot[bot]' &&
github.event_name != 'pull_request' &&
!startsWith(github.ref, 'refs/heads/feature/') &&
!contains(github.ref, '.dev') &&
!contains(github.ref, 'rc')
}}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64, linux/arm64
docs:
name: Documentation
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Build sphinx
# Manual build documentation
# Follow https://github.com/ammaraskar/sphinx-action/issues/43#issuecomment-1218439431
run: |
# Upgrade pip
# https://github.com/actions/setup-python/issues/225
# sudo -H env "PATH=$PATH" python -m pip install --upgrade pip --break-system-packages
# Install jtop
sudo -H env "PATH=$PATH" pip install -v -e .
# Install sphinx requirements
sudo -H env "PATH=$PATH" pip install -r docs/requirements.txt
# Run sphinx
cd docs
sphinx-build -b html -W . _build/html
- name: Export website
id: export_website
if: ${{ !startsWith(github.ref, 'refs/heads/master') }}
uses: actions/upload-artifact@v4
with:
name: html
path: docs/_build/html # The folder the action should deploy.
- name: Deploy on branch
if: startsWith(github.ref, 'refs/heads/master') || (startsWith(github.ref, 'refs/tags/') && !contains(github.ref, '.dev') && !contains(github.ref, 'rc'))
# Follow: https://github.com/marketplace/actions/deploy-to-github-pages
uses: JamesIves/github-pages-deploy-action@releases/v3
with:
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
BRANCH: gh-pages # The branch the action should deploy to.
FOLDER: docs/_build/html # The folder the action should deploy.
update_docker_description:
name: Update docker description
if: startsWith(github.ref, 'refs/heads/master') || (startsWith(github.ref, 'refs/tags/') && !contains(github.ref, '.dev') && !contains(github.ref, 'rc'))
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Docker Hub Description # https://github.com/peter-evans/dockerhub-description
uses: peter-evans/dockerhub-description@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
repository: rbonghi/jetson_stats
short-description: ${{ github.event.repository.description }}
readme-filepath: ./README.md
deploy:
name: Deploy on PIP
needs: [build, docker]
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install dependencies
run: |
# sudo -H python -m pip install --upgrade pip
sudo -H pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
sudo python setup.py sdist
twine upload dist/*
notify:
name: "Notify socials"
needs: [deploy, docs]
runs-on: ubuntu-latest
steps:
- name: Repository status
id: repo_status
shell: bash
run: |
if ${{ startsWith(github.ref, 'refs/tags/') }} ; then
TAG_RELEASE=${GITHUB_REF/refs\/tags\//}
else
TAG_RELEASE=${GITHUB_REF/refs\/heads\//}
fi
echo ::set-output name=tag::${TAG_RELEASE}
echo "tag=${TAG_RELEASE}"
- name: Discord notification
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
uses: Ilshidur/action-discord@master
with:
args: "jetson-stats **${{ steps.repo_status.outputs.tag }}** has been deployed!\nTo install `sudo pip3 install jetson-stats==${{ steps.repo_status.outputs.tag }}`"
- name: Send telegram message
uses: appleboy/telegram-action@master
with:
to: ${{ secrets.TELEGRAM_TO }}
token: ${{ secrets.TELEGRAM_TOKEN }}
message: |
jetson-stats **${{ steps.repo_status.outputs.tag }}** has been deployed!
See changes: https://github.com/${{ github.repository }}/releases/latest