Skip to content

Commit 9160d0c

Browse files
committed
updated write index
1 parent a355cdd commit 9160d0c

File tree

1 file changed

+32
-26
lines changed

1 file changed

+32
-26
lines changed
Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,65 @@
1-
name: Build & Publish pip Simple Index
1+
name: Build & Deploy pip Simple Index
22

33
on:
44
workflow_dispatch:
55

66
permissions:
7-
contents: write
8-
pages: write
7+
contents: write # for checkout and uploading artifacts
8+
pages: write # to deploy GitHub Pages
9+
id-token: write # to mint an OIDC token for deploy-pages
910

1011
jobs:
1112
publish-index:
1213
runs-on: ubuntu-latest
14+
1315
steps:
14-
- name: Checkout default branch
16+
# 1. Check out the default branch so we have repo context
17+
- name: Checkout repository
1518
uses: actions/checkout@v4
1619

20+
# 2. Generate PEP 503 “simple” index from release assets
1721
- name: Generate pip simple index
1822
uses: actions/github-script@v6
1923
with:
2024
script: |
2125
const fs = require('fs');
2226
const { owner, repo } = context.repo;
23-
// 1. List all releases
27+
// Fetch all releases via the GitHub API
2428
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 });
29+
const packages = {};
30+
// Collect all .whl asset URLs, grouped by package name
31+
for (const release of releases.data) {
32+
for (const asset of release.assets) {
33+
if (asset.name.endsWith('.whl')) {
34+
const pkg = asset.name.split('-')[0].toLowerCase();
35+
packages[pkg] = packages[pkg] || [];
36+
packages[pkg].push({ url: asset.browser_download_url, name: asset.name });
3337
}
3438
}
3539
}
36-
// 3. Build directories & HTML
40+
// Build the /simple/ HTML structure
3741
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`;
42+
let rootHtml = '<!DOCTYPE html><html><body>\n';
43+
for (const pkg of Object.keys(packages).sort()) {
44+
rootHtml += `<a href="./${pkg}/">${pkg}</a><br>\n`;
45+
const pkgDir = `simple/${pkg}`;
46+
fs.mkdirSync(pkgDir, { recursive: true });
47+
let pkgHtml = '<!DOCTYPE html><html><body>\n';
48+
for (const file of packages[pkg]) {
49+
pkgHtml += `<a href="${file.url}#${file.name}">${file.name}</a><br>\n`;
4650
}
47-
pkgHtml += '</body></html>\\n';
48-
fs.writeFileSync(`${dir}/index.html`, pkgHtml);
51+
pkgHtml += '</body></html>\n';
52+
fs.writeFileSync(`${pkgDir}/index.html`, pkgHtml);
4953
}
50-
indexHtml += '</body></html>\\n';
51-
fs.writeFileSync('simple/index.html', indexHtml);
54+
rootHtml += '</body></html>\n';
55+
fs.writeFileSync('simple/index.html', rootHtml);
5256
57+
# 3. Package the generated index for Pages
5358
- name: Upload Pages artifact
5459
uses: actions/upload-pages-artifact@v3
5560
with:
5661
path: simple
5762

63+
# 4. Deploy the artifact to GitHub Pages
5864
- name: Deploy to GitHub Pages
5965
uses: actions/deploy-pages@v4

0 commit comments

Comments
 (0)