-
-
Notifications
You must be signed in to change notification settings - Fork 89
227 lines (221 loc) · 9.07 KB
/
build-0.4.x.x.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
name: Build Test and Release
on:
push:
paths-ignore: [docs/**, README.md, examples/**]
branches: [ 0.4.X.X ]
pull_request:
branches: [ 0.4.X.X ]
jobs:
# ----------------------------------
# BUILD
# ----------------------------------
build:
name: Build on Python ${{matrix.python_version}}
runs-on: ubuntu-latest
strategy:
matrix:
python_version: ['3.7', '3.8', '3.9', '3.10']
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- name: Setup Python ${{matrix.python_version}}
uses: actions/setup-python@v2
with:
python-version: ${{matrix.python_version}}
- name: Install python dependencies
run: |
python -m pip install --upgrade pip
pip install -U setuptools wheel
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Build artifact
run: python setup.py sdist bdist_wheel
# -----------------------------------
# Turn on ENV
# -----------------------------------
turn-on-env:
name: Turn on test environment
runs-on: ubuntu-latest
env:
HOMEASSISTANT_TOKEN: ${{ secrets.HOMEASSISTANT_TOKEN }}
steps:
- name: Powering on the dev-environment
run: |
curl -X POST -k --header "Content-Type: application/json" --header "Authorization: Bearer $HOMEASSISTANT_TOKEN" https://milano.geniola.it/api/services/switch/turn_on -d "{\"entity_id\":\"switch.meross_lab\"}"
# ---------------------------------
# Testing
# ---------------------------------
test:
name: Testing
runs-on: ubuntu-latest
strategy:
matrix:
python_version: ['3.7', '3.8', '3.9', '3.10']
max-parallel: 1
outputs:
failure_rate_python_3_7: ${{steps.pytest.outputs.failure_rate_3_7}}
failure_rate_python_3_8: ${{steps.pytest.outputs.failure_rate_3_8}}
failure_rate_python_3_9: ${{steps.pytest.outputs.failure_rate_3_9}}
failure_rate_python_3_10: ${{steps.pytest.outputs.failure_rate_3_10}}
needs: [build, turn-on-env]
steps:
- uses: actions/checkout@v2
- name: Setup Python ${{matrix.python_version}}
uses: actions/setup-python@v2
with:
python-version: ${{matrix.python_version}}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest --upgrade
pip install pytest-html --upgrade
pip install pytest-cov --upgrade
pip install pytest-json-report --upgrade
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Wait a bit before running tests
run: |
echo "Waiting 120 seconds before starting..."
sleep 120
echo "Waiting done."
- name: Test with pytest
id: pytest
env:
MEROSS_EMAIL: ${{ secrets.MEROSS_EMAIL }}
MEROSS_PASSWORD: ${{ secrets.MEROSS_PASSWORD }}
run: |
pip install .
pip install -r requirements-dev.txt
# Set credentials into memory
TOKEN=$(meross_api_cli auth login --email $MEROSS_EMAIL --password "$MEROSS_PASSWORD" --api-base-url "https://iotx-us.meross.com" | base64 -w0)
# Run test
__MEROSS_CREDS=$TOKEN pytest tests --suppress-tests-failed-exit-code --json-report --doctest-modules --junitxml=junit/test-results.xml --cov=. --cov-report=xml --cov-report=html --html=junit/test-results.html --self-contained-html
# Invalidate token
__MEROSS_CREDS=$TOKEN meross_api_cli auth logout
# Parse test outcomes
total_tests=`cat .report.json | jq .summary.total`
failed_tests=`cat .report.json | jq .summary.failed`
failure_rate=`echo $failed_tests/$total_tests*100 | bc -l`
pythonv=`echo failure_rate_${{ matrix.python_version }} | sed 's/\./_/'`
echo "Setting pythonv=$pythonv"
echo "::set-output name=$pythonv::$failure_rate"
echo "Python ${{ matrix.python_version }}: $failure_rate %" > results-${{ matrix.python_version }}.txt
continue-on-error: true
- name: Upload pytest test TXT results
uses: actions/upload-artifact@v2
with:
name: test-report-${{ matrix.python_version }}
path: results-${{ matrix.python_version }}.txt
# Use always() to always run this step to publish test results when there are test failures
if: ${{ always() }}
- name: Upload pytest test RAW results
uses: actions/upload-artifact@v2
with:
name: pytest-results-${{ matrix.python_version }}
path: junit/
# Use always() to always run this step to publish test results when there are test failures
if: ${{ always() }}
- name: Upload pytest HTML test results
uses: actions/upload-artifact@v2
with:
name: pytest-results-html-${{ matrix.python_version }}
path: htmlcov/
- name: Upload pytest JSON test json results
uses: actions/upload-artifact@v2
with:
name: pytest-results-json-${{ matrix.python_version }}
path: .report.json
# Use always() to always run this step to publish test results when there are test failures
if: ${{ always() }}
# ------------------------------
# Turn off ENV
# ------------------------------
turn-off-env:
name: Turn off test environment
runs-on: ubuntu-latest
env:
HOMEASSISTANT_TOKEN: ${{ secrets.HOMEASSISTANT_TOKEN }}
steps:
- name: Powering on the dev-environment
run: |
curl -X POST -k --header "Content-Type: application/json" --header "Authorization: Bearer $HOMEASSISTANT_TOKEN" https://milano.geniola.it/api/services/switch/turn_off -d "{\"entity_id\":\"switch.meross_lab\"}"
if: ${{ always() }}
# -----------------------------
# Release checks
# -----------------------------
release_checks:
runs-on: ubuntu-latest
needs: [ test ]
outputs:
should_publish: ${{ steps.release_decision.outputs.should_release }}
steps:
- name: Print current configuration
run: |
echo "Python 3.7: ${{ needs.test.outputs.failure_rate_python_3_7 }}%"
echo "Python 3.8: ${{ needs.test.outputs.failure_rate_python_3_8 }}%"
echo "Python 3.9: ${{ needs.test.outputs.failure_rate_python_3_9 }}%"
echo "Python 3.10: ${{ needs.test.outputs.failure_rate_python_3_10 }}%"
- name: Save test output artifacts
run: |
touch "test_pass_rates.txt"
echo "Python 3.7: ${{ needs.test.outputs.failure_rate_python_3_7 }}%" >> "test_pass_rates.txt"
echo "Python 3.8: ${{ needs.test.outputs.failure_rate_python_3_8 }}%" >> "test_pass_rates.txt"
echo "Python 3.9: ${{ needs.test.outputs.failure_rate_python_3_9 }}%" >> "test_pass_rates.txt"
echo "Python 3.10: ${{ needs.test.outputs.failure_rate_python_3_10 }}%" >> "test_pass_rates.txt"
- name: Upload test pass rates
uses: actions/upload-artifact@v2
with:
name: test-pass-rates
path: test_pass_rates.txt
- name: Take release decision
id: release_decision
run: |
failure_threshold=10
echo "Current minimum pass-threshold: $failure_threshold %"
should_release=`echo "${{ needs.test.outputs.failure_rate_python_3_7 }} < $failure_threshold && ${{ needs.test.outputs.failure_rate_python_3_8 }} < $failure_threshold && ${{ needs.test.outputs.failure_rate_python_3_9 }} < $failure_threshold && ${{ needs.test.outputs.failure_rate_python_3_10 }} < $failure_threshold" | bc -l`
echo "::set-output name=should_release::$should_release"
echo "Release decision: $should_release"
if [[ $should_release -ne 1 ]]; then
echo "Failing as one of the tests did hit the maximum failure threshold."
exit 1
fi
# -----------------------------
# Build and Release
# -----------------------------
release:
runs-on: ubuntu-latest
needs: [release_checks]
if: ${{ success() }}
steps:
- uses: actions/checkout@v2
- name: Setup Python 3.10
uses: actions/setup-python@v2
with:
python-version: "3.10"
- name: Install python dependencies
run: |
python -m pip install --upgrade pip
pip install -U setuptools wheel
pip install twine
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Build artifact
run: python setup.py sdist bdist_wheel --universal
- name: Calculate Version
id: tag
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
run: |
TAG=$(cat $GITHUB_WORKSPACE/.version)
echo "Tag: $TAG"
echo "tag=$TAG" >> $GITHUB_ENV
- name: Release on GitHub
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{env.tag}}
release_name: Version ${{env.tag}}
- name: Release on Pypi
env:
TWINE_USERNAME: ${{ secrets.TWINE_USERNAME }}
TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
run: |
twine upload -u "$TWINE_USERNAME" -p "$TWINE_PASSWORD" dist/*