-
Notifications
You must be signed in to change notification settings - Fork 4
203 lines (164 loc) · 6.51 KB
/
python-package.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
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
name: Python package and Docker image
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
release:
types: [created]
workflow_dispatch:
inputs:
version_name:
description: 'Version used on testPypi and dockerHub'
required: true
env:
IMAGE_NAME: 'wirepas/wmm_alpine_cpp'
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.9', '3.10', '3.11', '3.12']
steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: Set proto path
run: echo "PROTO_FOLDER=backend-apis/gateway_to_backend/protocol_buffers_files" >> $GITHUB_ENV
- name: Install Protoc
uses: arduino/[email protected]
with:
version: '3.20.3'
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Generate proto files
run: |
protoc -I ${{ env.PROTO_FOLDER }} --python_out=./wirepas_mesh_messaging/proto ${{ env.PROTO_FOLDER }}/*.proto
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
# Use sepcific version of pip as temporary fix for deprecation of setup.py install
# being an error in 23.1
python -m pip install pip==23.0
python -m pip install flake8 pytest setuptools wheel
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --ignore=F821 --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: Install wheel locally
run: pip install .
- name: Test with pytest
run: |
pytest tests/
- name: Get short sha
uses: benjlevesque/[email protected]
id: short-sha
with:
length: 6
- name: Set Version for master push
if: ${{ github.event_name == 'push' }}
run: echo "VERSION=${{ steps.short-sha.outputs.sha }}" >> $GITHUB_ENV
- name: Set Version for release
if: ${{ github.event_name == 'release' }}
run: echo "VERSION=${{ github.event.release.tag_name }}" >> $GITHUB_ENV
- name: Set Version for PR
if: ${{ github.event_name == 'pull_request' }}
run: echo "VERSION=PR_${{ github.event.pull_request.number }}" >> $GITHUB_ENV
- name: Set Version for manual triggering
if: ${{ github.event_name == 'workflow_dispatch' }}
run: echo "VERSION=${{ github.event.inputs.version_name }}" >> $GITHUB_ENV
- name: Set the version
run: |
sed -i '/__version__ = /c\__version__ = "${{ env.VERSION }}"' wirepas_mesh_messaging/__about__.py
- name: Build the wheel
run: python setup.py sdist bdist_wheel
- name: Save produced wheel name and path
run: echo "WHEEL_FILE=$(ls dist/*-py3-none-any.whl)" >> $GITHUB_ENV
- name: Store artifacts only for last matrix version
if: ${{ matrix.python-version == '3.8' }}
uses: actions/upload-artifact@v3
with:
path: ${{ env.WHEEL_FILE }}
# Produced wheels is same independently of python version
- name: Upload Wheel for releases only for last matrix version
if: ${{ github.event_name == 'release' && matrix.python-version == '3.8' }}
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ${{ env.WHEEL_FILE }}
asset_content_type: application/zip
asset_name: wirepas_mesh_messaging-${{ env.VERSION }}-py3-none-any.whl
- name: Publish package to TestPyPI for push to master
if: ${{ github.event_name == 'workflow_dispatch' && matrix.python-version == '3.8' }}
uses: pypa/[email protected]
with:
user: __token__
password: ${{ secrets.PYPI_TEST_PWD }}
repository_url: https://test.pypi.org/legacy/
- name: Publish package to PyPI for release
if: ${{ github.event_name == 'release' && matrix.python-version == '3.8' }}
uses: pypa/[email protected]
with:
user: __token__
password: ${{ secrets.PYPI_PWD }}
docker:
runs-on: ubuntu-latest
needs: build
steps:
- name: checkout code
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Retrieve wheel to be installed image
uses: actions/download-artifact@v2
- name: Set tag for push
if: github.event_name == 'push'
run: |
echo "TAG1=$IMAGE_NAME:edge" >> $GITHUB_ENV
echo "PUSH=true" >> $GITHUB_ENV
- name: Set tag for manually triggered
if: github.event_name == 'workflow_dispatch'
run: |
echo "TAG1=$IMAGE_NAME:${{ github.event.inputs.version_name }}" >> $GITHUB_ENV
echo "PUSH=true" >> $GITHUB_ENV
- name: Set tag for release version
if: github.event_name == 'release'
run: |
echo "TAG1=$IMAGE_NAME:${{ github.event.release.tag_name }}" >> $GITHUB_ENV
echo "PUSH=true" >> $GITHUB_ENV
- name: Set additionnal latest tag also for official release
if: github.event_name == 'release' && !contains(github.event.release.tag_name, 'rc')
run: |
echo "TAG2=$IMAGE_NAME:latest" >> $GITHUB_ENV
echo "PUSH=true" >> $GITHUB_ENV
- name: Do not push on docker hub for pull_request
if: github.event_name == 'pull_request'
run: |
echo "PUSH=false" >> $GITHUB_ENV
- name: Login to docker hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
file: docker/Dockerfile
platforms: linux/amd64, linux/arm64, linux/arm/v7, linux/arm/v6
push: ${{ env.PUSH }}
build-args: WIREPAS_MESH_MESSAGING_BUIL_SHA1=${{ github.sha }}
tags: |
${{ env.TAG1 }}
${{ env.TAG2 }}