Skip to content

Commit c216304

Browse files
committed
fix: pr from forks deployment issue
Signed-off-by: Aritra Dey <[email protected]>
1 parent 332e137 commit c216304

File tree

1 file changed

+53
-6
lines changed

1 file changed

+53
-6
lines changed

.github/workflows/publish-docs.yml

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ on:
66
pull_request:
77
branches: [master]
88
types: [opened, synchronize, reopened, closed]
9+
workflow_dispatch:
10+
inputs:
11+
pr_number:
12+
description: 'PR number to deploy preview for'
13+
required: true
14+
type: number
15+
run_id:
16+
description: 'Run ID of the build workflow (from the PR checks)'
17+
required: true
18+
type: string
919

1020
permissions:
1121
contents: write
@@ -19,6 +29,7 @@ concurrency:
1929

2030
jobs:
2131
build-and-deploy:
32+
if: github.event_name != 'workflow_dispatch'
2233
runs-on: ubuntu-latest
2334
steps:
2435
- name: Checkout 🛎️
@@ -34,18 +45,54 @@ jobs:
3445
npm ci
3546
npm run build
3647
37-
- name: Deploy Preview deploy-preview 🚀
48+
- name: Upload PR Preview Artifact 📦
3849
if: github.event_name == 'pull_request'
39-
uses: rossjrw/pr-preview-action@v1
50+
uses: actions/upload-artifact@v4
4051
with:
41-
source-dir: ./build/
42-
preview-branch: gh-pages-pr-previews
43-
umbrella-dir: pr-preview
44-
action: auto
52+
name: pr-preview-${{ github.event.pull_request.number }}
53+
path: build/
54+
retention-days: 7
4555

4656
- name: Deploy to GitHub Pages 🚀
4757
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
4858
uses: JamesIves/github-pages-deploy-action@v4
4959
with:
5060
branch: gh-pages
5161
folder: build
62+
63+
deploy-preview:
64+
if: github.event_name == 'workflow_dispatch'
65+
runs-on: ubuntu-latest
66+
steps:
67+
- name: Checkout 🛎️
68+
uses: actions/checkout@v4
69+
70+
- name: Download PR Preview Artifact 📥
71+
uses: actions/download-artifact@v4
72+
with:
73+
name: pr-preview-${{ inputs.pr_number }}
74+
path: preview-build/
75+
run-id: ${{ inputs.run_id }}
76+
github-token: ${{ secrets.GITHUB_TOKEN }}
77+
78+
- name: Deploy Preview 🚀
79+
uses: rossjrw/pr-preview-action@v1
80+
with:
81+
source-dir: ./preview-build/
82+
preview-branch: gh-pages-pr-previews
83+
umbrella-dir: pr-preview
84+
action: deploy
85+
86+
- name: Comment PR with Preview URL 💬
87+
uses: actions/github-script@v7
88+
with:
89+
script: |
90+
const prNumber = ${{ inputs.pr_number }};
91+
const previewUrl = `https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/pr-preview/pr-${prNumber}/`;
92+
93+
await github.rest.issues.createComment({
94+
owner: context.repo.owner,
95+
repo: context.repo.repo,
96+
issue_number: prNumber,
97+
body: `🚀 Preview deployed! View it at: ${previewUrl}`
98+
});

0 commit comments

Comments
 (0)