diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..f425f28 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,59 @@ +# Builds the docs and deploys them to Cloudflare (see wrangler.toml). +# push to main -> production, docs.mida.so +# pull request -> a preview URL, posted as a comment on the PR +name: Deploy docs + +on: + push: + branches: [main] + pull_request: + +concurrency: + group: deploy-${{ github.ref }} + cancel-in-progress: true + +jobs: + deploy: + # pull requests from forks don't get the Cloudflare secrets, so they only build + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: write + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 20 + cache: npm + - run: npm ci + - run: npm run build + + - name: Deploy to docs.mida.so + if: github.event_name == 'push' + uses: cloudflare/wrangler-action@v3 + with: + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + wranglerVersion: '4.86.0' + command: deploy + + - name: Upload preview + if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository + uses: cloudflare/wrangler-action@v3 + with: + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + wranglerVersion: '4.86.0' + command: versions upload --preview-alias pr-${{ github.event.pull_request.number }} + + - name: Comment the preview URL + if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository + uses: actions/github-script@v7 + with: + script: | + const url = `https://pr-${context.issue.number}-mida-docs.donald-929.workers.dev`; + const body = `Preview of this pull request: ${url}\n\n(updated for ${context.sha.slice(0, 7)})`; + const { data: comments } = await github.rest.issues.listComments({ ...context.repo, issue_number: context.issue.number }); + const mine = comments.find(c => c.user.type === 'Bot' && c.body.startsWith('Preview of this pull request')); + if (mine) await github.rest.issues.updateComment({ ...context.repo, comment_id: mine.id, body }); + else await github.rest.issues.createComment({ ...context.repo, issue_number: context.issue.number, body }); diff --git a/wrangler.toml b/wrangler.toml new file mode 100644 index 0000000..fb9d85d --- /dev/null +++ b/wrangler.toml @@ -0,0 +1,12 @@ +# docs.mida.so: the Docusaurus build served as static assets by a Cloudflare Worker (free: static asset requests aren't billed). +# Deploys from GitHub Actions (.github/workflows/deploy.yml): main -> production, pull requests -> preview URL. +name = "mida-docs" +compatibility_date = "2026-10-01" +workers_dev = true +preview_urls = true +routes = [{ pattern = "docs.mida.so", custom_domain = true }] + +[assets] +directory = "./build" +html_handling = "drop-trailing-slash" +not_found_handling = "404-page"