Skip to content

Commit

Permalink
Add support for a beta channel
Browse files Browse the repository at this point in the history
This improves the OTA app to parse version numbers better, with the following rules:

- Major, Minor and Patch versions are parsed as numbers rather than strings, so v1.10.0 > v1.9.0
- Development versions where there's a 'number of commits ahead' item are counted as ahead of the version they're on
- If there's an rc after the patch number, it's treated as ahead of the previous version, so v1.9.0 < v1.10.0rc1 < v1.10.0rc1-1-aaaaaa < v1.10.0 < v1.10.0-1-aaaaaa

If there is an rc in the tag name, it won't overwrite the `latest` release, it will overwrite the `preview` release.

The setting `update_channel` will work as normal if unset or set to `latest`. Set it to `preview` to get release candidates.
  • Loading branch information
MatthewWilkes authored and thinkl33t committed Jun 17, 2024
1 parent 6059530 commit b31df33
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
16 changes: 13 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:
micropython/ports/esp32/build-tildagon/tildagon.txt
- name: Create latest release for tags
uses: "marvinpinto/action-automatic-releases@latest"
if: github.event_name == 'push'
if: ${{startsWith(github.event.ref, 'refs/tags/v')} && !contains(github.event.ref, 'rc')}
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: "latest"
Expand All @@ -83,12 +83,22 @@ jobs:
micropython/ports/esp32/build-tildagon/tildagon.txt
- name: Create specific release for tags
uses: "marvinpinto/action-automatic-releases@latest"
if: github.event_name == 'push'
if: ${{startsWith(github.event.ref, 'refs/tags/v')}}
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
files: |
micropython/ports/esp32/build-tildagon/micropython.bin
micropython/ports/esp32/build-tildagon/tildagon.txt
- name: Create latest release for tags
uses: "marvinpinto/action-automatic-releases@latest"
if: ${{startsWith(github.event.ref, 'refs/tags/v')} && contains(github.event.ref, 'rc')}
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: "preview"
title: "Latest release build"
files: |
micropython/ports/esp32/build-tildagon/micropython.bin
micropython/ports/esp32/build-tildagon/tildagon.txt
- name: Build merged image
run: |
source esp-idf/export.sh
Expand All @@ -101,7 +111,7 @@ jobs:
uses: actions/upload-pages-artifact@v3 # or specific "vX.X.X" version tag for this action
with:
path: ./flasher
if: startsWith(github.event.ref, 'refs/tags/v')
if: ${{startsWith(github.event.ref, 'refs/tags/v')} && !contains(github.event.ref, 'rc')}
deploy:
if: startsWith(github.event.ref, 'refs/tags/v')
needs: Build-Firmware
Expand Down
1 change: 1 addition & 0 deletions modules/firmware_apps/settings_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ def settings_options(self):
("pattern", "LED Pattern", string_formatter, None),
("pattern_brightness", "Pattern brightness", pct_formatter, None),
("pattern_mirror_hexpansions", "Mirror pattern", string_formatter, None),
("update_channel", "Update channel", string_formatter, None),
("wifi_tx_power", "WiFi TX power", string_formatter, None),
(
"wifi_connection_timeout",
Expand Down
28 changes: 25 additions & 3 deletions modules/system/ota/ota.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,32 @@
import ntptime
import requests
import wifi
import settings
from system.eventbus import eventbus
from system.scheduler.events import RequestStopAppEvent
from events.input import BUTTON_TYPES, ButtonDownEvent


def parse_version(version):
if "-" in version:
version, ahead, _ = version.split("-")
ahead = int(ahead)
else:
ahead = 0
version = version.strip("v").split(".")
major, minor, patch = version
if "rc" in patch:
patch, rc = patch.split("rc")
patch = int(patch) - 1
patch = patch + float(rc) / 10
else:
patch = int(patch)
major = int(major)
minor = int(minor)
patch = float(patch)
return major, minor, patch, ahead


class OtaUpdate(App):
def __init__(self):
self.status = None
Expand All @@ -26,6 +47,7 @@ def __init__(self):
)
self.layout.y_offset = 70
self.task = None
self.channel = settings.get("update_channel", "latest")
eventbus.on_async(ButtonDownEvent, self._button_handler, self)

async def _button_handler(self, event):
Expand Down Expand Up @@ -119,7 +141,7 @@ async def otaupdate(self, render_update):
self.task = async_helpers.unblock(
requests.head,
render_update,
"https://github.com/emfcamp/badge-2024-software/releases/download/latest/micropython.bin",
f"https://github.com/emfcamp/badge-2024-software/releases/download/{self.channel}/micropython.bin",
allow_redirects=False,
)
response = await self.task
Expand All @@ -129,7 +151,7 @@ async def otaupdate(self, render_update):
self.task = async_helpers.unblock(
requests.get,
render_update,
"https://api.github.com/repos/emfcamp/badge-2024-software/releases/tags/latest",
f"https://api.github.com/repos/emfcamp/badge-2024-software/releases/tags/{self.channel}",
headers={"User-Agent": "Badge OTA"},
)
notes = await self.task
Expand Down Expand Up @@ -180,7 +202,7 @@ def progress(self, version, val):
if not self.confirmed:
if len(version) > 0:
self.new_version.value = version
if version <= ota.get_version():
if parse_version(version) <= parse_version(ota.get_version()):
self.status.value = "No update needed"
return False

Expand Down

0 comments on commit b31df33

Please sign in to comment.