Skip to content

Commit

Permalink
[FEATURE] Publish version information for update check
Browse files Browse the repository at this point in the history
  • Loading branch information
mjonuschat committed Dec 21, 2024
1 parent ed8737e commit 4c0da1f
Show file tree
Hide file tree
Showing 2 changed files with 153 additions and 0 deletions.
108 changes: 108 additions & 0 deletions .github/scripts/create_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#!/usr/bin/env python3

import json
import argparse
import re

from pathlib import Path
from urllib.request import urlopen

RELEASES_URL = "https://api.github.com/repos/mjonuschat/PrusaSlicer/releases"
VERSION_PATTERN = re.compile(
r"version_(?P<version>\d+\.\d+\.\d+)(-(?P<suffix>(alpha|beta|rc)\d+))?\+boss"
)


def main():
parser = argparse.ArgumentParser()
parser.add_argument("output", help="Write version information to this file")
args = parser.parse_args()

with urlopen(RELEASES_URL) as response:
body = response.read()
releases = json.loads(body)


versions = {}
assets = {}

for release in releases:
if release.get("draft", True):
continue
if not (tag := release.get("tag_name", "")):
continue
if not (match := VERSION_PATTERN.fullmatch(tag)):
continue

version = match.group("version")
suffix = match.group("suffix") or ""

if suffix.startswith("rc"):
kind = "rc"
full_version = f"{version}-{suffix}"
elif suffix.startswith("beta"):
kind = "beta"
full_version = f"{version}-{suffix}"
elif suffix.startswith("alpha"):
kind = "alpha"
full_version = f"{version}-{suffix}"
else:
kind = "release"
full_version = version

if versions.get(kind, "") < full_version:
versions[kind] = full_version

if kind == "release":
for asset in release.get("assets", {}):
name = asset.get("name", "")
if not name:
continue

if "Linux" in name:
assets["linux"] = asset
if "MacOS-universal" in name:
assets["osx"] = asset
if "win64" in name:
assets["win64"] = asset

contents = []
if version := versions.get("release"):
contents.append(version)
if version := versions.get("alpha"):
contents.append(f"alpha={version}")
if version := versions.get("beta"):
contents.append(f"beta={version}")
contents.append("")

contents.append("[common]")
for kind in ["release", "alpha", "beta", "rc"]:
if version := versions.get(kind, ""):
contents.append(f"{kind} = {version}")

contents.append("")
for os in ["win64", "linux", "osx"]:
if not (asset := assets.get(os, {})):
continue

if not (url := asset.get("browser_download_url", "")):
continue

if not (size := asset.get("size", 0)):
continue

contents.append(f"[release:{os}]")
contents.append(f"url = {url}")
match os:
case "osx":
contents.append(f"size = {size}")
case _:
contents.append("action = browser")
contents.append("")

with open(Path(args.output), 'w', encoding="utf-8") as f:
print("\n".join(contents), file=f)


if __name__ == "__main__":
main()
45 changes: 45 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Simple workflow for deploying version information to GitHub Pages
name: Publish Version Information

on:
release:
types: [published, unpublished]

workflow_dispatch:

permissions:
contents: read
pages: write
id-token: write

concurrency:
group: "pages"
cancel-in-progress: false

jobs:
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Pages
uses: actions/configure-pages@v5

- name: Create Version File
working-directory: ${{ github.workspace }}
run: |
mkdir -p ${{ github.workspace }}/build
python3 ${{ github.workspace }}/.github/scripts/create_version.py build/PrusaSlicer.version
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: 'build'

- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4

0 comments on commit 4c0da1f

Please sign in to comment.