Publish dev addon as versioned (#120)

This commit is contained in:
Jesse Hills 2024-04-17 15:32:13 +12:00 committed by GitHub
parent 599905313a
commit db411b1f09
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 88 additions and 159 deletions

View File

@ -18,10 +18,11 @@ jobs:
- uses: actions/checkout@v4.1.1
- uses: actions/setup-python@v4.8.0
with:
python-version: '3.11'
python-version: "3.11"
- run: pip install -r script/requirements.txt
- run: script/bump-version.py ${{ github.event.inputs.version }}
- name: Write Beta changelog
if: ${{ !contains(github.event.inputs.version, 'dev') }}
run: |
cat > esphome-beta/CHANGELOG.md << 'EOF'
## ${{ github.event.inputs.version }}
@ -29,7 +30,7 @@ jobs:
${{ github.event.inputs.content }}
EOF
- name: Write Stable changelog
if: ${{ !contains(github.event.inputs.version, 'b') }}
if: ${{ !contains(github.event.inputs.version, 'b') && !contains(github.event.inputs.version, 'dev') }}
run: |
cat > esphome/CHANGELOG.md << 'EOF'
## ${{ github.event.inputs.version }}
@ -49,6 +50,7 @@ jobs:
- name: Create a Release
uses: actions/create-release@v1.1.4
continue-on-error: true
if: ${{ !contains(github.event.inputs.version, 'dev') }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:

View File

@ -1 +1 @@
See https://esphome.io/changelog/index.html
See https://github.com/esphome/esphome/commits/dev

View File

@ -1,10 +0,0 @@
ARG BUILD_FROM=esphome/esphome-hassio-amd64:dev
FROM ${BUILD_FROM}
# Copy root filesystem
COPY rootfs /
# Labels
LABEL \
io.hass.type="addon" \
io.hass.version=dev

View File

@ -1,5 +0,0 @@
---
build_from:
aarch64: ghcr.io/esphome/esphome-hassio:dev
amd64: ghcr.io/esphome/esphome-hassio:dev
armv7: ghcr.io/esphome/esphome-hassio:dev

View File

@ -33,9 +33,10 @@ backup_exclude:
init: false
startup: services
name: ESPHome (dev)
version: dev
version: 2024.5.0-dev20240411
slug: esphome-dev
description: Development version of ESPHome add-on
image: ghcr.io/esphome/esphome-hassio
stage: experimental
advanced: true
options:

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 69 KiB

View File

@ -1,47 +0,0 @@
#!/usr/bin/with-contenv bashio
# ==============================================================================
# Community Hass.io Add-ons: ESPHome
# This files installs the user ESPHome fork if specified
# The fork must be up to date with the latest ESPHome dev branch
# and have no conflicts
# ==============================================================================
declare esphome_fork
if bashio::config.has_value 'esphome_fork'; then
esphome_fork=$(bashio::config 'esphome_fork')
if [[ $esphome_fork == *":"* ]]; then
IFS=':' read -r -a array <<< "$esphome_fork"
username=${array[0]}
ref=${array[1]}
else
username="esphome"
ref=$esphome_fork
fi
full_url="https://github.com/${username}/esphome/archive/${ref}.tar.gz"
bashio::log.info "Checking forked ESPHome"
dev_version=$(python3 -c "from esphome.const import __version__; print(__version__)")
bashio::log.info "Downloading ESPHome from fork '${esphome_fork}' (${full_url})..."
curl -L -o /tmp/esphome.tar.gz "${full_url}" -qq \
|| bashio::exit.nok "Failed downloading ESPHome fork."
bashio::log.info "Installing ESPHome from fork '${esphome_fork}' (${full_url})..."
rm -rf /esphome || bashio::exit.nok "Failed to remove ESPHome."
mkdir /esphome
tar -zxf /tmp/esphome.tar.gz -C /esphome --strip-components=1 \
|| bashio::exit.nok "Failed installing ESPHome from fork."
pip install -U -e /esphome || bashio::exit.nok "Failed installing ESPHome from fork."
rm -f /tmp/esphome.tar.gz
fork_version=$(python3 -c "from esphome.const import __version__; print(__version__)")
if [[ "$fork_version" != "$dev_version" ]]; then
bashio::log.error "############################"
bashio::log.error "Uninstalled fork as version does not match"
bashio::log.error "Update (or ask the author to update) the branch"
bashio::log.error "This is important as the dev addon and the dev ESPHome"
bashio::log.error "branch can have changes that are not compatible with old forks"
bashio::log.error "and get reported as bugs which we cannot solve easily."
bashio::log.error "############################"
bashio::exit.nok
fi
bashio::log.info "Installed ESPHome from fork '${esphome_fork}' (${full_url})..."
fi

View File

@ -2,7 +2,6 @@
import argparse
import re
import subprocess
from dataclasses import dataclass
import sys
import os
@ -17,72 +16,71 @@ class Version:
minor: int
patch: int
beta: int = 0
dev: bool = False
dev: str = ""
def __str__(self):
return f'{self.major}.{self.minor}.{self.full_patch}'
return f"{self.major}.{self.minor}.{self.full_patch}"
@property
def full_patch(self):
res = f'{self.patch}'
res = f"{self.patch}"
if self.beta > 0:
res += f'b{self.beta}'
res += f"b{self.beta}"
if self.dev:
res += '-dev'
res += f"-dev{self.dev}"
return res
@classmethod
def parse(cls, value):
match = re.match(r'(\d+).(\d+).(\d+)(b\d+)?(-dev)?', value)
match = re.match(r"(\d+).(\d+).(\d+)(b\d+)?(-dev\d+)?", value)
assert match is not None
major = int(match[1])
minor = int(match[2])
patch = int(match[3])
beta = int(match[4][1:]) if match[4] else 0
dev = bool(match[5])
return Version(
major=major, minor=minor, patch=patch,
beta=beta, dev=dev
)
dev = str(match[5][4:]) if match[5] else ""
return Version(major=major, minor=minor, patch=patch, beta=beta, dev=dev)
def sub(path, pattern, repl, expected_count=1):
with open(path) as fh:
def _sub(path, pattern, repl, expected_count=1):
with open(path, encoding="utf-8") as fh:
content = fh.read()
content, count = re.subn(pattern, repl, content, flags=re.MULTILINE)
content, count = re.subn(pattern, repl, content, flags=re.NOFLAG)
if expected_count is not None:
assert count == expected_count, f"Pattern {pattern} replacement failed!"
with open(path, "wt") as fh:
with open(path, "wt", encoding="utf-8") as fh:
fh.write(content)
def write_version(target: str, version: Version):
# version: '1.14.5' # BETA
# version: '1.14.5' # STABLE
sub(
'template/addon_config.yaml',
r" version: '[^']+' # {}".format(target.upper()),
f" version: '{version}' # {target.upper()}"
def _write_version(target: str, version: Version):
# version: "2024.5.0-dev20240412" # DEV
# version: "1.14.5" # BETA
# version: "1.14.5" # STABLE
_sub(
"template/addon_config.yaml",
f' version: "[^"]+" # {target.upper()}',
f' version: "{version}" # {target.upper()}',
)
def main():
parser = argparse.ArgumentParser()
parser.add_argument('new_version', type=str)
parser.add_argument("new_version", type=str)
args = parser.parse_args()
version = Version.parse(args.new_version)
assert not version.dev
print(f"Bumping to {version}")
if version.beta:
write_version('beta', version)
generate.main(['beta'])
if version.dev:
_write_version("dev", version)
generate.main(["dev"])
elif version.beta:
_write_version("beta", version)
generate.main(["beta"])
else:
assert not version.beta
write_version('stable', version)
write_version('beta', version)
generate.main(['stable', 'beta'])
_write_version("stable", version)
_write_version("beta", version)
generate.main(["stable", "beta"])
return 0

View File

@ -1,13 +1,14 @@
#!/usr/bin/env python3
import argparse
import yaml
from pathlib import Path
from enum import Enum
from shutil import copyfile
import sys
import os
import yaml
class Channel(Enum):
stable = "stable"
@ -25,17 +26,16 @@ def main(args):
root = Path(__file__).parent.parent
templ = root / "template"
with open(templ / "addon_config.yaml", "r") as f:
with open(templ / "addon_config.yaml", "r", encoding="utf-8") as f:
config = yaml.safe_load(f)
copyf = config["copy_files"]
for channel in args.channels:
conf = config[f"esphome-{channel.value}"]
base_image = conf.pop("base_image", None)
dir_ = root / conf.pop("directory")
path = dir_ / "config.yaml"
with open(path, "w") as f:
with open(path, "w", encoding="utf-8") as f:
yaml.dump(conf, f, indent=2, sort_keys=False, explicit_start=True)
for file_ in copyf:
@ -46,19 +46,9 @@ def main(args):
copyfile(templ / file_, dir_ / file_)
path = dir_ / "FILES ARE GENERATED DO NOT EDIT"
with open(path, "w") as f:
with open(path, "w", encoding="utf-8") as f:
f.write("Any edits should be made to the files in the 'template' directory")
if channel == Channel.dev:
path = dir_ / "build.yaml"
build_conf = {
"build_from": {
arch: base_image for arch in conf["arch"]
}
}
with open(path, "w") as f:
yaml.dump(build_conf, f, indent=2, sort_keys=True, explicit_start=True)
if __name__ == "__main__":
main(sys.argv[1:])

View File

@ -16,11 +16,11 @@ base: &base
# Ingress settings
ingress: true
ingress_port: 0
panel_icon: 'mdi:chip'
panel_icon: "mdi:chip"
# Automatically add UART devices to add-on
uart: true
ports:
'6052/tcp': null
"6052/tcp": null
map:
- ssl:ro
- config:rw
@ -46,10 +46,11 @@ esphome-dev:
<<: *base
directory: esphome-dev
name: ESPHome (dev)
version: 'dev' # DEV
version: "2024.5.0-dev20240411" # DEV
slug: esphome-dev
description: "Development version of ESPHome add-on"
url: https://next.esphome.io/
image: ghcr.io/esphome/esphome-hassio
stage: experimental
advanced: true
schema:
@ -62,7 +63,6 @@ esphome-dev:
certfile: str?
keyfile: str?
leave_front_door_open: bool?
base_image: ghcr.io/esphome/esphome-hassio:dev
options:
home_assistant_dashboard_integration: false
@ -70,7 +70,7 @@ esphome-beta:
<<: *base
directory: esphome-beta
name: ESPHome (beta)
version: '2024.4.0' # BETA
version: "2024.4.0" # BETA
slug: esphome-beta
description: "Beta version of ESPHome add-on"
url: https://beta.esphome.io/
@ -84,7 +84,7 @@ esphome-stable:
<<: *base
directory: esphome
name: ESPHome
version: '2024.4.0' # STABLE
version: "2024.4.0" # STABLE
slug: esphome
description: "ESPHome add-on for intelligently managing all your ESP8266/ESP32 devices"
image: ghcr.io/esphome/esphome-hassio