Skip to content

[X] Update package index #3

[X] Update package index

[X] Update package index #3

name: "[X] Update package index"
jobs:
cleanup:
runs-on: ubuntu-latest
steps:
- name: Remove untagged images
uses: actions/github-script@v7
env:
package_name: ${{ matrix.package_name }}
with:
github-token: ${{ secrets.GHCR_TOKEN }}
script: |
// Retrieve container image versions
const versions = github.rest.packages.getAllPackageVersionsForPackageOwnedByUser({
package_name: process.env['package_name'],
package_type: 'container',
username: context.repo.owner,
});
console.log(versions);
// Iterate over received versions
for (const version of versions) {
// If there is no tags assigned for the image version
if (version.metadata.container.tags.length === 0) {
// Delete that version
github.rest.packages.deletePackageVersionForUser({
package_name: process.env['package_name'],
package_type: 'container',
package_version_id: version.id,
username: context.repo.owner,
});
// Print notice
core.notice(`Container image version removed: ${version.id}`);
}
}
strategy:
matrix:
package_name:
- "vllm"
build:
runs-on: ubuntu-latest
steps:
- 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:
workflow_call:
secrets:
GHCR_TOKEN:
required: true
workflow_dispatch: