this repo has no description
at main 131 lines 3.6 kB view raw
1# .github/workflows/deploy-sites.yml 2name: Deploy Subdirectories to GitHub Pages 3 4on: 5 push: 6 branches: [main, master] 7 workflow_dispatch: 8 9permissions: 10 contents: read 11 pages: write 12 id-token: write 13 14concurrency: 15 group: pages 16 cancel-in-progress: false 17 18jobs: 19 discover-sites: 20 runs-on: ubuntu-latest 21 outputs: 22 sites: ${{ steps.find-sites.outputs.sites }} 23 steps: 24 - name: Checkout 25 uses: actions/checkout@v4 26 27 - name: Find site directories 28 id: find-sites 29 run: | 30 # Find all directories containing index.html 31 sites=() 32 for dir in */; do 33 if [ -f "${dir}index.html" ]; then 34 sites+=("${dir%/}") 35 fi 36 done 37 38 # Create JSON array and output on single line 39 sites_json=$(printf '%s\n' "${sites[@]}" | jq -R . | jq -s -c .) 40 echo "sites=$sites_json" >> $GITHUB_OUTPUT 41 echo "Found sites: $sites_json" 42 43 build: 44 runs-on: ubuntu-latest 45 needs: discover-sites 46 strategy: 47 matrix: 48 site: ${{ fromJson(needs.discover-sites.outputs.sites) }} 49 steps: 50 - name: Checkout 51 uses: actions/checkout@v4 52 53 - name: Prepare site build 54 run: | 55 mkdir -p _site/${{ matrix.site }} 56 cp -r ${{ matrix.site }}/* _site/${{ matrix.site }}/ 57 58 - name: Upload site artifact 59 uses: actions/upload-artifact@v4 60 with: 61 name: site-${{ matrix.site }} 62 path: _site 63 64 create-index: 65 runs-on: ubuntu-latest 66 needs: discover-sites 67 steps: 68 - name: Create root index 69 run: | 70 mkdir -p _site 71 cat > _site/index.html << 'EOF' 72 <!DOCTYPE html> 73 <html> 74 <head> 75 <title>Sites Index</title> 76 <style> 77 body { font-family: system-ui, sans-serif; max-width: 800px; margin: 40px auto; padding: 20px; } 78 h1 { color: #333; } 79 ul { list-style: none; padding: 0; } 80 li { margin: 10px 0; } 81 a { color: #0366d6; text-decoration: none; font-size: 1.1em; } 82 a:hover { text-decoration: underline; } 83 </style> 84 </head> 85 <body> 86 <h1>📁 Available Sites</h1> 87 <ul id="sites-list"></ul> 88 <script> 89 const sites = document.getElementById('sites-list'); 90 fetch('./sites.json') 91 .then(r => r.json()) 92 .then(data => { 93 data.forEach(site => { 94 const li = document.createElement('li'); 95 const a = document.createElement('a'); 96 a.href = './' + site + '/'; 97 a.textContent = site; 98 li.appendChild(a); 99 sites.appendChild(li); 100 }); 101 }); 102 </script> 103 </body> 104 </html> 105 EOF 106 echo '${{ needs.discover-sites.outputs.sites }}' > _site/sites.json 107 108 - name: Upload index artifact 109 uses: actions/upload-artifact@v4 110 with: 111 name: site-index 112 path: _site 113 114 merge-and-deploy: 115 runs-on: ubuntu-latest 116 needs: [discover-sites, build, create-index] 117 steps: 118 - name: Download all artifacts 119 uses: actions/download-artifact@v4 120 with: 121 path: _site 122 pattern: site-* 123 merge-multiple: true 124 125 - name: Upload to GitHub Pages 126 uses: actions/upload-pages-artifact@v3 127 with: 128 path: _site 129 130 - name: Deploy to GitHub Pages 131 uses: actions/deploy-pages@v4