Skip to content

ci(preview): use pull_request_target to allow secrets in fork PRs#445

Merged
vitormattos merged 2 commits into
mainfrom
fix/preview-fork-pr-secrets
Jul 10, 2026
Merged

ci(preview): use pull_request_target to allow secrets in fork PRs#445
vitormattos merged 2 commits into
mainfrom
fix/preview-fork-pr-secrets

Conversation

@vitormattos

Copy link
Copy Markdown
Member

Problem

Preview deploy was failing for all PRs originating from forks (Weblate, external contributors):

remote: Invalid username or token.
fatal: Authentication failed for 'https://github.com/LibreSign/site-preview.git/'

Root cause: GitHub Actions does not expose repository secrets to workflows triggered by pull_request when the PR comes from a fork. The Weblate bot opens PRs from weblate/site-1 (a fork), so PREVIEW_TOKEN arrived as an empty string — push failed immediately.

This is separate from the wait-for-pages-deployment timeout fixed in #444. That fix prevented a timeout for same-repo PRs; this fix allows fork PRs to work at all.

Fix

Switch to pull_request_target and explicitly check out the PR head SHA:

Before After
Event pull_request pull_request_target
Secrets for fork PRs ❌ not available ✅ available
Code checked out default (base) github.event.pull_request.head.sha (PR head)

pull_request_target runs in the context of the base repository (where secrets live). The explicit ref ensures we always build the contributor's branch, not the base branch.

Security note

pull_request_target with an explicit checkout of the PR head does expose secrets to the PR code during the build. For this repository the secrets used in the build are:

  • WC_CONSUMER_KEY / WC_CONSUMER_SECRET: read-only WooCommerce credentials to fetch public pricing data
  • PREVIEW_TOKEN: used only to push to LibreSign/site-preview (a preview-only repository)

This risk is acceptable for an open-source project where contributors are generally trusted. Weblate PRs contain only translation changes and never touch build scripts.

The preview workflow was failing for PRs from forks (e.g. Weblate
translations at weblate/site-1) with:

  remote: Invalid username or token.
  fatal: Authentication failed for .../site-preview.git/

GitHub Actions does not make repository secrets available to workflows
triggered by pull_request when the PR comes from a fork. PREVIEW_TOKEN
arrived empty, so the push to LibreSign/site-preview failed.

Switch to pull_request_target (which runs in the context of the base
repository and has access to secrets regardless of PR origin) and
explicitly check out the PR head SHA so fork PRs build their own code
rather than the base branch.

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Using pull_request_target to access secrets in fork PRs requires an
explicit ref checkout (because pull_request_target checks out the base
branch by default) and introduces unnecessary complexity and security
surface.

The correct approach is to keep pull_request (which always checks out
the right commit by default) and simply skip the job when the PR comes
from a fork. Weblate translation PRs do not need a visual preview.

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://libresign.github.io/site-preview/pr-preview/pr-445/

Built to branch main at 2026-07-10 14:23 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@vitormattos
vitormattos merged commit a3f7fee into main Jul 10, 2026
5 checks passed
@vitormattos
vitormattos deleted the fix/preview-fork-pr-secrets branch July 10, 2026 14:24
@henmohr

henmohr commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

🚀 Starting production deploy of header and footer fragments...

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Starting production deploy of site header and footer fragments...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants