[X] Update package index #14
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
name: "[X] Update package index" | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Generate package index | |
shell: python | |
run: | | |
import os | |
import packaging.utils | |
import requests | |
import sys | |
# Fetch releases from the GitHub API | |
response = requests.get("https://api.github.com/repos/${{ github.repository }}/releases") | |
# Raise an error if the request was unsuccessful | |
response.raise_for_status() | |
# Parse the response JSON | |
data = response.json() | |
# Initialize variable to hold the assets of the first non-prerelease | |
assets = None | |
# Loop through the releases to find the first non-prerelease | |
for release in data: | |
if not release["prerelease"]: | |
assets = release["assets"] | |
break | |
# Dictionary to hold package information | |
packages = {} | |
# Process each asset in the release | |
for asset in assets: | |
# Get the asset name and download URL | |
name = asset["name"] | |
url = asset["browser_download_url"] | |
# Parse the wheel filename to extract package information | |
parsed = packaging.utils.parse_wheel_filename(name) | |
# Extract the package name from the parsed information | |
package_name = parsed[0] | |
# Initialize the package entry in the dictionary if not already present | |
if package_name not in packages: | |
packages[package_name] = [] | |
# Append the asset information to the package entry | |
packages[package_name].append((name, url)) | |
# Generate HTML pages for each package | |
for package_name, wheels in packages.items(): | |
# Create an index.html file for the package | |
os.makedirs(f"_site/{package_name}", exist_ok=True) | |
with open(f"_site/{package_name}/index.html", "w") as file: | |
file.write("<!DOCTYPE html>") | |
file.write("<html>") | |
file.write("<body>") | |
file.write(f"<h1>Links for {package_name}</h1>") | |
# Add links to each wheel file | |
for (wheel_name, wheel_url) in wheels: | |
file.write(f'<a href="{wheel_url}">{wheel_name}</a><br/>') | |
file.write("</body>") | |
file.write("</html>") | |
# Create the main index.html file | |
os.makedirs("_site", exist_ok=True) | |
with open("_site/index.html", "w") as file: | |
file.write("<!DOCTYPE html>") | |
file.write("<html>") | |
file.write("<body>") | |
# Add links to each package | |
for package_name in packages.keys(): | |
file.write(f'<a href="{package_name}/">{package_name}</a><br/>') | |
file.write("</body>") | |
file.write("</html>") | |
- name: Upload pages artifact | |
uses: actions/upload-pages-artifact@v3 | |
deploy: | |
needs: build | |
runs-on: ubuntu-latest | |
environment: | |
name: github-pages | |
url: ${{ steps.deployment.outputs.page_url }} | |
permissions: | |
id-token: write | |
pages: write | |
steps: | |
- name: Deploy to GitHub Pages | |
id: deployment | |
uses: actions/deploy-pages@v4 | |
on: | |
schedule: | |
- cron: "30 4 * * *" | |
workflow_dispatch: |