Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Update Metainfo workflow #234

Merged
merged 2 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions .github/tools/update-metainfo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env python3

# Command arguments: release version (tag name), date (in format YEAR-MONTH-DAY), URL
# First argument is required, date and url are optional

import sys
import logging
import xml.etree.ElementTree as ET

from datetime import datetime

logging.basicConfig(level=logging.INFO)

METAINFO_PATH = "../../so.libdb.gtkcord4.metainfo.xml"
REPOSITORY_URL = "https://github.com/diamondburned/gtkcord4"

arg_list = sys.argv[1:]
rel_version = arg_list[0]

if len(arg_list) == 1:
rel_date = datetime.today().strftime("%Y-%m-%d")
rel_url = f"{REPOSITORY_URL}/releases/tag/{rel_version}"
else:
rel_date = arg_list[1]
rel_url = arg_list[2]

logging.info("Parsed release info:")
logging.info("Version: %s", rel_version)
logging.info("Date: %s", rel_date)
logging.info("Tag URL: %s", rel_url)

# Get element tree and 'component' root element
tree = ET.parse(METAINFO_PATH)
root = tree.getroot()

# Get 'releases' element
releases = root.find("releases")

# Create new 'release' element with 'url' subelement
new_release = ET.Element(
"release",
{
'version': rel_version,
'date': rel_date
}
)

release_url = ET.SubElement(new_release, "url")
release_url.text = rel_url

# Insert 'release' as a first element of the 'releases' element
releases.insert(0, new_release)

# Indent 'releases' element for better readability
ET.indent(releases, level=1)

# Write edited XML to the original metainfo file
tree.write(METAINFO_PATH, encoding="utf-8", xml_declaration=True)
21 changes: 21 additions & 0 deletions .github/workflows/update-metainfo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Update Metainfo

on:
release:
types: [released]
diamondburned marked this conversation as resolved.
Show resolved Hide resolved

jobs:
update:
name: Update Metainfo file
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref_name }}
- name: Run update-metainfo script
run: python ./.github/tools/update-metainfo.py ${{ github.ref_name }}
- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "chore: Update metainfo.xml"
file_pattern: so.libdb.gtkcord4.metainfo.xml
Loading