From 271e356ef1ad3b9418e1965e824a46fe414400e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= <{{ gitemail }}> Date: Thu, 30 Mar 2023 10:00:12 +0200 Subject: [PATCH] Use tomlkit to read manifest --- .github/workflows/updater.py | 22 +++++++++++++++++----- .github/workflows/updater.yml | 5 +++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/.github/workflows/updater.py b/.github/workflows/updater.py index c92fb2c..0e9f8fa 100755 --- a/.github/workflows/updater.py +++ b/.github/workflows/updater.py @@ -11,9 +11,11 @@ You need to enable the action by removing `if ${{ false }}` in updater.yml! import hashlib import json +import tomlkit import logging import os import re +from pathlib import Path from subprocess import run, PIPE import textwrap from typing import List, Tuple, Any @@ -86,8 +88,14 @@ def write_github_env(proceed: bool, new_version: str, branch: str): """)) def main(): - with open("manifest.json", "r", encoding="utf-8") as manifest_file: - manifest = json.load(manifest_file) + repository_path = Path(__file__).parent.parent.parent + manifest_toml = repository_path / "manifest.toml" + if manifest_toml.exists(): + with open(manifest_toml, "r", encoding="utf-8") as manifest_file: + manifest = tomlkit.parse(manifest_file.read()) + else: + with open("manifest.json", "r", encoding="utf-8") as manifest_file: + manifest = json.load(manifest_file) repo = manifest["upstream"]["code"] current_version = version.Version(manifest["version"].split("~")[0]) @@ -115,9 +123,13 @@ def main(): handle_asset(asset) manifest["version"] = f"{latest_version}~ynh1" - with open("manifest.json", "w", encoding="utf-8") as manifest_file: - json.dump(manifest, manifest_file, indent=4, ensure_ascii=False) - manifest_file.write("\n") + if manifest_toml.exists(): + with open(manifest_toml, "w", encoding="utf-8") as manifest_file: + tomlkit.dump(manifest, manifest_file) + else: + with open("manifest.json", "w", encoding="utf-8") as manifest_file: + json.dump(manifest, manifest_file, indent=4, ensure_ascii=False) + manifest_file.write("\n") write_github_env(True, latest_version, branch) diff --git a/.github/workflows/updater.yml b/.github/workflows/updater.yml index 3899b0a..7a0f97a 100644 --- a/.github/workflows/updater.yml +++ b/.github/workflows/updater.yml @@ -23,6 +23,11 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} ref: testing + - uses: awalsh128/cache-apt-pkgs-action@latest + with: + packages: python3-tomlkit + version: 1.0 + - name: Run the updater script run: .github/workflows/updater.py