From 1dfe5efe9ee8f58deabf9382b58894a00b2d440c Mon Sep 17 00:00:00 2001 From: Daniel Ellis <1346302+dellis23@users.noreply.github.com> Date: Tue, 20 Sep 2022 10:40:44 -0400 Subject: [PATCH] Create github action for creating pip-compatible releases index --- .github/workflows/gh-pages-releases.yml | 40 +++++++++++++++++++++++++ build_tools/scrape_releases.py | 36 ++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 .github/workflows/gh-pages-releases.yml create mode 100644 build_tools/scrape_releases.py diff --git a/.github/workflows/gh-pages-releases.yml b/.github/workflows/gh-pages-releases.yml new file mode 100644 index 000000000..6d05f11b9 --- /dev/null +++ b/.github/workflows/gh-pages-releases.yml @@ -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 \ No newline at end of file diff --git a/build_tools/scrape_releases.py b/build_tools/scrape_releases.py new file mode 100644 index 000000000..b8c7265d3 --- /dev/null +++ b/build_tools/scrape_releases.py @@ -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 = """ + + +""" +for name, url in releases: + html += f" {name}
\n" +html += """ +""" +print(html) \ No newline at end of file