Update pages.yml #31
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy to GitHub Pages (force-write repo URL with debug) | |
| on: | |
| push: | |
| branches: [ main ] | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| pages: write | |
| id-token: write | |
| concurrency: | |
| group: "pages" | |
| cancel-in-progress: true | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout this repo | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 1 | |
| - name: Install tools | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y pandoc jq | |
| - id: build_page | |
| name: Build index.html (keep existing, or README -> HTML) | |
| env: | |
| REPO_HTML_TITLE: ${{ github.repository }} | |
| run: | | |
| set -euo pipefail | |
| if [ -f index.html ]; then | |
| echo "Keeping existing index.html (not regenerating)." | |
| elif [ -f README.md ]; then | |
| pandoc README.md -f markdown -t html -s --highlight-style=tango -o index.html --metadata title="$REPO_HTML_TITLE" | |
| else | |
| printf '%s\n' '<!doctype html><html><head><meta charset="utf-8"><title>Site</title></head><body>' '<h1>Site</h1>' '<p>No README.md found. Add one and push to regenerate this page.</p>' '</body></html>' > index.html | |
| fi | |
| # Minimal CSS injection | |
| CSS_BLOCK='<style>body{font-family:Arial,Helvetica,sans-serif} pre code{display:block;padding:.75em;background:#f6f8fa;border-radius:6px;font-size:90%;overflow:auto}</style>' | |
| if grep -qi '</head>' index.html; then | |
| awk -v css="$CSS_BLOCK" 'BEGIN{IGNORECASE=1} { if (!done && match(tolower($0), /</head>/)) { sub(/</head>/, css"</head>"); done=1 } print }' index.html > index.html.tmp | |
| mv index.html.tmp index.html | |
| else | |
| TMP=$(mktemp) | |
| printf '%s\n' '<!doctype html><html><head><meta charset="utf-8">' "${CSS_BLOCK}" '</head><body>' > "$TMP" | |
| cat index.html >> "$TMP" | |
| printf '%s\n' '</body></html>' >> "$TMP" | |
| mv "$TMP" index.html | |
| fi | |
| - name: Force-write License/Citation/BibTeX/Repository with URL + DEBUG | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| REPO: ${{ github.repository }} | |
| shell: bash | |
| run: | | |
| set -Eeuo pipefail | |
| REPO_NAME="${REPO#*/}" | |
| REPO_URL="https://github.com/$REPO" | |
| LAST_UPDATE=$(git log -1 --format=%cI || date -u +%Y-%m-%dT%H:%M:%SZ) | |
| YEAR=$(date -u -d "$LAST_UPDATE" +%Y 2>/dev/null || date -u +%Y) | |
| echo "DEBUG: REPO=$REPO" | |
| echo "DEBUG: REPO_URL=$REPO_URL" | |
| echo "DEBUG: LAST_UPDATE=$LAST_UPDATE" | |
| logins=$(curl -s -H "Authorization: Bearer $GH_TOKEN" "https://api.github.com/repos/$REPO/contributors?per_page=100&anon=false" | jq -r '.[] | select((.type // "") != "Bot") | select(.login != "ghost") | .login' | sort -fu) | |
| names="" | |
| for u in $logins; do | |
| name=$(curl -s -H "Authorization: Bearer $GH_TOKEN" "https://api.github.com/users/$u" | jq -r '.name // empty') | |
| [ -z "$name" ] && name="$u" | |
| names="$names\n$name" | |
| done | |
| names_sorted=$(printf "%b" "$names" | awk 'NF' | sort -fu) | |
| citation_written="Steph Buongiorno" | |
| if [ -n "$names_sorted" ]; then | |
| citation_written="$citation_written; $(echo "$names_sorted" | paste -sd ', ' -)" | |
| fi | |
| citation_written="$citation_written. $REPO_NAME. $YEAR. Available at: $REPO_URL" | |
| authors_bibtex="Steph Buongiorno" | |
| if [ -n "$names_sorted" ]; then | |
| authors_bibtex="$authors_bibtex and $(echo "$names_sorted" | paste -sd ' and ' -)" | |
| fi | |
| bibtex="@misc{$REPO_NAME-$YEAR, | |
| author = {$authors_bibtex}, | |
| title = {$REPO_NAME}, | |
| year = {$YEAR}, | |
| howpublished = {\\url{$REPO_URL}}, | |
| note = {Last updated: $LAST_UPDATE} | |
| }" | |
| # Remove any previous block entirely and append a fresh one | |
| awk 'BEGIN{p=1} /<!-- BEGIN-REPO-META -->/{p=0} /<!-- END-REPO-META -->/{next} p{print}' index.html > index.clean.html || true | |
| mv index.clean.html index.html || true | |
| cat >> index.html <<HTMLBLOCK | |
| <!-- BEGIN-REPO-META --> | |
| <hr> | |
| <h2>License</h2> | |
| <p>This project is licensed under the <a href="LICENSE">MIT License</a>.</p> | |
| <h2>Suggested Citation</h2> | |
| <p>$citation_written</p> | |
| <h3>BibTeX</h3> | |
| <pre><code>$bibtex</code></pre> | |
| <h3>Repository</h3> | |
| <p><em>$REPO_NAME</em><br> | |
| <a href="$REPO_URL">$REPO_URL</a><br> | |
| <strong>Last updated:</strong> $LAST_UPDATE</p> | |
| <!-- END-REPO-META --> | |
| HTMLBLOCK | |
| echo "---------- FINAL LINES OF index.html ----------" | |
| tail -n 60 index.html | |
| - name: Upload site artifact | |
| uses: actions/upload-pages-artifact@v3 | |
| with: | |
| path: . | |
| deploy: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: github-pages | |
| url: ${{ steps.deployment.outputs.page_url }} | |
| steps: | |
| - id: deployment | |
| uses: actions/deploy-pages@v4 |