Skip to content

Commit 89d8cc7

Browse files
committed
updated create index action
1 parent 9160d0c commit 89d8cc7

File tree

2 files changed

+73
-65
lines changed

2 files changed

+73
-65
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Build & Deploy pip Simple Index
2+
3+
on:
4+
release:
5+
types: [ published ]
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: write # for checkout and uploading artifacts
10+
pages: write # to deploy GitHub Pages
11+
id-token: write # to mint an OIDC token for deploy-pages
12+
13+
jobs:
14+
publish-index:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
# 1. Check out default branch
19+
- name: Checkout repository
20+
uses: actions/checkout@v4
21+
22+
# 2. Generate PEP 503 “simple” index from all .whl assets
23+
- name: Generate pip simple index
24+
uses: actions/github-script@v6
25+
with:
26+
script: |
27+
const fs = require('fs');
28+
const { owner, repo } = context.repo;
29+
// 1) Fetch all releases
30+
const releases = await github.rest.repos.listReleases({ owner, repo, per_page: 100 });
31+
const packages = {};
32+
// 2) Gather wheel URLs, group by "normalized" package name
33+
for (const rel of releases.data) {
34+
for (const asset of rel.assets) {
35+
if (asset.name.endsWith('.whl')) {
36+
// take first segment, lowercase, underscores → hyphens
37+
const raw = asset.name.split('-')[0].toLowerCase();
38+
const pkg = raw.replace(/_/g, '-');
39+
packages[pkg] = packages[pkg] || [];
40+
packages[pkg].push({ url: asset.browser_download_url, name: asset.name });
41+
}
42+
}
43+
}
44+
// 3) Build 'simple/' directory tree
45+
fs.rmSync('simple', { recursive: true, force: true });
46+
fs.mkdirSync('simple', { recursive: true });
47+
// Root index.html
48+
let root = '<!DOCTYPE html><html><body>\n';
49+
for (const pkg of Object.keys(packages).sort()) {
50+
root += `<a href="./${pkg}/">${pkg}</a><br>\n`;
51+
// per-package page
52+
const dir = `simple/${pkg}`;
53+
fs.mkdirSync(dir, { recursive: true });
54+
let page = '<!DOCTYPE html><html><body>\n';
55+
for (const f of packages[pkg]) {
56+
// fragment "#filename" ensures pip sees the correct wheel name
57+
page += `<a href="${f.url}#${f.name}">${f.name}</a><br>\n`;
58+
}
59+
page += '</body></html>\n';
60+
fs.writeFileSync(`${dir}/index.html`, page);
61+
}
62+
root += '</body></html>\n';
63+
fs.writeFileSync('simple/index.html', root);
64+
65+
# 3. Package the 'simple/' folder for Pages
66+
- name: Upload Pages artifact
67+
uses: actions/upload-pages-artifact@v3
68+
with:
69+
path: simple
70+
71+
# 4. Deploy to GitHub Pages
72+
- name: Deploy to GitHub Pages
73+
uses: actions/deploy-pages@v4

.github/workflows/create-index.yaml.yml

Lines changed: 0 additions & 65 deletions
This file was deleted.

0 commit comments

Comments
 (0)