Skip to content

Commit 4de930d

Browse files
committed
templating and automation
1 parent 3208a43 commit 4de930d

27 files changed

+505
-38
lines changed

.github/workflows/bump-version.yml

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Publish Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: The version to release
8+
required: true
9+
content:
10+
description: The content of the release-notes
11+
required: true
12+
13+
jobs:
14+
create-release:
15+
runs-on: ubuntu-latest
16+
continue-on-error: true
17+
steps:
18+
- uses: actions/[email protected]
19+
- uses: actions/setup-python@v4
20+
with:
21+
python-version: '3.x'
22+
- run: pip install -r script/requirements.txt
23+
- run: script/bump-version.py ${{ github.event.inputs.version }}
24+
- name: Write Beta changelog
25+
run: |
26+
cat > typedaemon-beta/CHANGELOG.md << 'EOF'
27+
## ${{ github.event.inputs.version }}
28+
29+
${{ github.event.inputs.content }}
30+
EOF
31+
- name: Write Stable changelog
32+
if: ${{ !contains(github.event.inputs.version, 'b') }}
33+
run: |
34+
cat > typedaemon/CHANGELOG.md << 'EOF'
35+
## ${{ github.event.inputs.version }}
36+
37+
${{ github.event.inputs.content }}
38+
EOF
39+
- name: Commit version bump
40+
id: commit_version
41+
run: |
42+
git config user.name typedaemonbot
43+
git config user.email [email protected]
44+
git add .
45+
git commit -m "Bump version to ${{ github.event.inputs.version }}"
46+
git push
47+
COMMIT=$(git rev-parse HEAD)
48+
echo "::set-output name=commit_sha::${COMMIT}"
49+
- name: Create a Release
50+
uses: actions/[email protected]
51+
continue-on-error: true
52+
env:
53+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
54+
with:
55+
tag_name: ${{ github.event.inputs.version }}
56+
release_name: ${{ github.event.inputs.version }}
57+
body: ${{ github.event.inputs.content }}
58+
prerelease: ${{ contains(github.event.inputs.version, 'b') }}
59+
commitish: ${{ steps.commit_version.outputs.commit_sha }}

script/bump-version.py

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/usr/bin/env python3
2+
3+
import argparse
4+
import re
5+
import subprocess
6+
from dataclasses import dataclass
7+
import sys
8+
import os
9+
10+
sys.path.append(os.path.dirname(__file__))
11+
import generate
12+
13+
14+
@dataclass
15+
class Version:
16+
major: int
17+
minor: int
18+
patch: int
19+
beta: int = 0
20+
dev: bool = False
21+
22+
def __str__(self):
23+
return f'{self.major}.{self.minor}.{self.full_patch}'
24+
25+
@property
26+
def full_patch(self):
27+
res = f'{self.patch}'
28+
if self.beta > 0:
29+
res += f'b{self.beta}'
30+
if self.dev:
31+
res += '-dev'
32+
return res
33+
34+
@classmethod
35+
def parse(cls, value):
36+
match = re.match(r'(\d+).(\d+).(\d+)(b\d+)?(-dev)?', value)
37+
assert match is not None
38+
major = int(match[1])
39+
minor = int(match[2])
40+
patch = int(match[3])
41+
beta = int(match[4][1:]) if match[4] else 0
42+
dev = bool(match[5])
43+
return Version(
44+
major=major, minor=minor, patch=patch,
45+
beta=beta, dev=dev
46+
)
47+
48+
49+
def sub(path, pattern, repl, expected_count=1):
50+
with open(path) as fh:
51+
content = fh.read()
52+
content, count = re.subn(pattern, repl, content, flags=re.MULTILINE)
53+
if expected_count is not None:
54+
assert count == expected_count, f"Pattern {pattern} replacement failed!"
55+
with open(path, "wt") as fh:
56+
fh.write(content)
57+
58+
59+
def write_version(target: str, version: Version):
60+
# version: '1.14.5' # BETA
61+
# version: '1.14.5' # STABLE
62+
sub(
63+
'template/addon_config.yaml',
64+
r" version: '[^']+' # {}".format(target.upper()),
65+
f" version: '{version}' # {target.upper()}"
66+
)
67+
68+
69+
def main():
70+
parser = argparse.ArgumentParser()
71+
parser.add_argument('new_version', type=str)
72+
args = parser.parse_args()
73+
74+
version = Version.parse(args.new_version)
75+
assert not version.dev
76+
77+
print(f"Bumping to {version}")
78+
if version.beta:
79+
write_version('beta', version)
80+
generate.main(['beta'])
81+
else:
82+
assert not version.beta
83+
write_version('stable', version)
84+
write_version('beta', version)
85+
generate.main(['stable', 'beta'])
86+
return 0
87+
88+
89+
if __name__ == "__main__":
90+
sys.exit(main() or 0)

