Skip to content

Commit a355cdd

Browse files
committed
added index creation
1 parent 0a88f9c commit a355cdd

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Build & Publish pip Simple Index
2+
3+
on:
4+
workflow_dispatch:
5+
6+
permissions:
7+
contents: write
8+
pages: write
9+
10+
jobs:
11+
publish-index:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout default branch
15+
uses: actions/checkout@v4
16+
17+
- name: Generate pip simple index
18+
uses: actions/github-script@v6
19+
with:
20+
script: |
21+
const fs = require('fs');
22+
const { owner, repo } = context.repo;
23+
// 1. List all releases
24+
const releases = await github.rest.repos.listReleases({ owner, repo });
25+
const pkgs = {};
26+
// 2. Collect wheel URLs by package
27+
for (const r of releases.data) {
28+
for (const a of r.assets) {
29+
if (a.name.endsWith('.whl')) {
30+
const name = a.name.split('-')[0].toLowerCase();
31+
pkgs[name] = pkgs[name] || [];
32+
pkgs[name].push({ url: a.browser_download_url, file: a.name });
33+
}
34+
}
35+
}
36+
// 3. Build directories & HTML
37+
fs.mkdirSync('simple', { recursive: true });
38+
let indexHtml = '<!DOCTYPE html><html><body>\\n';
39+
for (const name of Object.keys(pkgs).sort()) {
40+
indexHtml += `<a href="./${name}/">${name}</a><br>\\n`;
41+
const dir = `simple/${name}`;
42+
fs.mkdirSync(dir, { recursive: true });
43+
let pkgHtml = '<!DOCTYPE html><html><body>\\n';
44+
for (const f of pkgs[name]) {
45+
pkgHtml += `<a href="${f.url}#${f.file}">${f.file}</a><br>\\n`;
46+
}
47+
pkgHtml += '</body></html>\\n';
48+
fs.writeFileSync(`${dir}/index.html`, pkgHtml);
49+
}
50+
indexHtml += '</body></html>\\n';
51+
fs.writeFileSync('simple/index.html', indexHtml);
52+
53+
- name: Upload Pages artifact
54+
uses: actions/upload-pages-artifact@v3
55+
with:
56+
path: simple
57+
58+
- name: Deploy to GitHub Pages
59+
uses: actions/deploy-pages@v4

0 commit comments

Comments
 (0)