Skip to content

Commit

Permalink
render notebooks when building docs
Browse files Browse the repository at this point in the history
  • Loading branch information
hrodmn committed Dec 4, 2024
1 parent abe6317 commit 156f54a
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 1,674 deletions.
56 changes: 30 additions & 26 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,63 +84,67 @@ jobs:
git config --global user.email "actions@github.com"
# Checkout gh-pages branch
git restore uv.lock
git restore .
git fetch origin gh-pages --depth=1
git checkout gh-pages
# Create preview directory if it doesn't exist
mkdir -p pr-previews
# Check if there are actual changes in the built site
if [ -d "pr-previews/pr-${{ github.event.pull_request.number }}" ]; then
diff -r site/pr-${{ github.event.pull_request.number }} pr-previews/pr-${{ github.event.pull_request.number }} > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "No changes in documentation. Skipping deployment."
exit 0
fi
fi
# Remove old preview if it exists
rm -rf pr-previews/pr-${{ github.event.pull_request.number }}
# Copy new preview
rm -rf pr-previews/pr-${{ github.event.pull_request.number }}
cp -r site/pr-${{ github.event.pull_request.number }} pr-previews/
# Commit and push
# Check if there are actual changes in git
git add pr-previews
git commit -m "Deploy preview for PR #${{ github.event.pull_request.number }}" || echo "No changes to commit"
git diff --staged --quiet || git push origin gh-pages
if git diff --staged --quiet; then
echo "No changes in documentation. Skipping deployment."
echo "has_changes=false" >> $GITHUB_OUTPUT
exit 0
fi
# If we get here, there are changes
git commit -m "Deploy preview for PR #${{ github.event.pull_request.number }}"
git push origin gh-pages
echo "has_changes=true" >> $GITHUB_OUTPUT
- name: Post/Update PR Review
- name: Post/Update PR Comment
if: github.event.action != 'closed'
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
console.log('Starting PR comment update...');
const has_changes = '${{ steps.deploy.outputs.has_changes }}' === 'true';
const preview_url = `https://${context.repo.owner}.github.io/${context.repo.repo}/pr-previews/pr-${context.payload.pull_request.number}/`;
const message = `📚 Documentation preview will be available at: ${preview_url}
Status: ${has_changes ? '✅ Preview is ready!' : '🔄 No changes in documentation since last update'}`;
const reviews = await github.rest.pulls.listReviews({
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.pull_request.number,
issue_number: context.payload.pull_request.number,
});
const docReview = reviews.data.find(review =>
review.user.login === 'github-actions[bot]' &&
review.body.includes('Documentation preview will be available at:')
const docComment = comments.data.find(comment =>
comment.user.login === 'github-actions[bot]' &&
comment.body.includes('Documentation preview will be available at:')
);
if (!docReview) {
await github.rest.pulls.createReview({
if (docComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: docComment.id,
body: message
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.pull_request.number,
body: message,
event: 'COMMENT'
issue_number: context.payload.pull_request.number,
body: message
});
}
Expand Down
Loading

0 comments on commit 156f54a

Please sign in to comment.