|
1 | | -name: Build & Publish pip Simple Index |
| 1 | +name: Build & Deploy pip Simple Index |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | workflow_dispatch: |
5 | 5 |
|
6 | 6 | 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 |
9 | 10 |
|
10 | 11 | jobs: |
11 | 12 | publish-index: |
12 | 13 | runs-on: ubuntu-latest |
| 14 | + |
13 | 15 | steps: |
14 | | - - name: Checkout default branch |
| 16 | + # 1. Check out the default branch so we have repo context |
| 17 | + - name: Checkout repository |
15 | 18 | uses: actions/checkout@v4 |
16 | 19 |
|
| 20 | + # 2. Generate PEP 503 “simple” index from release assets |
17 | 21 | - name: Generate pip simple index |
18 | 22 | uses: actions/github-script@v6 |
19 | 23 | with: |
20 | 24 | script: | |
21 | 25 | const fs = require('fs'); |
22 | 26 | const { owner, repo } = context.repo; |
23 | | - // 1. List all releases |
| 27 | + // Fetch all releases via the GitHub API |
24 | 28 | 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 }); |
33 | 37 | } |
34 | 38 | } |
35 | 39 | } |
36 | | - // 3. Build directories & HTML |
| 40 | + // Build the /simple/ HTML structure |
37 | 41 | 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`; |
46 | 50 | } |
47 | | - pkgHtml += '</body></html>\\n'; |
48 | | - fs.writeFileSync(`${dir}/index.html`, pkgHtml); |
| 51 | + pkgHtml += '</body></html>\n'; |
| 52 | + fs.writeFileSync(`${pkgDir}/index.html`, pkgHtml); |
49 | 53 | } |
50 | | - indexHtml += '</body></html>\\n'; |
51 | | - fs.writeFileSync('simple/index.html', indexHtml); |
| 54 | + rootHtml += '</body></html>\n'; |
| 55 | + fs.writeFileSync('simple/index.html', rootHtml); |
52 | 56 |
|
| 57 | + # 3. Package the generated index for Pages |
53 | 58 | - name: Upload Pages artifact |
54 | 59 | uses: actions/upload-pages-artifact@v3 |
55 | 60 | with: |
56 | 61 | path: simple |
57 | 62 |
|
| 63 | + # 4. Deploy the artifact to GitHub Pages |
58 | 64 | - name: Deploy to GitHub Pages |
59 | 65 | uses: actions/deploy-pages@v4 |
0 commit comments