From 306d447e972ba359873eff253b9ad40b7d492b87 Mon Sep 17 00:00:00 2001 From: Tagadda <36127788+Tagadda@users.noreply.github.com> Date: Tue, 22 Feb 2022 23:44:44 +0000 Subject: [PATCH 1/4] Add a warning when not on a master branch --- README-generator/make_readme.py | 4 ++++ README-generator/templates/README.md.j2 | 2 +- README-generator/templates/README_fr.md.j2 | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README-generator/make_readme.py b/README-generator/make_readme.py index ddcc3d2..d00e1ed 100755 --- a/README-generator/make_readme.py +++ b/README-generator/make_readme.py @@ -53,6 +53,9 @@ def generate_READMEs(app_path: str): else: disclaimer = None + # Get the current branch using git inside the app path + branch = os.popen("git --git-dir=%s/.git --work-tree=%s rev-parse --abbrev-ref HEAD" % (app_path, app_path)).read().strip() + out = template.render( lang=lang, upstream=upstream, @@ -60,6 +63,7 @@ def generate_READMEs(app_path: str): screenshots=screenshots, disclaimer=disclaimer, manifest=manifest, + branch=branch, ) (app_path / f"README{lang_suffix}.md").write_text(out) diff --git a/README-generator/templates/README.md.j2 b/README-generator/templates/README.md.j2 index 6e58002..b0eb5c2 100644 --- a/README-generator/templates/README.md.j2 +++ b/README-generator/templates/README.md.j2 @@ -31,7 +31,7 @@ If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/in {% if description %}{{description}}{% else %}{{manifest.description[lang]}}{% endif %} -**Shipped version:** {% if upstream.version %}{{upstream.version}}{% else %}{{manifest.version}}{% endif %} +**Shipped version:** {% if upstream.version %}{{upstream.version}}{% else %}{{manifest.version}}{% endif %}{% if branch != "master" %} *(This is the `{{ branch }}` branch. See the [`master` branch](https://github.com/YunoHost-Apps/{{manifest.id}}_ynh/tree/master) for the version in the catalog.)*{% endif %} {% if upstream.demo %}**Demo:** {{upstream.demo}}{% endif %} diff --git a/README-generator/templates/README_fr.md.j2 b/README-generator/templates/README_fr.md.j2 index 9169cbb..63ca8c4 100644 --- a/README-generator/templates/README_fr.md.j2 +++ b/README-generator/templates/README_fr.md.j2 @@ -13,7 +13,7 @@ Si vous n'avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) pour {% if description %}{{description}}{% else %}{{manifest.description[lang]}}{% endif %} -**Version incluse :** {% if upstream.version %}{{upstream.version}}{% else %}{{manifest.version}}{% endif %} +**Version incluse :** {% if upstream.version %}{{upstream.version}}{% else %}{{manifest.version}}{% endif %}{% if branch != "master" %} *(Vous êtes sur la branche `{{ branch }}`. Voir la [branche `master`](https://github.com/YunoHost-Apps/{{manifest.id}}_ynh/tree/master) pour la version du catalogue.)*{% endif %} {% if upstream.demo %}**Démo :** {{upstream.demo}}{% endif %} From cf0343f6a178047274da2003bc96d838d0215b56 Mon Sep 17 00:00:00 2001 From: Tagadda <36127788+Tagadda@users.noreply.github.com> Date: Wed, 23 Feb 2022 06:36:19 +0000 Subject: [PATCH 2/4] Get the default branch from the apps.json --- README-generator/make_readme.py | 4 ++++ README-generator/templates/README.md.j2 | 2 +- README-generator/templates/README_fr.md.j2 | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README-generator/make_readme.py b/README-generator/make_readme.py index d00e1ed..4b34ef5 100755 --- a/README-generator/make_readme.py +++ b/README-generator/make_readme.py @@ -18,6 +18,9 @@ def generate_READMEs(app_path: str): manifest = json.load(open(app_path / "manifest.json")) upstream = manifest.get("upstream", {}) + catalog = json.load(open(Path(__file__).parent.parent.parent / "apps.json")) + from_catalog = catalog.get(manifest['id'], {}) + if not upstream and not (app_path / "doc" / "DISCLAIMER.md").exists(): print( "There's no 'upstream' key in the manifest, and doc/DISCLAIMER.md doesn't exists - therefore assuming that we shall not auto-update the README.md for this app yet." @@ -64,6 +67,7 @@ def generate_READMEs(app_path: str): disclaimer=disclaimer, manifest=manifest, branch=branch, + default_branch=from_catalog.get('branch', 'master'), ) (app_path / f"README{lang_suffix}.md").write_text(out) diff --git a/README-generator/templates/README.md.j2 b/README-generator/templates/README.md.j2 index b0eb5c2..a0fdf07 100644 --- a/README-generator/templates/README.md.j2 +++ b/README-generator/templates/README.md.j2 @@ -31,7 +31,7 @@ If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/in {% if description %}{{description}}{% else %}{{manifest.description[lang]}}{% endif %} -**Shipped version:** {% if upstream.version %}{{upstream.version}}{% else %}{{manifest.version}}{% endif %}{% if branch != "master" %} *(This is the `{{ branch }}` branch. See the [`master` branch](https://github.com/YunoHost-Apps/{{manifest.id}}_ynh/tree/master) for the version in the catalog.)*{% endif %} +**Shipped version:** {% if upstream.version %}{{upstream.version}}{% else %}{{manifest.version}}{% endif %}{% if branch != default_branch %} *(This is the `{{ branch }}` branch. See the [`{{ default_branch }}` branch](https://github.com/YunoHost-Apps/{{manifest.id}}_ynh/tree/{{ default_branch }}) for the version in the catalog.)*{% endif %} {% if upstream.demo %}**Demo:** {{upstream.demo}}{% endif %} diff --git a/README-generator/templates/README_fr.md.j2 b/README-generator/templates/README_fr.md.j2 index 63ca8c4..14bd727 100644 --- a/README-generator/templates/README_fr.md.j2 +++ b/README-generator/templates/README_fr.md.j2 @@ -13,7 +13,7 @@ Si vous n'avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) pour {% if description %}{{description}}{% else %}{{manifest.description[lang]}}{% endif %} -**Version incluse :** {% if upstream.version %}{{upstream.version}}{% else %}{{manifest.version}}{% endif %}{% if branch != "master" %} *(Vous êtes sur la branche `{{ branch }}`. Voir la [branche `master`](https://github.com/YunoHost-Apps/{{manifest.id}}_ynh/tree/master) pour la version du catalogue.)*{% endif %} +**Version incluse :** {% if upstream.version %}{{upstream.version}}{% else %}{{manifest.version}}{% endif %}{% if branch != default_branch %} *(Vous êtes sur la branche `{{ branch }}`. Voir la [branche `{{ default_branch }}`](https://github.com/YunoHost-Apps/{{manifest.id}}_ynh/tree/{{ default_branch }}) pour la version du catalogue.)*{% endif %} {% if upstream.demo %}**Démo :** {{upstream.demo}}{% endif %} From 388337d8bf3686bb5696ecd20808aff3259bcf43 Mon Sep 17 00:00:00 2001 From: Tagadda <36127788+Tagadda@users.noreply.github.com> Date: Wed, 23 Feb 2022 07:07:45 +0000 Subject: [PATCH 3/4] fix --- README-generator/make_readme.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README-generator/make_readme.py b/README-generator/make_readme.py index 4b34ef5..ac47a04 100755 --- a/README-generator/make_readme.py +++ b/README-generator/make_readme.py @@ -18,7 +18,7 @@ def generate_READMEs(app_path: str): manifest = json.load(open(app_path / "manifest.json")) upstream = manifest.get("upstream", {}) - catalog = json.load(open(Path(__file__).parent.parent.parent / "apps.json")) + catalog = json.load(open(Path(os.path.abspath(__file__)).parent.parent.parent / "apps.json")) from_catalog = catalog.get(manifest['id'], {}) if not upstream and not (app_path / "doc" / "DISCLAIMER.md").exists(): From 0a9495483fd4ff16742ac0c3f1130c58a403f9a1 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Fri, 5 Aug 2022 23:06:38 +0200 Subject: [PATCH 4/4] README-generator: improve mechanism to only add the 'specific branch' note when version is different from master + display master's version --- README-generator/make_readme.py | 14 +++++++++++--- README-generator/templates/README.md.j2 | 2 +- README-generator/templates/README_fr.md.j2 | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/README-generator/make_readme.py b/README-generator/make_readme.py index ac47a04..049aa21 100755 --- a/README-generator/make_readme.py +++ b/README-generator/make_readme.py @@ -57,7 +57,14 @@ def generate_READMEs(app_path: str): disclaimer = None # Get the current branch using git inside the app path - branch = os.popen("git --git-dir=%s/.git --work-tree=%s rev-parse --abbrev-ref HEAD" % (app_path, app_path)).read().strip() + default_branch = from_catalog.get('branch', 'master') + current_branch = os.popen(f"git -C {app_path} rev-parse --abbrev-ref HEAD").read().strip() + + if default_branch != current_branch: + os.system(f"git -C {app_path} fetch origin {default_branch} 2>/dev/null") + default_branch_version = os.popen(f"git -C {app_path} show FETCH_HEAD:manifest.json | jq -r .version").read().strip() + else: + default_branch_version = None # we don't care in that case out = template.render( lang=lang, @@ -66,8 +73,9 @@ def generate_READMEs(app_path: str): screenshots=screenshots, disclaimer=disclaimer, manifest=manifest, - branch=branch, - default_branch=from_catalog.get('branch', 'master'), + current_branch=current_branch, + default_branch=default_branch, + default_branch_version=default_branch_version, ) (app_path / f"README{lang_suffix}.md").write_text(out) diff --git a/README-generator/templates/README.md.j2 b/README-generator/templates/README.md.j2 index 125833c..ec99391 100644 --- a/README-generator/templates/README.md.j2 +++ b/README-generator/templates/README.md.j2 @@ -31,7 +31,7 @@ If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/in {% if description %}{{description}}{% else %}{{manifest.description[lang]}}{% endif %} -**Shipped version:** {% if upstream.version %}{{upstream.version}}{% else %}{{manifest.version}}{% endif %}{% if branch != default_branch %} *(This is the `{{ branch }}` branch. See the [`{{ default_branch }}` branch](https://github.com/YunoHost-Apps/{{manifest.id}}_ynh/tree/{{ default_branch }}) for the version in the catalog.)*{% endif %} +**Shipped version:** {% if upstream.version %}{{upstream.version}}{% else %}{{manifest.version}}{% endif %}{% if current_branch != default_branch and manifest.version != default_branch_version %} *(:warning: This is the `{{ current_branch }}` branch. The [`{{ default_branch }}` branch](https://github.com/YunoHost-Apps/{{manifest.id}}_ynh/tree/{{ default_branch }}) used in the catalog is currently on version {{ default_branch_version.replace('~', '\~') }}.)*{% endif %} {% if upstream.demo %} **Demo:** {{upstream.demo}} diff --git a/README-generator/templates/README_fr.md.j2 b/README-generator/templates/README_fr.md.j2 index 7350947..d616280 100644 --- a/README-generator/templates/README_fr.md.j2 +++ b/README-generator/templates/README_fr.md.j2 @@ -17,7 +17,7 @@ Si vous n'avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) pour {% if description %}{{description}}{% else %}{{manifest.description[lang]}}{% endif %} -**Version incluse :** {% if upstream.version %}{{upstream.version}}{% else %}{{manifest.version}}{% endif %}{% if branch != default_branch %} *(Vous êtes sur la branche `{{ branch }}`. Voir la [branche `{{ default_branch }}`](https://github.com/YunoHost-Apps/{{manifest.id}}_ynh/tree/{{ default_branch }}) pour la version du catalogue.)*{% endif %} +**Version incluse :** {% if upstream.version %}{{upstream.version}}{% else %}{{manifest.version}}{% endif %}{% if current_branch != default_branch and manifest.version != default_branch_version %} *(:warning: Il s'agit de la branche `{{ current_branch }}`. La [branche `{{ default_branch }}`](https://github.com/YunoHost-Apps/{{manifest.id}}_ynh/tree/{{ default_branch }}) utilisée dans le catalogue est actuellement en {{ default_branch_version.replace('~', '\~') }}.)*{% endif %} {% if upstream.demo %} **Démo :** {{upstream.demo}}