Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 92 additions & 19 deletions .github/workflows/preview.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
name: Deploy New Docs Preview
name: Deploy PR Preview

on:
push:
branches:
- docs-glow-up
pull_request:
types:
- opened
- reopened
- synchronize
- closed

concurrency:
group: new-docs-preview
group: preview-${{ github.ref }}
cancel-in-progress: true

jobs:
deploy-new-docs:
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
Expand All @@ -32,8 +37,8 @@ jobs:

- name: Build static site
env:
BASE: /docs-preview/new_docs/
NEXT_PUBLIC_BASE_PATH: /docs-preview/new_docs
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
Expand All @@ -43,28 +48,96 @@ jobs:
token: ${{ secrets.PR_PREVIEW_DEPLOY }}
path: docs-preview

- name: Clear previous new_docs deployment
- name: Deploy to docs-preview
run: |
rm -rf docs-preview/new_docs
mkdir -p docs-preview/new_docs
# Create target directory
TARGET_DIR="docs-preview/pr-${{ github.event.number }}"
mkdir -p "$TARGET_DIR"

- name: Copy built files
run: |
cp -r out/* docs-preview/new_docs/
# Remove existing content in target directory to ensure clean deploy
rm -rrf "$TARGET_DIR"/*

- name: Create .nojekyll file
run: |
# Copy built files
cp -r out/* "$TARGET_DIR"/

# Ensure .nojekyll exists in root
touch docs-preview/.nojekyll

- name: Deploy to docs-preview
run: |
# 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 new docs preview from ${{ github.sha }}"
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
Loading