Skip to content

Fix 16 broken internal and external documentation links #115

Fix 16 broken internal and external documentation links

Fix 16 broken internal and external documentation links #115

Workflow file for this run

name: Deploy PR Preview
on:
pull_request:
types:
- opened
- reopened
- synchronize
- closed
concurrency:
group: preview-${{ github.ref }}
cancel-in-progress: true
jobs:
deploy-preview:
if: github.event.action != 'closed'
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v4.1.7
- name: Setup Node
uses: actions/setup-node@v4.0.3
with:
node-version: 20
cache: yarn
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Generate llms.txt
run: yarn generate:llms
- name: Build static site
env:
BASE: /docs-preview/pr-${{ github.event.number }}/
NEXT_PUBLIC_BASE_PATH: /docs-preview/pr-${{ github.event.number }}
run: yarn build
- name: Checkout docs-preview repository
uses: actions/checkout@v4.1.7
with:
repository: celestiaorg/docs-preview
token: ${{ secrets.PR_PREVIEW_DEPLOY }}
path: docs-preview
- name: Deploy to docs-preview
run: |
# Create target directory
TARGET_DIR="docs-preview/pr-${{ github.event.number }}"
mkdir -p "$TARGET_DIR"
# Remove existing content in target directory to ensure clean deploy
rm -rrf "$TARGET_DIR"/*
# Copy built files
cp -r out/* "$TARGET_DIR"/
# Ensure .nojekyll exists in root
touch docs-preview/.nojekyll
# Commit and Push
cd docs-preview
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add .
# Only commit if there are changes
if git diff --staged --quiet; then
echo "No changes to deploy"
else
git commit -m "Deploy preview for PR #${{ github.event.number }} from ${{ github.sha }}"
git push
fi
- name: Post Preview Link
uses: actions/github-script@v7
with:
script: |
const prNumber = context.payload.pull_request.number;
const previewUrl = `https://celestiaorg.github.io/docs-preview/pr-${prNumber}/`;
const body = `🚀 **Preview Deployment**\n\nYour preview is ready: [${previewUrl}](${previewUrl})`;
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
});
const botComment = comments.find(comment =>
comment.body.includes('🚀 **Preview Deployment**') &&
comment.user.type === 'Bot'
);
if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: body
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: body
});
}
cleanup-preview:
if: github.event.action == 'closed'
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout docs-preview repository
uses: actions/checkout@v4.1.7
with:
repository: celestiaorg/docs-preview
token: ${{ secrets.PR_PREVIEW_DEPLOY }}
path: docs-preview
- name: Remove preview
run: |
TARGET_DIR="docs-preview/pr-${{ github.event.number }}"
if [ -d "$TARGET_DIR" ]; then
rm -rf "$TARGET_DIR"
cd docs-preview
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add .
git commit -m "Remove preview for PR #${{ github.event.number }}"
git push
else
echo "Preview directory $TARGET_DIR does not exist, skipping cleanup."
fi