-
-
Notifications
You must be signed in to change notification settings - Fork 89
164 lines (155 loc) · 5.78 KB
/
build-dev.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
name: Development Build
on:
push:
paths-ignore: [docs/**, README.md]
branches: [ "development-0.4.X.X" ]
jobs:
# ------------------------------
# Builds the code
# ------------------------------
build:
name: Build on node Python 3.9
outputs:
tag: ${{steps.tag.outputs.tag}}
runs-on: ubuntu-latest
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- name: Setup Python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.9
- 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
- name: Calculate Version
id: tag
run: |
TAG=$(cat $GITHUB_WORKSPACE/.version)$GITHUB_RUN_NUMBER
echo "Tag: $TAG"
echo "::set-output name=tag::$TAG"
# ------------------------------
# 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
needs: [build, turn-on-env]
outputs:
failure_rate: ${{steps.pytest.outputs.failure_rate}}
steps:
- uses: actions/checkout@v2
- name: Setup Python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.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
continue-on-error: true
id: pytest
env:
MEROSS_EMAIL: ${{ secrets.MEROSS_EMAIL }}
MEROSS_EMAIL_MFA: ${{ secrets.MEROSS_EMAIL_MFA }}
MEROSS_PASSWORD: ${{ secrets.MEROSS_PASSWORD }}
run: |
pip install .
# 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`
passed_tests=`cat .report.json | jq .summary.passed`
failed_tests=`cat .report.json | jq .summary.failed`
failure_rate=`echo $failed_tests/$total_tests*100 | bc -l`
echo "::set-output name=failure_rate::$failure_rate"
- name: Upload pytest test results
uses: actions/upload-artifact@v2
with:
name: pytest-results
path: junit/
# Use always() to always run this step to publish test results when there are test failures
if: ${{ always() }}
- name: Upload pytest test results
uses: actions/upload-artifact@v2
with:
name: pytest-results-html
path: htmlcov/
# Use always() to always run this step to publish test results when there are test failures
if: ${{ always() }}
# Upload to CODECOV
- name: codecov-upload
uses: codecov/codecov-action@v2
with:
token: ${{ secrets.CODECOV_TOKEN }}
name: codecov-merossiot-python-dev
flags: unittests
verbose: true
# ------------------------------
# Turn off ENV
# ------------------------------
turn-off-env:
runs-on: ubuntu-latest
needs: [test]
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\"}"
name: Turn off test environment
if: ${{ always() }}
# ------------------------------
# Pre-Release on DEV
# ------------------------------
pre-release:
name: Pre-Release on GitHub
runs-on: ubuntu-latest
needs: [build, test]
# Only publish release if the failure rate is < 10 %
if: needs.test.outputs.failure_rate < 10
steps:
- uses: actions/checkout@v2
- name: Calculate Version
id: tag
run: |
TAG=$(cat $GITHUB_WORKSPACE/.version)
echo "Tag: $TAG"
echo "tag=$TAG" >> $GITHUB_ENV
- name: Create a Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
# The name of the tag. This should come from the webhook payload, `github.GITHUB_REF` when a user pushes a new tag
tag_name: ${{env.tag}}-${{github.RUN_NUMBER}}
# The name of the release. For example, `Release v1.0.1`
release_name: Development release ${{env.tag}}-${{github.RUN_NUMBER}}
# `true` to identify the release as a prerelease. `false` to identify the release as a full release. Default: `false`
prerelease: true