script/generate.py

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env python3
2+
3+
import argparse
4+
import yaml
5+
from pathlib import Path
6+
from enum import Enum
7+
from shutil import copyfile
8+
import sys
9+
import os
10+
11+
12+
class Channel(Enum):
13+
stable = "stable"
14+
beta = "beta"
15+
edge = "edge"
16+
17+
18+
def main(args):
19+
parser = argparse.ArgumentParser(
20+
description="Generate ESPHome Home Assistant config.json"
21+
)
22+
parser.add_argument("channels", nargs="+", type=Channel, choices=list(Channel))
23+
args = parser.parse_args(args)
24+
25+
root = Path(__file__).parent.parent
26+
templ = root / "template"
27+
28+
with open(templ / "addon_config.yaml", "r") as f:
29+
config = yaml.safe_load(f)
30+
31+
copyf = config["copy_files"]
32+
33+
for channel in args.channels:
34+
conf = config[f"typedaemon-{channel.value}"]
35+
base_image = conf.pop("base_image", None)
36+
dir_ = root / conf.pop("directory")
37+
path = dir_ / "config.yaml"
38+
39+
os.makedirs(dir_, exist_ok=True)
40+
41+
with open(path, "w") as f:
42+
yaml.dump(conf, f, indent=2, sort_keys=False, explicit_start=True)
43+
44+
for file_ in copyf:
45+
os.makedirs(dir_ / Path(file_).parent, exist_ok=True)
46+
if Path.exists(templ / channel.value / file_):
47+
copyfile(templ / channel.value / file_, dir_ / file_)
48+
else:
49+
copyfile(templ / file_, dir_ / file_)
50+
51+
path = dir_ / "FILES ARE GENERATED DO NOT EDIT"
52+
with open(path, "w") as f:
53+
f.write("Any edits should be made to the files in the 'template' directory")
54+
55+
if channel == Channel.edge:
56+
path = dir_ / "build.yaml"
57+
build_conf = {
58+
"build_from": {
59+
arch: base_image for arch in conf["arch"]
60+
}
61+
}
62+
with open(path, "w") as f:
63+
yaml.dump(build_conf, f, indent=2, sort_keys=True, explicit_start=True)
64+
65+
66+
if __name__ == "__main__":
67+
main(sys.argv[1:])

script/requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
PyYAML==6.0.1

template/DOCS.md

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# TypeDaemon Add-on
2+
## Installation
3+
4+
The installation of this add-on is pretty straightforward and not different in comparison to installing any other Home Assistant add-on.
5+
6+
1. Add the https://github.com/Matchlighter/typedaemon-hassio repository by:
7+
1. Navigating to Home Assistant Settings > Addons > Add-on Store
8+
2. Access the kebab menu in the upper right, and select "Repositories"
9+
3. Paste `https://github.com/Matchlighter/typedaemon-hassio` in the "Add" field, then click "ADD".
10+
2. Reload the page
11+
3. Find the TypeDaemon section and select the TypeDaemon addon
12+
4. Install it
13+
14+
## Configuration
15+
16+
**Note**: _Remember to restart the add-on when the configuration is changed._
17+
18+
Example add-on configuration:
19+
20+
```json
21+
{
22+
23+
}
24+
```

template/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# TypeDaemon Add-On

