From fb6579d819bf1140fd94fc5ae79343271e9ea7e9 Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Fri, 6 Jun 2025 13:52:07 +0200 Subject: [PATCH] Add automatic flatpak version bumping logic This now bumps the version number in de.wger.flutter.metainfo.xml, which is something we were not doing before... --- .github/workflows/bump-version.yml | 12 ++- .github/workflows/make-release.yml | 1 + flatpak/bump-flatpak-version.py | 135 +++++++++++++++++++++++++++ flatpak/de.wger.flutter.metainfo.xml | 14 +-- 4 files changed, 148 insertions(+), 14 deletions(-) create mode 100644 flatpak/bump-flatpak-version.py diff --git a/.github/workflows/bump-version.yml b/.github/workflows/bump-version.yml index 81b1e3fd..5b66db4b 100644 --- a/.github/workflows/bump-version.yml +++ b/.github/workflows/bump-version.yml @@ -21,6 +21,9 @@ jobs: - name: Common flutter setup uses: ./.github/actions/flutter-common + - name: Setup uv + uses: astral-sh/setup-uv@v5 + - name: Validate version run: | RELEASE_VERSION="${{ inputs.app_version }}" @@ -39,11 +42,16 @@ jobs: NEXT_BUILD=$(( (CURRENT_BUILD / 10 + 1) * 10 )) flutter pub run cider version ${{ inputs.app_version }}+${NEXT_BUILD} + - name: Bump flatpak version + run: | + cd flatpak + uv run bump-flatpak-version.py ${{ inputs.app_version }} + - name: Tag release and commit pubspec run: | git config user.name Github-Actions git config user.email github-actions@github.com - git add pubspec.yaml - git commit -m "Bump version to $( flutter pub run cider version )" + git add pubspec.yaml flatpak/de.wger.flutter.metainfo.xml + git commit -m "Bump version to ${{ inputs.app_version }}" git tag ${{ inputs.app_version }} git push origin HEAD:master --tags diff --git a/.github/workflows/make-release.yml b/.github/workflows/make-release.yml index 4736eef7..8dc9dd82 100644 --- a/.github/workflows/make-release.yml +++ b/.github/workflows/make-release.yml @@ -138,6 +138,7 @@ jobs: - name: Make Github release uses: softprops/action-gh-release@v2 with: + generate_release_notes: true tag_name: ${{ inputs.version }} files: | builds-aab/app-release.aab diff --git a/flatpak/bump-flatpak-version.py b/flatpak/bump-flatpak-version.py new file mode 100644 index 00000000..8d25142c --- /dev/null +++ b/flatpak/bump-flatpak-version.py @@ -0,0 +1,135 @@ +# This file is part of wger Workout Manager. +# +# wger Workout Manager is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# wger Workout Manager 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. +# +# You should have received a copy of the GNU Affero General Public License + +# /// script +# requires-python = ">=3.13" +# dependencies = [ +# "requests == 2.31.0", +# "markdown == 3.5.1", +# ] +# /// + + +""" +Updates the Flatpak metainfo.xml file with the given version. + +Usage: + uv run bump-flatpak-version.py x.y.z +""" + +import sys +import xml.etree.ElementTree as ET +from datetime import datetime +from typing import Tuple + +import markdown +import requests + +REPO = "wger-project/flutter" + + +def get_github_release_info(repo: str, version: str) -> Tuple[str, str]: + """ + Fetches the release description and published_at date from GitHub for the given repository + and version. The description is converted fro markdown and returned as HTML. + """ + + print('Fetching release information from GitHub...') + url = f'https://api.github.com/repos/{repo}/releases/tags/{version}' + response = requests.get(url) + response.raise_for_status() + data = response.json() + html_desc = markdown.markdown(data.get('body', '')) + + # Get the published_at date, formatted as YYYY-MM-DD, we don't need the time part + published_at = data.get('published_at', '')[:10] + return html_desc, published_at + + +def add_release_to_metainfo( + repo: str, + xml_filename: str, + version: str, + date: str | None = None, + description: str | None = None +) -> None: + """ + Adds a element with the specified version and date to the + section in the given metainfo.xml file. + + If a description is provided, it will be added as a child element of the + element. + """ + print(f'Adding release to {xml_filename}...') + + if date is None: + date = datetime.now().strftime('%Y-%m-%d') + + if description is None: + description = '

Bug fixes and improvements.

' + + tree = ET.parse(xml_filename) + root = tree.getroot() + releases = root.find('releases') + new_release = ET.Element('release', {'version': version, 'date': date}) + if description: + desc_elem = ET.SubElement(new_release, 'description') + + # Needed to add HTML content directly, otherwise it will be escaped + fragment = ET.fromstring(f'{description}') + for child in fragment: + desc_elem.append(child) + + url_elem = ET.SubElement(new_release, 'url') + url_elem.text = f'https://{repo}/releases/tag/{version}' + + releases.insert(0, new_release) + ET.indent(tree, space=" ", level=0) + tree.write(xml_filename, encoding="utf-8", xml_declaration=True) + + +if __name__ == '__main__': + if len(sys.argv) != 2: + print('Usage: python bump-flatpak-version.py ') + sys.exit(1) + + version = sys.argv[1] + + print(f'Processing version {version}...') + + # Note: it seems it's currently not possible to update existing releases on + # GitHub with softprops/action-gh-release. + # + # Once that's fixed, we can update the workflows to first create the + # release and its changelog, and in a later step only update the artifacts. + # We can then simply fetch the description and update the metainfo.xml file. + # + # See + # * https://github.com/softprops/action-gh-release/issues/616 + # * https://github.com/softprops/action-gh-release/issues/445 + + # description, published_at = get_github_release_info( + # REPO, + # version + # ) + + add_release_to_metainfo( + repo=REPO, + xml_filename='de.wger.flutter.metainfo.xml', + version=version, + date=None, # published_at, + description=None # description + ) + + print(f'Finished!') diff --git a/flatpak/de.wger.flutter.metainfo.xml b/flatpak/de.wger.flutter.metainfo.xml index fbcca043..5f64c262 100755 --- a/flatpak/de.wger.flutter.metainfo.xml +++ b/flatpak/de.wger.flutter.metainfo.xml @@ -1,4 +1,4 @@ - + de.wger.flutter wger @@ -7,7 +7,6 @@

wger is a free and open-source fitness application designed to help you achieve your fitness goals.

-

Workout Management

  • Create and customize workout routines tailored to your fitness level and @@ -16,21 +15,18 @@
  • Track your progress with detailed exercise logs
  • Access a vast library of exercises
-

Nutrition Tracking

  • Log your food intake using the Open Food Facts database
  • Calculate your calorie intake and macronutrient breakdown
  • Set personalized dietary goals and track your progress
-

Body Measurement Tracking

  • Monitor your body weight, body fat percentage, and other measurements
  • Visualize your progress with charts and graphs
- CC0-1.0 AGPL-3.0-or-later @@ -45,13 +41,10 @@ https://buymeacoffee.com/wger https://github.com/wger-project/flutter https://hosted.weblate.org/engage/wger/ - - #a2aedd #687bd9 - wger's dashboard @@ -84,12 +77,9 @@ - - - de.wger.flutter.desktop -
+ \ No newline at end of file