Skip to content

Commit

Permalink
Add workflow to generate appstream releases file
Browse files Browse the repository at this point in the history
  • Loading branch information
oskirby committed Aug 24, 2024
1 parent bc138a2 commit a20dc46
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 0 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/github-pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Github Pages
on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build:
name: Build Content
runs-on: ubuntu-latest
steps:
- name: Clone repository
uses: actions/checkout@v4

- name: Generate Appstream releases
shell: bash
run: python ./generate-appstream-releases.py docs/mozillavpn.json > docs/org.mozilla.vpn.releases.xml

- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: docs

deploy:
name: Deploy Pages
if: ${{ github.ref == 'refs/heads/main' }}
needs: build
runs-on: ubuntu-latest
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy to GitHub Pages
uses: actions/deploy-pages@v4
id: deployment
64 changes: 64 additions & 0 deletions generate-appstream-releases.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#! /usr/bin/env python3
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

import argparse
import os
import sys
import json

from packaging.version import Version
from xml.etree import ElementTree

class release:
def __init__(self, version, js):
self.version = version
self.json = js
self.platforms = [x.lower() for x in js['platforms']]

def matches(self, platform):
return platform.lower() in self.platforms

def toxml(self):
attrs = {
'version': self.version,
'date': self.json['date']
}
xml = ElementTree.Element('release', attrib=attrs)

# Add the details URL which should point to github
xurl = ElementTree.Element('url', attrib={'type': 'details'})
xurl.text = f"https://github.com/mozilla-mobile/mozilla-vpn-client/releases/v{self.version}"
xml.append(xurl)

return xml

if __name__ == "__main__":
## Parse arguments to locate the input files and options.
parser = argparse.ArgumentParser(
description='Generate releases information for an appstream file')

parser.add_argument('source', metavar='SOURCE', type=str, action='store',
help='Appstream metainfo file to parse')
parser.add_argument('--platform', metavar='PLATFORM', type=str,
action='store', default='LINUX',
help='Target platform for appstream releases')
args = parser.parse_args()

# Parse the release file
with open(args.source, 'r') as fp:
data = json.load(fp)

# Build the releases XML document.
root = ElementTree.Element('releases')
versions = list(data['releases'].keys())
versions.sort(key=Version, reverse=True)
for version in versions:
info = release(version, data['releases'][version])
if info.matches(args.platform):
root.append(info.toxml())

# Dump the XML data to stdout
ElementTree.indent(root, space=" ")
ElementTree.dump(root)

0 comments on commit a20dc46

Please sign in to comment.