Create github action for creating pip-compatible releases index

pull/1375/head
Daniel Ellis 2022-09-20 10:40:44 -04:00
parent 53bf09ceef
commit 1dfe5efe9e
2 changed files with 76 additions and 0 deletions

View File

@ -0,0 +1,40 @@
# See: https://github.com/llvm/torch-mlir/issues/1374
name: Publish releases page
on:
schedule:
- cron: '0 * * * *'
workflow_dispatch:
jobs:
scrape_and_publish_releases:
name: "Scrape and publish releases"
runs-on: ubuntu-20.04
# Don't run this in everyone's forks.
if: github.repository == 'llvm/torch-mlir'
steps:
- name: Checking out repository
uses: actions/checkout@v2
with:
token: ${{ secrets.WORKFLOW_INVOCATION_TOKEN }}
- name: Run scrape releases script
run: python ./build_tools/scrape_releases.py llvm torch-mlir > /tmp/index.html
shell: bash
- run: git fetch --all
- run: git switch github-pages
- run: git config --global user.email "none@none.com"
- run: git config --global user.name "torch-mlir"
- run: mv /tmp/index.html package-index/index.html
- run: git add package-index/index.html
# Only try to make a commit if the file has changed.
- run: git diff --cached --exit-code || git commit -m "Update releases."
- name: GitHub Push
uses: ad-m/github-push-action@v0.6.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: github-pages

View File

@ -0,0 +1,36 @@
"""Scrapes the github releases API to generate a static pip-install-able releases page.
See https://github.com/llvm/torch-mlir/issues/1374
"""
import argparse
import json
import requests
# Parse arguments
parser = argparse.ArgumentParser()
parser.add_argument('owner', type=str)
parser.add_argument('repo', type=str)
args = parser.parse_args()
# Get releases
response = requests.get(
f"https://api.github.com/repos/{args.owner}/{args.repo}/releases")
body = json.loads(response.content)
# Parse releases
releases = []
for row in body:
for asset in row['assets']:
releases.append((asset["name"], asset["browser_download_url"]))
# Output HTML
html = """<!DOCTYPE html>
<html>
<body>
"""
for name, url in releases:
html += f" <a href='{url}'>{name}</a><br />\n"
html += """ </body>
</html>"""
print(html)