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