File: check-for-updates

package info (click to toggle)
python-djvulibre 0.9.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 648 kB
  • sloc: python: 2,437; makefile: 38; sh: 25
file content (79 lines) | stat: -rwxr-xr-x 2,428 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python

# Copyright © 2023-2024 FriedrichFroebel
#
# This file is part of djvulibre-python.
#
# djvulibre-python is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 as published by
# the Free Software Foundation. If you like, you might use the
# `check-for-updates` script under the terms of the MIT license as well, id
# est this file can be considered "GPL-2.0-only OR MIT".
#
# djvulibre-python is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.

import sys
from pathlib import Path

import requests
import yaml
from bs4 import BeautifulSoup


DJVULIBRE_URL = "https://sourceforge.net/projects/djvu/rss?path=/DjVuLibre"


def fetch_latest_djvulibre_release():
    soup = BeautifulSoup(requests.get(DJVULIBRE_URL).content, features="xml")
    item = soup.find("item")
    version = item.find("title").text

    assert version, version
    assert version.startswith("/DjVuLibre/"), version
    version = version.split("/DjVuLibre/")[1]
    assert version, version
    assert "/" in version, version
    version = version.split("/")[0]
    assert version, version
    assert version.count(".") == 2, version
    assert version.replace(".", "").isnumeric(), version
    return version


def get_all_workflow_files():
    return Path(".github/workflows").glob("*.yml")


def check_workflow(workflow_path, latest_djvulibre_release):
    with open(workflow_path) as fd:
        content = yaml.safe_load(fd)
    env = content.get("env")
    if not env:
        return True

    current_version = env.get("DJVULIBRE_VERSION")
    if not current_version:
        return True
    if current_version != latest_djvulibre_release:
        print(f"DjVuLibre version {latest_djvulibre_release} is available for {workflow_path} (currently: {current_version}).")
        return False
    return True


def main():
    latest_djvulibre_release = fetch_latest_djvulibre_release()
    are_valid = True
    for workflow_path in get_all_workflow_files():
        are_valid &= check_workflow(
            workflow_path=workflow_path,
            latest_djvulibre_release=latest_djvulibre_release,
        )
    if not are_valid:
        sys.exit(5)


if __name__ == "__main__":
    main()