-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c33ddbd
commit d786e1d
Showing
1 changed file
with
23 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,23 +32,35 @@ jobs: | |
|
||
- name: Deploy preview | ||
run: | | ||
BRANCH_NAME="preview-pr-${{ github.event.pull_request.number }}" | ||
# Create a temporary directory for the preview | ||
PR_DIR="pr-${{ github.event.pull_request.number }}" | ||
# Configure git | ||
git config --global user.name "GitHub Actions" | ||
git config --global user.email "[email protected]" | ||
git checkout -b $BRANCH_NAME | ||
# Fetch gh-pages branch if it exists, or create it | ||
if git fetch origin gh-pages; then | ||
git checkout gh-pages | ||
else | ||
git checkout --orphan gh-pages | ||
git rm -rf . | ||
git commit --allow-empty -m "Initial gh-pages branch" | ||
fi | ||
# Remove existing content except _site and .git | ||
find . -mindepth 1 -maxdepth 1 ! -name '_site' ! -name '.git' -exec rm -rf {} + | ||
# Remove previous preview if it exists | ||
if [ -d "$PR_DIR" ]; then | ||
rm -rf "$PR_DIR" | ||
fi | ||
# Move _site contents to root | ||
cp -r _site/* ./ | ||
rm -rf _site | ||
# Move built site to PR-specific directory | ||
mkdir -p "$PR_DIR" | ||
cp -r _site/* "$PR_DIR/" | ||
# Commit and push | ||
git add . | ||
git commit -m "Deploy PR preview" | ||
git push origin $BRANCH_NAME --force | ||
git commit -m "Deploy preview for PR #${{ github.event.pull_request.number }}" | ||
git push origin gh-pages | ||
- name: Comment PR | ||
uses: actions/github-script@v7 | ||
|
@@ -57,11 +69,11 @@ jobs: | |
const prNumber = context.issue.number; | ||
const repoName = context.repo.repo; | ||
const ownerName = context.repo.owner; | ||
const previewUrl = `https://${ownerName}.github.io/${repoName}/preview-pr-${prNumber}/`; | ||
const previewUrl = `https://${ownerName}.github.io/${repoName}/pr-${prNumber}/`; | ||
github.rest.issues.createComment({ | ||
owner: ownerName, | ||
repo: repoName, | ||
issue_number: prNumber, | ||
body: `📝 Preview this PR at: ${previewUrl}` | ||
body: `📝 Preview this PR at: ${previewUrl}\n\nNote: It may take a few minutes for GitHub Pages to update.` | ||
}); |