template/addon_config.yaml

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
---
2+
# When changing options in this file, please also run:
3+
# python3 script/generate.py edge
4+
# to update the edge addon config (beta/stable configs will be updated on next release by release script)
5+
base: &base
6+
url: https://github.com/matchlighter/typedaemon
7+
description: Typescript-based Automations, Services, and Entities
8+
9+
panel_icon: mdi:graph
10+
11+
init: false
12+
homeassistant: 2021.3.0
13+
14+
arch:
15+
- amd64
16+
- armhf
17+
- armv7
18+
# - aarch64
19+
# - i386
20+
21+
ingress: true
22+
ingress_port: 0
23+
ingress_stream: true
24+
host_network: false
25+
ports:
26+
80/tcp: 1880
27+
9000/tcp: 9000
28+
ports_description:
29+
80/tcp: Web interface
30+
9000/tcp: Http interface/API
31+
32+
hassio_api: false
33+
homeassistant_api: true
34+
auth_api: true
35+
36+
uart: false
37+
38+
map:
39+
- config:rw
40+
- media:rw
41+
- share:rw
42+
43+
services:
44+
- mqtt:want
45+
46+
environment:
47+
TYPEDAEMON_CONFIG: /config/typedaemon
48+
49+
options: {}
50+
schema: {}
51+
52+
typedaemon-edge:
53+
<<: *base
54+
directory: typedaemon-edge
55+
name: TypeDaemon (edge)
56+
version: 'edge'
57+
slug: typedaemon-edge
58+
description: "Development version of TypeDaemon add-on"
59+
stage: experimental
60+
advanced: true
61+
image: ghcr.io/matchlighter/typedaemon
62+
base_image: ghcr.io/matchlighter/typedaemon:edge
63+
options:
64+
home_assistant_dashboard_integration: false
65+
66+
typedaemon-beta:
67+
<<: *base
68+
directory: typedaemon-beta
69+
name: TypeDaemon (beta)
70+
version: '0.1.0' # BETA
71+
slug: typedaemon-beta
72+
description: "Beta version of TypeDaemon add-on"
73+
image: ghcr.io/matchlighter/typedaemon
74+
stage: experimental
75+
advanced: true
76+
options:
77+
home_assistant_dashboard_integration: false
78+
79+
typedaemon-stable:
80+
<<: *base
81+
directory: typedaemon
82+
name: TypeDaemon
83+
version: '0.1.0' # STABLE
84+
slug: typedaemon
85+
image: ghcr.io/matchlighter/typedaemon
86+
87+
copy_files:
88+
- DOCS.md
89+
# - icon.png
90+
# - logo.png
91+
- README.md
92+
- translations/en.yaml

template/dev/DOCS.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# TypeDaemom DEV add on
2+
3+
This is **development** version of the TypeDaemom add on.
4+
5+
To deploy production nodes please use mainstream release add on.
6+
7+
The add on uses a version of TypeDaemom built automatically every push and is used to test components in development.
8+
9+
## Configuration
10+
11+
**Note**: _Remember to restart the add-on when the configuration is changed._
12+
13+
## General TypeDaemom add on configurations
14+
15+
General options also available in other versions.
16+
17+

template/translations/en.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
configuration: {}
3+
network: {}

typedaemon-beta/DOCS.md

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# TypeDaemon Add-on
2+
## Installation
3+
4+
The installation of this add-on is pretty straightforward and not different in comparison to installing any other Home Assistant add-on.
5+
6+
1. Add the https://github.com/Matchlighter/typedaemon-hassio repository by:
7+
1. Navigating to Home Assistant Settings > Addons > Add-on Store
8+
2. Access the kebab menu in the upper right, and select "Repositories"
9+
3. Paste `https://github.com/Matchlighter/typedaemon-hassio` in the "Add" field, then click "ADD".
10+
2. Reload the page
11+
3. Find the TypeDaemon section and select the TypeDaemon addon
12+
4. Install it
13+
14+
## Configuration
15+
16+
**Note**: _Remember to restart the add-on when the configuration is changed._
17+
18+
Example add-on configuration:
19+
20+
```json
21+
{
22+
23+
}
24+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Any edits should be made to the files in the 'template' directory

typedaemon-beta/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# TypeDaemon Add-On

0 commit comments

Comments
 (0)