Skip to content

docs-updated

docs-updated #274

name: Site Build and Deploy
on:
pull_request:
push:
branches: [main]
repository_dispatch:
types: [docs-updated]
workflow_dispatch:
permissions:
contents: read
pull-requests: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v5
- name: Setup Node
uses: actions/setup-node@v5
with:
node-version: 24
- name: Sync docs
run: npm run sync:docs
env:
REACT_ON_RAILS_REPO_URL: https://github.com/shakacode/react_on_rails.git
REACT_ON_RAILS_REF: main
- name: Prepare docs
run: npm run prepare:docs
- name: Audit docs
id: audit_docs
continue-on-error: true
run: npm run audit:docs -- --output VALIDATION_REPORT_CI.md --fail-on error
- name: Upload docs audit report
if: always()
uses: actions/upload-artifact@v4
with:
name: docs-audit-report
path: VALIDATION_REPORT_CI.md
if-no-files-found: error
- name: Add docs audit summary
if: always()
run: |
{
echo "### Docs Audit"
echo ""
grep -E '^(Pages scanned|Pages with findings|Pages with errors|Pages with warnings|Pages with info|Errors|Warnings|Info):' VALIDATION_REPORT_CI.md || true
echo ""
echo "- Artifact: \`docs-audit-report\`"
} >> "$GITHUB_STEP_SUMMARY"
- name: Fail on blocking docs audit findings
if: steps.audit_docs.outcome == 'failure'
run: exit 1
- name: Install site dependencies
run: npm --prefix prototypes/docusaurus install
- name: Build site
run: npm run build
env:
ALGOLIA_APP_ID: ${{ vars.ALGOLIA_APP_ID }}
ALGOLIA_SEARCH_API_KEY: ${{ vars.ALGOLIA_SEARCH_API_KEY }}
ALGOLIA_INDEX_NAME: ${{ vars.ALGOLIA_INDEX_NAME }}
deploy:
if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'repository_dispatch' || github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == false)
needs: build
runs-on: ubuntu-latest
environment:
name: pages-deploy
url: ${{ steps.deploy.outputs.deployment_url }}
steps:
- name: Checkout
uses: actions/checkout@v5
- name: Setup Node
uses: actions/setup-node@v5
with:
node-version: 24
- name: Sync docs
run: npm run sync:docs
env:
REACT_ON_RAILS_REPO_URL: https://github.com/shakacode/react_on_rails.git
REACT_ON_RAILS_REF: main
- name: Prepare docs
run: npm run prepare:docs
- name: Install site dependencies
run: npm --prefix prototypes/docusaurus install
- name: Build site
run: npm run build
env:
ALGOLIA_APP_ID: ${{ vars.ALGOLIA_APP_ID }}
ALGOLIA_SEARCH_API_KEY: ${{ vars.ALGOLIA_SEARCH_API_KEY }}
ALGOLIA_INDEX_NAME: ${{ vars.ALGOLIA_INDEX_NAME }}
- name: Determine deploy branch
id: deploy_branch
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
echo "branch=pr-${{ github.event.pull_request.number }}" >> "$GITHUB_OUTPUT"
elif [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "branch=${{ github.ref_name }}" >> "$GITHUB_OUTPUT"
else
echo "branch=main" >> "$GITHUB_OUTPUT"
fi
- name: Deploy to Cloudflare Pages
id: deploy
run: |
set -euo pipefail
npx wrangler pages deploy prototypes/docusaurus/build \
--project-name "${CLOUDFLARE_PAGES_PROJECT:-reactonrails-com}" \
--branch "${{ steps.deploy_branch.outputs.branch }}" | tee /tmp/wrangler-pages-deploy.log
DEPLOYMENT_URL="$(grep -Eo 'https://[^ ]+\.pages\.dev' /tmp/wrangler-pages-deploy.log | head -n 1 || true)"
if [ -z "$DEPLOYMENT_URL" ]; then
if [ "${{ steps.deploy_branch.outputs.branch }}" = "main" ]; then
DEPLOYMENT_URL="https://reactonrails.com"
else
SAFE_BRANCH="$(echo "${{ steps.deploy_branch.outputs.branch }}" | sed 's/[^A-Za-z0-9-]/-/g')"
DEPLOYMENT_URL="https://${SAFE_BRANCH}.${CLOUDFLARE_PAGES_PROJECT:-reactonrails-com}.pages.dev"
fi
fi
echo "deployment_url=$DEPLOYMENT_URL" >> "$GITHUB_OUTPUT"
{
echo "### Cloudflare Pages Deployment"
echo ""
echo "- Branch: \`${{ steps.deploy_branch.outputs.branch }}\`"
echo "- URL: $DEPLOYMENT_URL"
} >> "$GITHUB_STEP_SUMMARY"
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
CLOUDFLARE_PAGES_PROJECT: ${{ vars.CLOUDFLARE_PAGES_PROJECT }}
- name: Comment preview URL
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
env:
DEPLOYMENT_URL: ${{ steps.deploy.outputs.deployment_url }}
DEPLOY_BRANCH: ${{ steps.deploy_branch.outputs.branch }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const marker = "<!-- cf-pages-preview -->";
const body = `${marker}
Cloudflare preview deployed.
- Branch: \`${process.env.DEPLOY_BRANCH}\`
- URL: ${process.env.DEPLOYMENT_URL}`;
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
per_page: 100,
});
const existing = comments.find((comment) =>
comment.user?.type === "Bot" && comment.body?.includes(marker)
);
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
}