stagit-build.yml (3653B)
1 name: Build Stagit Portal 2 3 on: 4 schedule: 5 - cron: '36 */3 * * *' 6 repository_dispatch: 7 types: [repo_pushed] 8 workflow_dispatch: 9 10 jobs: 11 build: 12 runs-on: ubuntu-latest 13 permissions: 14 contents: write 15 pages: write 16 id-token: write 17 18 steps: 19 - name: Install dependencies & stagit 20 run: | 21 sudo apt-get update 22 sudo apt-get install -y libgit2-dev gcc make 23 git clone https://github.com/oxalorg/stagit.git /tmp/stagit 24 cd /tmp/stagit 25 sed -i 's/#define maxfilesize .*/#define maxfilesize (1024 * 1024 * 2)/g' stagit.c || true 26 make -j$(nproc) 27 sudo make install 28 29 - name: Clone All Repositories 30 env: 31 GH_TOKEN: ${{ secrets.PORTAL_PAT }} 32 run: | 33 git config --global url."https://x-access-token:${GH_TOKEN}@github.com/".insteadOf "https://github.com/" 34 35 mkdir -p repositories 36 37 gh repo list --limit 1000 --json url -q '.[].url' | while read -r url; do 38 [ -z "$url" ] && continue 39 repo_name=$(basename "$url" .git) 40 git clone --bare "$url" "repositories/${repo_name}.git" 41 done 42 43 - name: Generate Stagit HTML 44 run: | 45 mkdir -p html 46 ROOT_DIR="$(pwd)" 47 48 for repo_dir in "${ROOT_DIR}/repositories"/*.git; do 49 [ -d "$repo_dir" ] || continue 50 51 repo_name=$(basename "$repo_dir" .git) 52 site_dir="${ROOT_DIR}/html/${repo_name}" 53 54 mkdir -p "$site_dir" 55 56 (cd "$site_dir" && stagit "$repo_dir") 57 done 58 59 (cd "${ROOT_DIR}/repositories" && stagit-index *.git > "${ROOT_DIR}/html/index.html") 60 61 - name: Purge oversized HTML files for Cloudflare Pages 62 run: | 63 echo "Checking for files larger than 20MB..." 64 65 # 20MBを超えるHTMLファイルを検出して置換 66 find html -type f -size +20M -name "*.html" | while read -r file; do 67 filesize=$(du -h "$file" | cut -f1) 68 echo "PURGING: $file ($filesize) exceeds Cloudflare Pages limits." 69 70 cat << 'EOF' > "$file" 71 <!DOCTYPE html> 72 <html> 73 <head> 74 <meta charset="utf-8"> 75 <title>File Truncated</title> 76 <style> 77 body { font-family: sans-serif; margin: 2em; background: #fdf6e3; color: #657b83; } 78 .box { border: 2px solid #dc322f; padding: 1.5em; border-radius: 4px; background: #fff; } 79 h1 { color: #dc322f; margin-top: 0; } 80 </style> 81 </head> 82 <body> 83 <div class="box"> 84 <h1>⚠️ Diff/File Exceeds Size Limit</h1> 85 <p>This page was omitted from the static build because its generated size exceeds Cloudflare Pages' 25MB single-file limit.</p> 86 <p>Please inspect this commit or file locally in your git clone.</p> 87 </div> 88 </body> 89 </html> 90 EOF 91 done 92 93 - name: Push ./html to gh-pages branch 94 env: 95 GH_TOKEN: ${{ secrets.PORTAL_PAT }} 96 run: | 97 cd html 98 git init 99 git config user.name "github-actions[bot]" 100 git config user.email "github-actions[bot]@users.noreply.github.com" 101 102 git add -A 103 git commit -m "deploy: update stagit portal site" 104 105 # PORTAL_PAT を使って gh-pages ブランチに強制プッシュ 106 git push -f "https://x-access-token:${GH_TOKEN}@github.com/${{ github.repository }}.git" HEAD:gh-pages