|
| 1 | +name: Publish README to GitHub Pages |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +concurrency: |
| 9 | + group: gh-pages-readme |
| 10 | + cancel-in-progress: false |
| 11 | + |
| 12 | +permissions: |
| 13 | + contents: write |
| 14 | + |
| 15 | +jobs: |
| 16 | + publish: |
| 17 | + name: Update gh-pages index.html from README |
| 18 | + runs-on: ubuntu-latest |
| 19 | + timeout-minutes: 10 |
| 20 | + steps: |
| 21 | + - name: Checkout main |
| 22 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 23 | + with: |
| 24 | + fetch-depth: 0 |
| 25 | + |
| 26 | + - name: Render README.md to HTML (GFM) |
| 27 | + id: render |
| 28 | + env: |
| 29 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 30 | + run: | |
| 31 | + payload="$(jq -n \ |
| 32 | + --arg text "$(cat README.md)" \ |
| 33 | + --arg mode "gfm" \ |
| 34 | + --arg context "${GITHUB_REPOSITORY}" \ |
| 35 | + '{text:$text,mode:$mode,context:$context}')" |
| 36 | +
|
| 37 | + html="$(curl -fsSL \ |
| 38 | + -H "Authorization: Bearer ${GITHUB_TOKEN}" \ |
| 39 | + -H "Accept: application/vnd.github+json" \ |
| 40 | + https://api.github.com/markdown \ |
| 41 | + -d "${payload}")" |
| 42 | +
|
| 43 | + cat > index.html <<'EOF' |
| 44 | + <!doctype html> |
| 45 | + <html lang="en"> |
| 46 | + <head> |
| 47 | + <meta charset="utf-8" /> |
| 48 | + <meta name="viewport" content="width=device-width,initial-scale=1" /> |
| 49 | + <title>Kaytoo</title> |
| 50 | + <link rel="stylesheet" href="https://unpkg.com/github-markdown-css@5.8.1/github-markdown.css" /> |
| 51 | + <style> |
| 52 | + body { margin: 0; } |
| 53 | + .markdown-body { box-sizing: border-box; min-width: 200px; max-width: 980px; margin: 0 auto; padding: 32px 20px; } |
| 54 | + </style> |
| 55 | + </head> |
| 56 | + <body> |
| 57 | + <article class="markdown-body"> |
| 58 | + EOF |
| 59 | +
|
| 60 | + printf '%s\n' "${html}" >> index.html |
| 61 | +
|
| 62 | + cat >> index.html <<'EOF' |
| 63 | + </article> |
| 64 | + </body> |
| 65 | + </html> |
| 66 | + EOF |
| 67 | +
|
| 68 | + - name: Checkout gh-pages |
| 69 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 70 | + with: |
| 71 | + ref: gh-pages |
| 72 | + path: gh-pages |
| 73 | + fetch-depth: 0 |
| 74 | + |
| 75 | + - name: Update gh-pages index.html |
| 76 | + run: | |
| 77 | + cp index.html gh-pages/index.html |
| 78 | + touch gh-pages/.nojekyll |
| 79 | +
|
| 80 | + - name: Commit and push (if changed) |
| 81 | + run: | |
| 82 | + cd gh-pages |
| 83 | + if git diff --quiet; then |
| 84 | + echo "No changes to publish." |
| 85 | + exit 0 |
| 86 | + fi |
| 87 | + git config user.name "${GITHUB_ACTOR}" |
| 88 | + git config user.email "${GITHUB_ACTOR}@users.noreply.github.com" |
| 89 | + git add index.html .nojekyll |
| 90 | + git commit -m "chore(pages): publish README from main" |
| 91 | + git push |
| 92 | +
|
0 commit comments