Skip to content
Merged
Show file tree
Hide file tree
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
32 changes: 32 additions & 0 deletions .github/workflows/docs-pr-cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Clean up PR doc preview

on:
pull_request:
types: [closed]
branches: [main, dev]

permissions:
contents: write

jobs:
cleanup:
runs-on: ubuntu-latest
steps:
- name: Checkout gh-pages branch
uses: actions/checkout@v3
with:
ref: gh-pages
fetch-depth: 0

- name: Remove PR preview directory
run: |
PR_DIR="pr-${{ github.event.pull_request.number }}"
if [ -d "$PR_DIR" ]; then
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git rm -rf "$PR_DIR"
git commit -m "Remove doc preview for PR #${{ github.event.pull_request.number }}"
git push
else
echo "No preview directory found for PR #${{ github.event.pull_request.number }}, nothing to clean up."
fi
46 changes: 45 additions & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ on:
branches: [ main, dev ]

permissions:
contents: write
contents: write
pull-requests: write

jobs:
build:
Expand Down Expand Up @@ -104,4 +105,47 @@ jobs:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: doc/_build/html

- name: Deploy PR Preview
if: github.event_name == 'pull_request'
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: doc/_build/html
destination_dir: pr-${{ github.event.pull_request.number }}
keep_files: true

- name: Comment PR Preview URL
if: github.event_name == 'pull_request'
uses: actions/github-script@v6
with:
script: |
const pr = context.payload.pull_request;
const previewUrl = `https://griffithslab.github.io/whobpyt/pr-${pr.number}/`;
const body = `📖 **Documentation preview** for this PR is available at:\n${previewUrl}\n\n_This preview will be updated as you push new commits to this PR._`;

const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
});

const botComment = comments.data.find(c =>
c.user.type === 'Bot' && c.body.includes('Documentation preview')
);

if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
body,
});
}

Loading