arnaucube
arnaucube/davinci-paperPublic Self-hosted repository
davinci-paper/.github/workflows/build-and-deploy.yml
.github/workflows/build-and-deploy.ymlRaw
  1name: Build & Deploy Paper
  2
  3on:
  4  push:
  5    branches: ["main"]
  6
  7jobs:
  8  build_and_deploy:
  9    runs-on: ubuntu-latest
 10    permissions:
 11      contents: write
 12
 13    steps:
 14      - name: Checkout repo
 15        uses: actions/checkout@v4
 16
 17      - name: Install tools
 18        run: |
 19          sudo apt-get update
 20          sudo apt-get install -y pandoc texlive-latex-recommended texlive-bibtex-extra texlive-extra-utils          
 21
 22      - name: Convert LaTeX to Markdown
 23        run: |
 24          ./scripts/convert-paper.sh          
 25
 26      - name: Build Markdown preview page
 27        run: |
 28          touch docs/.nojekyll
 29          cat << 'EOF' > docs/index.html
 30          <!DOCTYPE html>
 31          <html lang="en">
 32          <head>
 33            <meta charset="UTF-8">
 34            <meta name="viewport" content="width=device-width, initial-scale=1.0">
 35            <title>DaVinci Paper (Markdown)</title>
 36            <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/github-markdown-css@5.8.1/github-markdown.min.css">
 37            <style>
 38              :root { color-scheme: light; }
 39              body {
 40                margin: 0;
 41                background: #f6f8fa;
 42                color: #24292f;
 43              }
 44              .topbar {
 45                position: sticky;
 46                top: 0;
 47                z-index: 2;
 48                display: flex;
 49                gap: 12px;
 50                align-items: center;
 51                padding: 12px 16px;
 52                border-bottom: 1px solid #d0d7de;
 53                background: #ffffff;
 54              }
 55              .topbar a {
 56                text-decoration: none;
 57                border: 1px solid #d0d7de;
 58                border-radius: 6px;
 59                padding: 6px 10px;
 60                color: #24292f;
 61                background: #f6f8fa;
 62                font: 600 14px/1.2 -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
 63              }
 64              .markdown-body {
 65                box-sizing: border-box;
 66                min-width: 200px;
 67                max-width: 980px;
 68                margin: 0 auto;
 69                padding: 28px 20px 40px;
 70                background: #fff;
 71              }
 72              #status {
 73                margin-left: auto;
 74                font: 500 13px/1.3 -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
 75                color: #57606a;
 76              }
 77              @media (max-width: 767px) {
 78                .markdown-body { padding: 20px 16px 28px; }
 79              }
 80            </style>
 81          </head>
 82          <body>
 83            <div class="topbar">
 84              <a href="paper.md" download>Download paper.md</a>
 85              <a href="paper.md" target="_blank" rel="noopener noreferrer">Open raw markdown</a>
 86              <span id="status">Loading markdown...</span>
 87            </div>
 88            <article id="content" class="markdown-body"></article>
 89            <script src="https://cdn.jsdelivr.net/npm/marked@15.0.12/lib/marked.umd.min.js"></script>
 90            <script src="https://cdn.jsdelivr.net/npm/dompurify@3.1.7/dist/purify.min.js"></script>
 91            <script>
 92              (async () => {
 93                const status = document.getElementById('status');
 94                const content = document.getElementById('content');
 95                try {
 96                  const response = await fetch('paper.md', { cache: 'no-store' });
 97                  if (!response.ok) {
 98                    throw new Error('HTTP ' + response.status);
 99                  }
100                  const md = await response.text();
101                  marked.setOptions({ gfm: true, breaks: false });
102                  const html = marked.parse(md);
103                  content.innerHTML = DOMPurify.sanitize(html);
104                  status.textContent = 'Loaded';
105                } catch (err) {
106                  status.textContent = 'Failed to load markdown';
107                  content.innerHTML = '<p>Unable to render <code>paper.md</code>.</p><p>' + err.message + '</p>';
108                }
109              })();
110            </script>
111          </body>
112          </html>
113          EOF          
114
115      - name: Deploy to GitHub Pages
116        uses: peaceiris/actions-gh-pages@v4
117        with:
118          github_token: ${{ secrets.GITHUB_TOKEN }}
119          publish_dir: ./docs
120
121      - name: Upload paper.md artifact
122        uses: actions/upload-artifact@v4
123        with:
124          name: paper-markdown
125          path: docs/paper.md
126          if-no-files-found: error