Skip to content

Commit 5697ab6

Browse files
committed
try existing template
1 parent 8f5f3c7 commit 5697ab6

File tree

1 file changed

+21
-97
lines changed

1 file changed

+21
-97
lines changed
Lines changed: 21 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,124 +1,48 @@
1-
name: Deploy Preview
1+
name: Deploy PR Preview
22

33
on:
4-
workflow_call:
5-
inputs:
6-
pr_number:
7-
required: true
8-
type: string
9-
commit_sha:
10-
required: true
11-
type: string
12-
action:
13-
required: true
14-
type: string
15-
description: "create or delete preview"
16-
secrets:
17-
TOKEN:
18-
required: true
4+
pull_request:
5+
types:
6+
- opened
7+
- reopened
8+
- synchronize
9+
- closed
10+
11+
concurrency: preview-${{ github.ref }}
1912

2013
permissions:
2114
contents: write
2215
pull-requests: write
2316

2417
jobs:
2518
deploy-preview:
26-
name: Deploy Preview
19+
name: Deploy PR Preview
2720
runs-on: ubuntu-latest
2821
steps:
29-
- name: Checkout PR branch for cache restore
30-
if: inputs.action == 'create'
22+
- name: Checkout repository
23+
if: github.event.action != 'closed'
3124
uses: actions/checkout@v4
32-
with:
33-
token: ${{ secrets.TOKEN }}
34-
ref: ${{ inputs.commit_sha }}
3525

3626
- name: Setup Node.js
27+
if: github.event.action != 'closed'
3728
uses: actions/setup-node@v4
3829
with:
3930
node-version: 20
4031

4132
- name: Restore docs build output
42-
if: inputs.action == 'create'
33+
if: github.event.action != 'closed'
4334
uses: actions/cache@v4
4435
with:
4536
path: |
4637
build/docs/gatsby/public-preview
47-
key: docs-build-${{ inputs.commit_sha }}
38+
key: docs-build-${{ github.sha }}
4839
restore-keys: |
4940
docs-build-
5041
51-
- name: Checkout gh-pages branch
52-
uses: actions/checkout@v4
53-
with:
54-
token: ${{ secrets.TOKEN }}
55-
ref: gh-pages
56-
path: gh-pages
57-
58-
- name: Create preview directory and copy files
59-
if: inputs.action == 'create'
60-
run: |
61-
mkdir -p gh-pages/preview/PR${{ inputs.pr_number }}
62-
cp -r build/docs/gatsby/public-preview/* gh-pages/preview/PR${{ inputs.pr_number }}/
63-
64-
- name: Remove preview directory
65-
if: inputs.action == 'delete'
66-
run: |
67-
rm -rf gh-pages/preview/PR${{ inputs.pr_number }}
68-
69-
- name: Commit and push changes
70-
run: |
71-
cd gh-pages
72-
git config user.name "github-actions[bot]"
73-
git config user.email "github-actions[bot]@users.noreply.github.com"
74-
75-
if [ "${{ inputs.action }}" = "create" ]; then
76-
git add preview/PR${{ inputs.pr_number }}
77-
git commit -m "Add preview for PR #${{ inputs.pr_number }}"
78-
else
79-
git add -A
80-
git commit -m "Remove preview for PR #${{ inputs.pr_number }}"
81-
fi
82-
83-
git push origin gh-pages
84-
85-
- name: Comment on PR
86-
if: inputs.action == 'create'
87-
uses: actions/github-script@v7
88-
with:
89-
script: |
90-
const previewUrl = `https://${{ github.repository_owner }}.github.io/execution-apis/preview/PR${{ inputs.pr_number }}/`;
91-
github.rest.issues.createComment({
92-
issue_number: ${{ inputs.pr_number }},
93-
owner: '${{ github.repository_owner }}',
94-
repo: '${{ github.event.repository.name }}',
95-
body: `🚀 **Deploy Preview Available!**
96-
97-
Your changes are now available for preview at: **${previewUrl}**
98-
99-
This preview will be automatically removed when the PR is merged.`
100-
});
101-
102-
- name: Remove preview comment
103-
if: inputs.action == 'delete'
104-
uses: actions/github-script@v7
42+
- name: Deploy PR Preview
43+
uses: rossjrw/pr-preview-action@v1
10544
with:
106-
script: |
107-
const { data: comments } = await github.rest.issues.listComments({
108-
issue_number: ${{ inputs.pr_number }},
109-
owner: '${{ github.repository_owner }}',
110-
repo: '${{ github.event.repository.name }}'
111-
});
112-
113-
const previewComment = comments.find(comment =>
114-
comment.body.includes('Deploy Preview Available!') &&
115-
comment.user.login === 'github-actions[bot]'
116-
);
117-
118-
if (previewComment) {
119-
await github.rest.issues.deleteComment({
120-
comment_id: previewComment.id,
121-
owner: '${{ github.repository_owner }}',
122-
repo: '${{ github.event.repository.name }}'
123-
});
124-
}
45+
source-dir: build/docs/gatsby/public-preview
46+
preview-branch: gh-pages
47+
umbrella-dir: preview
48+
action: auto

0 commit comments

Comments
 (0)