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
56 changes: 46 additions & 10 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
name: PR Preview & GitHub Pages Publish

on:
pull_request:
types: [opened, synchronize, reopened, closed]
push:
branches:
- main

permissions:
contents: write # gh-pages + cleanup
pull-requests: write # PR comments
pages: write # deploy-pages
id-token: write # required by deploy-pages
contents: write
pull-requests: write
pages: write
id-token: write

concurrency:
group: pages-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
if: github.event.action != 'closed'
Expand Down Expand Up @@ -39,7 +46,9 @@ jobs:
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: site
publish_branch: gh-pages
destination_dir: pr-${{ github.event.pull_request.number }}
keep_files: true

- name: Comment PR with preview URL
if: github.event_name == 'pull_request'
Expand All @@ -48,15 +57,38 @@ jobs:
script: |
const pr = context.payload.pull_request.number;
const { owner, repo } = context.repo;

const url = `https://ff4j.github.io/docs/pr-${pr}/`;
const marker = "<!-- pr-preview-comment -->";

const body = `${marker} \n **Site preview available** 🔗 ${url}`;

await github.rest.issues.createComment({
const { data: comments } = await github.rest.issues.listComments({
owner,
repo,
issue_number: pr,
body: `📘 **Site preview available**:\n\n${url}`
});

const existing = comments.find(comment =>
comment.body?.includes(marker)
);
Comment on lines +65 to +73
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issues.listComments is paginated (default 30). If a PR has more than one page of comments, the marker comment may not be found and this can create duplicate preview comments. Consider requesting a larger per_page and/or paging through results (or using the paginate helper) before deciding whether to create vs update.

Copilot uses AI. Check for mistakes.

if (existing) {
// Update existing comment
await github.rest.issues.updateComment({
owner,
repo,
comment_id: existing.id,
body,
});
} else {
// Create new comment
await github.rest.issues.createComment({
owner,
repo,
issue_number: pr,
body,
});
}

- name: Upload Pages artifact
if: github.event_name == 'push'
Expand All @@ -76,8 +108,7 @@ jobs:

cleanup:
if: github.event_name == 'pull_request' &&
github.event.action == 'closed' &&
github.event.pull_request.merged == false
github.event.action == 'closed'
Comment on lines 110 to +111
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cleanup job now runs on every PR close, including merged PRs (previously it skipped merged==true). This changes behavior by deleting merged PR previews as soon as the PR is merged/closed; please confirm that’s intended (and update the PR description if so).

Copilot uses AI. Check for mistakes.
runs-on: ubuntu-latest

steps:
Expand All @@ -88,7 +119,12 @@ jobs:

- name: Remove PR preview folder
run: |
rm -rf pr-${{ github.event.pull_request.number }}
if [ -d "pr-${{ github.event.pull_request.number }}" ]; then
rm -rf pr-${{ github.event.pull_request.number }}
echo "Preview folder removed."
else
echo "Preview folder does not exist."
fi

- name: Commit cleanup
run: |
Expand Down