-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add workflow to generate appstream releases file
- Loading branch information
Showing
2 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |