Skip to content

Commit 4eb6a6f

Browse files
authored
Versioning (#182)
* no need for this * run the flow again
1 parent 957b963 commit 4eb6a6f

File tree

4 files changed

+58
-10
lines changed

4 files changed

+58
-10
lines changed

.github/workflows/docker-publish-multi.yml

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,14 @@ jobs:
130130
shell: bash
131131
run: echo "SHORT_SHA=${GITHUB_SHA:0:7}" >> $GITHUB_ENV
132132

133+
- name: Read Docker version tags
134+
shell: bash
135+
run: |
136+
DOCKER_VERSION=$(python3 -c "import json; print(json.load(open('versions.json'))['docker'].split('+', 1)[0])")
137+
echo "DOCKER_VERSION=$DOCKER_VERSION" >> $GITHUB_ENV
138+
echo "DOCKER_VERSION_MINOR=${DOCKER_VERSION%.*}" >> $GITHUB_ENV
139+
echo "DOCKER_VERSION_MAJOR=${DOCKER_VERSION%%.*}" >> $GITHUB_ENV
140+
133141
- name: Set up Depot CLI
134142
uses: depot/setup-action@v1
135143

@@ -178,6 +186,14 @@ jobs:
178186
shell: bash
179187
run: echo "SHORT_SHA=${GITHUB_SHA:0:7}" >> $GITHUB_ENV
180188

189+
- name: Read Docker version tags
190+
shell: bash
191+
run: |
192+
DOCKER_VERSION=$(python3 -c "import json; print(json.load(open('versions.json'))['docker'].split('+', 1)[0])")
193+
echo "DOCKER_VERSION=$DOCKER_VERSION" >> $GITHUB_ENV
194+
echo "DOCKER_VERSION_MINOR=${DOCKER_VERSION%.*}" >> $GITHUB_ENV
195+
echo "DOCKER_VERSION_MAJOR=${DOCKER_VERSION%%.*}" >> $GITHUB_ENV
196+
181197
- name: Set up Depot CLI
182198
uses: depot/setup-action@v1
183199

@@ -192,7 +208,9 @@ jobs:
192208
platforms: linux/amd64,linux/arm64/v8
193209
tags: |
194210
frameos/frameos:${{ env.BRANCH_NAME }}-${{ env.SHORT_SHA }}
195-
frameos/frameos:latest
211+
frameos/frameos:${{ env.DOCKER_VERSION }}
212+
frameos/frameos:${{ env.DOCKER_VERSION_MINOR }}
213+
frameos/frameos:${{ env.DOCKER_VERSION_MAJOR }}
196214
197215
update-addon-repo:
198216
name: Update Home Assistant Addon
@@ -216,19 +234,24 @@ jobs:
216234
shell: bash
217235
run: echo "SHORT_SHA=${GITHUB_SHA:0:7}" >> $GITHUB_ENV
218236

237+
- name: Read Docker version
238+
shell: bash
239+
run: |
240+
DOCKER_VERSION=$(python3 -c "import json; print(json.load(open('versions.json'))['docker'].split('+', 1)[0])")
241+
echo "DOCKER_VERSION=$DOCKER_VERSION" >> $GITHUB_ENV
242+
219243
- name: Update version in config.yaml
220244
run: |
221245
cd home-assistant-addon/frameos
222-
echo "Updating version in config.yaml to ${{ env.BRANCH_NAME }}-${{ env.SHORT_SHA }}"
223-
sed -i "s/^version: .*/version: ${{ env.BRANCH_NAME }}-${{ env.SHORT_SHA }}/" config.yaml
246+
echo "Updating version in config.yaml to ${{ env.DOCKER_VERSION }}"
247+
sed -i "s/^version: .*/version: ${{ env.DOCKER_VERSION }}/" config.yaml
224248
225249
- name: Commit changes
226250
uses: EndBug/add-and-commit@v9
227251
with:
228-
message: "Update FrameOS version to ${{ env.BRANCH_NAME }}-${{ env.SHORT_SHA }}"
252+
message: "Update FrameOS version to ${{ env.DOCKER_VERSION }}"
229253
add: "."
230254
cwd: home-assistant-addon
231255
push: true
232256
author_name: FrameOS Bot
233257
author_email: git@frameos.net
234-

.github/workflows/e2e-docker.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
name: E2E Docker Image
22

33
on:
4-
push:
5-
branches: [ "main" ]
64
pull_request:
75
branches: [ "main" ]
86

frameos/src/frameos/scheduler.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import sequtils
88

99
var thread: Thread[FrameOS]
1010

11-
# Returns the weekday as 1=Monday .. 7=Sunday
11+
# Returns the weekday as 1=Monday..7=Sunday
1212
proc weekdayMonSun(dt: DateTime): int =
1313
return dt.weekday.ord + 1
1414

tools/update_versions.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,20 @@ def _next_calver(previous: str | None, today: dt.date) -> str:
103103
return f"{today.year}.{today.month}.0"
104104

105105

106+
def _max_base_version(versions: Dict[str, str]) -> str | None:
107+
if not versions:
108+
return None
109+
bases = [value.split("+", 1)[0] for value in versions.values() if value]
110+
if not bases:
111+
return None
112+
return max(bases, key=_parse_version)
113+
114+
115+
def _increment_base_version(version: str) -> str:
116+
year, month, patch = _parse_version(version)
117+
return f"{year}.{month}.{patch + 1}"
118+
119+
106120
def main() -> int:
107121
projects_config = json.loads(PROJECTS_FILE.read_text(encoding="utf-8"))
108122
tracked_files = _git_tracked_files()
@@ -115,6 +129,9 @@ def main() -> int:
115129
updated_versions: Dict[str, str] = dict(existing_versions)
116130
today = dt.datetime.utcnow().date()
117131

132+
project_hashes: Dict[str, str] = {}
133+
changed_projects: List[str] = []
134+
118135
for project_name, config in projects_config["projects"].items():
119136
includes = config.get("include", [])
120137
excludes = config.get("exclude", [])
@@ -126,15 +143,25 @@ def main() -> int:
126143
]
127144

128145
project_hash = _hash_files(project_files)
146+
project_hashes[project_name] = project_hash
129147
previous = existing_versions.get(project_name)
130148
previous_hash = previous.split("+", 1)[1] if previous and "+" in previous else None
131149

132150
if previous_hash == project_hash:
133151
updated_versions[project_name] = previous
134152
continue
135153

136-
next_version = _next_calver(previous, today)
137-
updated_versions[project_name] = f"{next_version}+{project_hash}"
154+
changed_projects.append(project_name)
155+
156+
if changed_projects:
157+
max_existing_base = _max_base_version(existing_versions)
158+
if max_existing_base:
159+
next_version = _increment_base_version(max_existing_base)
160+
else:
161+
next_version = _next_calver(None, today)
162+
163+
for project_name in changed_projects:
164+
updated_versions[project_name] = f"{next_version}+{project_hashes[project_name]}"
138165

139166
ordered_projects = list(projects_config["projects"].keys())
140167
ordered_versions = {name: updated_versions[name] for name in ordered_projects if name in updated_versions}

0 commit comments

Comments
 (0)