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
29 changes: 26 additions & 3 deletions .github/workflows/preview-fork-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,29 @@ jobs:
if: >
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.pull_requests[0].head.repo.id != github.event.workflow_run.repository.id
github.event.workflow_run.head_repository.id != github.event.repository.id
runs-on: ubuntu-latest

steps:
# workflow_run.pull_requests may be empty for fork PRs. Verify the
# source repository and exact HEAD before publishing untrusted HTML.
- name: Resolve PR number from completed fork build
id: pr
env:
GH_TOKEN: ${{ github.token }}
SOURCE_REPOSITORY: ${{ github.event.workflow_run.head_repository.full_name }}
SOURCE_BRANCH: ${{ github.event.workflow_run.head_branch }}
SOURCE_SHA: ${{ github.event.workflow_run.head_sha }}
run: |
set -euo pipefail
ref="${SOURCE_REPOSITORY%%/*}:$SOURCE_BRANCH"
gh pr view "$ref" -R "$GITHUB_REPOSITORY" \
--json number,state,baseRefName,headRefOid,headRepository |
jq -er --arg sha "$SOURCE_SHA" --arg repo "$SOURCE_REPOSITORY" \
'select(.state == "OPEN" and .baseRefName == "main" and
.headRefOid == $sha and .headRepository.nameWithOwner == $repo) |
"number=\(.number)"' >> "$GITHUB_OUTPUT"

- name: Download preview artifact
uses: actions/download-artifact@v4
with:
Expand All @@ -27,14 +46,18 @@ jobs:
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Check downloaded preview
run: test -s build_production/index.html

- name: Deploy preview
uses: LibreSign/pr-preview-action@2a6da1177b47dc23173ba9a75e01da0a0d800978
with:
action: deploy
source-dir: ./build_production/
pr-number: ${{ github.event.workflow_run.pull_requests[0].number }}
pr-number: ${{ steps.pr.outputs.number }}
pages-base-url: libresign.github.io/site-preview
deploy-repository: LibreSign/site-preview
preview-branch: gh-pages
wait-for-pages-deployment: true
# The shared Pages branch can be published by another PR concurrently.
wait-for-pages-deployment: false
token: ${{ secrets.PREVIEW_TOKEN }}
3 changes: 2 additions & 1 deletion .github/workflows/preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,6 @@ jobs:
pages-base-url: libresign.github.io/site-preview
deploy-repository: LibreSign/site-preview
preview-branch: gh-pages
wait-for-pages-deployment: true
# Another PR can supersede this Pages build on the shared repository.
wait-for-pages-deployment: false
token: ${{ secrets.PREVIEW_TOKEN }}
Loading