Skip to content

Commit

Permalink
Merge pull request #21 from brainelectronics/feature/use-enhanced-cicd
Browse files Browse the repository at this point in the history
Use enhanced CICD
  • Loading branch information
brainelectronics authored Oct 23, 2022
2 parents a66ce3e + 26f677b commit 8b72caa
Show file tree
Hide file tree
Showing 12 changed files with 188 additions and 283 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@ permissions:

jobs:
deploy:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Checkout
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.9'
- name: Install dependencies
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements-deploy.txt ]; then pip install -r requirements-deploy.txt; fi
- name: Build package
run: |
python update_version.py \
changelog2version \
--changelog_file changelog.md \
--version_file nextion/version.py \
--version_file_type py \
--debug
python setup.py sdist
- name: Publish package
Expand Down
58 changes: 58 additions & 0 deletions .github/workflows/test-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# this file is *not* meant to cover or endorse the use of GitHub Actions, but rather to
# help make automated releases for this project

name: Upload Python Package to test.pypi.org

on: [pull_request]

permissions:
contents: read

jobs:
test-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.9'
- name: Install build dependencies
run: |
if [ -f requirements-deploy.txt ]; then pip install -r requirements-deploy.txt; fi
- name: Build package
run: |
changelog2version \
--changelog_file changelog.md \
--version_file nextion/version.py \
--version_file_type py \
--additional_version_info="-rc${{ github.run_number }}.dev${{ github.event.number }}" \
--debug
# micropython-nextion is owned by someone else on test.pypi.org
# rename package only for this case
sed -i \
"s/name\='micropython-nextion'/name\='be-micropython-nextion'/" \
setup.py
python setup.py sdist
- name: Test built package
# sdist call creates non twine conform "*.orig" files, remove them
run: |
rm dist/*.orig
twine check dist/*.tar.gz
- name: Archive build package artifact
uses: actions/upload-artifact@v3
with:
# https://docs.github.com/en/actions/learn-github-actions/contexts#github-context
# ${{ github.repository }} and ${{ github.ref_name }} can't be used for artifact name due to unallowed '/'
name: dist_repo.${{ github.event.repository.name }}_sha.${{ github.sha }}_build.${{ github.run_number }}
path: dist/*.tar.gz
retention-days: 14
- name: Publish package
uses: pypa/gh-action-pypi-publish@release/v1.5
with:
repository_url: https://test.pypi.org/legacy/
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
skip_existing: true
verbose: true
print_hash: true
25 changes: 6 additions & 19 deletions .github/workflows/python-test.yml → .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,13 @@ permissions:

jobs:
build:

runs-on: ubuntu-latest
# strategy:
# fail-fast: false
# matrix:
# python-version: ["3.8", "3.9", "3.10"]

steps:
- uses: actions/checkout@v3
- name: Checkout
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
with:
# python-version: ${{ matrix.python-version }}
python-version: '3.9'
- name: Install dependencies
run: |
Expand Down Expand Up @@ -63,20 +57,13 @@ jobs:
if [ -f requirements-deploy.txt ]; then pip install -r requirements-deploy.txt; fi
- name: Build package
run: |
python update_version.py \
changelog2version \
--changelog_file changelog.md \
--version_file nextion/version.py \
--version_file_type py \
--debug
python setup.py sdist
rm dist/*.orig
- name: Test build package
run: |
twine check dist/*.tar.gz
- name: Archive build package artifact
uses: actions/upload-artifact@v3
with:
# https://docs.github.com/en/actions/learn-github-actions/contexts#github-context
# ${{ github.repository }} and ${{ github.ref_name }} can't be used for artifact name due to unallowed '/'
name: dist_repo.${{ github.event.repository.name }}_sha.${{ github.sha }}_build.${{ github.run_number }}
# _py.${{ matrix.python-version }}
path: dist/*.tar.gz
retention-days: 14
twine check dist/*
60 changes: 60 additions & 0 deletions QUICKSTART.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# MicroPython Nextion library

[![Downloads](https://pepy.tech/badge/micropython-nextion)](https://pepy.tech/project/micropython-nextion)
![Release](https://img.shields.io/github/v/release/brainelectronics/micropython-nextion?include_prereleases&color=success)
![MicroPython](https://img.shields.io/badge/micropython-Ok-green.svg)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

MicroPython Nextion library

---------------

## Get started

This is a quickstart guide to flash the
[MicroPython firmware][ref-upy-firmware-download], connect to a network and
install the MicroPython Nextion library on the board

### Flash firmware

```bash
esptool.py --chip esp32 --port /dev/tty.SLAB_USBtoUART erase_flash
esptool.py --chip esp32 --port /dev/tty.SLAB_USBtoUART --baud 921600 write_flash -z 0x1000 esp32spiram-20220117-v1.18.bin
```

### Install package on board with pip

```bash
rshell -p /dev/tty.SLAB_USBtoUART --editor nano
```

Inside the rshell

```bash
cp examples/progressbar/main.py /pyboard
cp examples/boot.py /pyboard
repl
```

Inside the REPL

```python
import machine
import network
import time
import upip

station = network.WLAN(network.STA_IF)
station.active(True)
station.connect('SSID', 'PASSWORD')
time.sleep(1)
print('Device connected to network: {}'.format(station.isconnected()))

upip.install('micropython-nextion')

print('Installation completed')
machine.soft_reset()
```

<!-- Links -->
[ref-upy-firmware-download]: https://micropython.org/download/
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,16 @@ in case no CP210x is used but a CH34x.
rshell --port /dev/tty.SLAB_USBtoUART --editor nano
```

Perform the following command to copy all files and folders to the device
Perform the following command inside the `rshell` to copy all files and
folders to the device

```bash
mkdir /pyboard/lib
mkdir /pyboard/lib/nextion

cp nextion/* /pyboard/lib/nextion

cp examples/main.py /pyboard
cp examples/basic/main.py /pyboard
cp examples/boot.py /pyboard
```

Expand Down
36 changes: 32 additions & 4 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,32 @@ r"^\#\# \[\d{1,}[.]\d{1,}[.]\d{1,}\] \- \d{4}\-\d{2}-\d{2}$"
-->

## Released
## [0.13.0] - 2022-10-23
### Added
- `changelog2version` to [requirements file](requirements-deploy.txt)
- [GitHub CI test release workflow](.github/workflows/test-release.yml) to
deploy package as `be-micropython-nextion` to
[Test Python Package Index](https://test.pypi.org/) on every PR
- [Quickstart guide](QUICKSTART.md)

### Changed
- Use [`changelog2version`][ref-changelog2version-package] to create package
version file, see [#19][ref-issue-19], in:
- [GitHub CI test workflow](.github/workflows/test.yml)
- [GitHub CI release workflow](.github/workflows/release.yml)

### Removed
- Script `update_version.py` to update version file

### Fixed
- Flake8 warning in [`nextion_waveform`](nextion/nextion_waveform.py) and
[`nextion_hardware`](nextion/nextion_hardware.py), see [#17][ref-issue-17]
- Use `self._logger.*` instead of `self._nh._logger.*` in:
- [`nextion_rtc`](nextion/nextion_rtc.py)
- [`nextion_upload`](nextion/nextion_upload.py)
- Path of `main.py` to copy manually to the MicroPython board described in
[`README`](README.md)

## [0.12.0] - 2022-07-30
### Added
- Support `NexRtc` usage with [`nextion_rtc`](nextion/nextion_rtc.py)
Expand Down Expand Up @@ -164,8 +190,9 @@ r"^\#\# \[\d{1,}[.]\d{1,}[.]\d{1,}\] \- \d{4}\-\d{2}-\d{2}$"
- [Example HMI file](examples/everything.HMI) to be used for all examples

<!-- Links -->
[Unreleased]: https://github.com/brainelectronics/micropython-nextion/compare/0.12.0...develop
[Unreleased]: https://github.com/brainelectronics/micropython-nextion/compare/0.13.0...develop

[0.13.0]: https://github.com/brainelectronics/micropython-nextion/tree/0.13.0
[0.12.0]: https://github.com/brainelectronics/micropython-nextion/tree/0.12.0
[0.11.0]: https://github.com/brainelectronics/micropython-nextion/tree/0.11.0
[0.10.0]: https://github.com/brainelectronics/micropython-nextion/tree/0.10.0
Expand All @@ -180,6 +207,7 @@ r"^\#\# \[\d{1,}[.]\d{1,}[.]\d{1,}\] \- \d{4}\-\d{2}-\d{2}$"
[0.2.0]: https://github.com/brainelectronics/micropython-nextion/tree/0.2.0
[0.1.0]: https://github.com/brainelectronics/micropython-nextion/tree/0.1.0

<!--
[ref-issue-1]: https://github.com/brainelectronics/micropython-nextion/issues/1
-->
[ref-issue-17]: https://github.com/brainelectronics/micropython-nextion/issues/17
[ref-issue-19]: https://github.com/brainelectronics/micropython-nextion/issues/19

[ref-changelog2version-package]: https://pypi.org/project/changelog2version/
2 changes: 1 addition & 1 deletion nextion/nextion_hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def recvRetNumber(self, timeout: int = 100) -> int:

if ((temp[0] == Const.NEX_RET_NUMBER_HEAD) and
(temp[5] == 0xFF) and (temp[6] == 0xFF) and (temp[7] == 0xFF)):
number = (temp[4] << 24) | (temp[3] << 16) | (temp[2] << 8) | (temp[1])
number = (temp[4] << 24) | (temp[3] << 16) | (temp[2] << 8) | (temp[1]) # noqa
# ret = True

# if ret:
Expand Down
7 changes: 3 additions & 4 deletions nextion/nextion_rtc.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,8 @@ def write_rtc_time(self, *args, **kwargs) -> bool:
format("2016,11,25,12,34,50",
[2016, 11, 25, 12, 34, 50]))

self._nh._logger.debug("Timestamp (ISO8601): {}-{}-{}T{}:{}:{}".
format(year, month, day, hour, minute,
second))
self._logger.debug("Timestamp (ISO8601): {}-{}-{}T{}:{}:{}".
format(year, month, day, hour, minute, second))

cmd = "rtc0={}".format(year)
self._nh.sendCommand(cmd)
Expand Down Expand Up @@ -122,7 +121,7 @@ def write_rtc_time(self, *args, **kwargs) -> bool:
else:
raise NexRtcError("Either use keyword or positional args")

self._nh._logger.debug("Set '{}' to '{}'".format(time_type, time))
self._logger.debug("Set '{}' to '{}'".format(time_type, time))
rtc_index = self.time_types.index(time_type.lower())

cmd = "rtc{}={}".format(rtc_index, time)
Expand Down
34 changes: 17 additions & 17 deletions nextion/nextion_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def upload(self) -> bool:
if not self._downloadTftFile():
raise NexUploadError("Download file error")

self._nh._logger.debug("Download ok")
self._logger.debug("Download ok")
return True

def _checkFile(self) -> bool:
Expand All @@ -127,13 +127,13 @@ def _checkFile(self) -> bool:
# https://docs.python.org/3/library/os.html#os.stat
info = stat(self.file_name)
self.file_size = info[6]
self._nh._logger.debug("TFT file size is '{}' bytes".
format(self.file_size))
self._nh._logger.debug("File check ok")
self._logger.debug("TFT file size is '{}' bytes".
format(self.file_size))
self._logger.debug("File check ok")
result = True
else:
self._nh._logger.debug("File '{}' does not exist".
format(self.file_name))
self._logger.debug("File '{}' does not exist".
format(self.file_name))
return result

def _getBaudrate(self) -> int:
Expand All @@ -147,13 +147,13 @@ def _getBaudrate(self) -> int:
_baudrate = 0

for baudrate in baudrate_array:
self._nh._logger.debug("Checking connection with '{}' baud".
format(baudrate))
self._logger.debug("Checking connection with '{}' baud".
format(baudrate))

if self._searchBaudrate(baudrate):
_baudrate = baudrate
self._nh._logger.debug("Success, baudrate set to '{}' baud".
format(_baudrate))
self._logger.debug("Success, baudrate set to '{}' baud".
format(_baudrate))
return _baudrate

return _baudrate
Expand All @@ -174,8 +174,8 @@ def _searchBaudrate(self, baudrate: int) -> bool:
self._nh.sendCommand("connect")
sleep(0.1) # necessary, data might not be available otherwise
response = self._recvRetString()
self._nh._logger.debug("_searchBaudrate response for '{}' baud: {}".
format(baudrate, response))
self._logger.debug("_searchBaudrate response for '{}' baud: {}".
format(baudrate, response))

if "comok" in response:
return True
Expand All @@ -193,16 +193,16 @@ def _setDownloadBaudrate(self, baudrate: int) -> bool:
:rtype: bool
"""
cmd = "whmi-wri {},{},0".format(self.file_size, baudrate)
self._nh._logger.debug("Set download baudrate cmd: '{}'".format(cmd))
self._logger.debug("Set download baudrate cmd: '{}'".format(cmd))

self._nh.sendCommand("")
self._nh.sendCommand(cmd)
sleep(0.05)
self._nh._baudrate = baudrate
self._nh._uart_init()
response = self._recvRetString(500)
self._nh._logger.debug("Set download baudrate response: '{}'".
format(response))
self._logger.debug("Set download baudrate response: '{}'".
format(response))
if (0x05).to_bytes(1, 'little') in response:
return True
return False
Expand All @@ -222,13 +222,13 @@ def _downloadTftFile(self) -> bool:
data_size = update_file.readinto(file_content)

if not data_size:
self._nh._logger.debug("Reached EOF, update finished")
self._logger.debug("Reached EOF, update finished")
break

self._nh._uart.write(file_content)

response = self._recvRetString(500)
# self._nh._logger.debug("File download response: '{}'".
# self._logger.debug("File download response: '{}'".
# format(response))

if (0x05).to_bytes(1, 'little') in response:
Expand Down
Loading

0 comments on commit 8b72caa

Please sign in to comment.