1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/cinny_ynh.git synced 2024-09-03 18:16:13 +02:00

Use tomlkit to read manifest

This commit is contained in:
Félix Piédallu 2023-03-30 10:00:12 +02:00
parent be7b241b2f
commit 271e356ef1
2 changed files with 22 additions and 5 deletions

View file

@ -11,9 +11,11 @@ You need to enable the action by removing `if ${{ false }}` in updater.yml!
import hashlib import hashlib
import json import json
import tomlkit
import logging import logging
import os import os
import re import re
from pathlib import Path
from subprocess import run, PIPE from subprocess import run, PIPE
import textwrap import textwrap
from typing import List, Tuple, Any from typing import List, Tuple, Any
@ -86,8 +88,14 @@ def write_github_env(proceed: bool, new_version: str, branch: str):
""")) """))
def main(): def main():
with open("manifest.json", "r", encoding="utf-8") as manifest_file: repository_path = Path(__file__).parent.parent.parent
manifest = json.load(manifest_file) 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"] repo = manifest["upstream"]["code"]
current_version = version.Version(manifest["version"].split("~")[0]) current_version = version.Version(manifest["version"].split("~")[0])
@ -115,9 +123,13 @@ def main():
handle_asset(asset) handle_asset(asset)
manifest["version"] = f"{latest_version}~ynh1" manifest["version"] = f"{latest_version}~ynh1"
with open("manifest.json", "w", encoding="utf-8") as manifest_file: if manifest_toml.exists():
json.dump(manifest, manifest_file, indent=4, ensure_ascii=False) with open(manifest_toml, "w", encoding="utf-8") as manifest_file:
manifest_file.write("\n") 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) write_github_env(True, latest_version, branch)

View file

@ -23,6 +23,11 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.GITHUB_TOKEN }}
ref: testing ref: testing
- uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: python3-tomlkit
version: 1.0
- name: Run the updater script - name: Run the updater script
run: .github/workflows/updater.py run: .github/workflows/updater.py