Skip to content

Commit 8a57a6c

Browse files
authored
add details on docs previews (#783)
1 parent 37fa59a commit 8a57a6c

File tree

2 files changed

+73
-1
lines changed

2 files changed

+73
-1
lines changed

.github/workflows/docs-preview-delete.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ on:
44
repository_dispatch:
55
types: [docs-preview-delete]
66

7+
env:
8+
BRANCH: preview-${{ github.event.client_payload.package }}-${{ github.event.client_payload.pr }}
9+
710
jobs:
811
Sync:
912
runs-on: ubuntu-latest
@@ -13,4 +16,4 @@ jobs:
1316
token: ${{ secrets.GH_TOKEN }}
1417

1518
- name: Delete branch
16-
run: git push origin :sync/${{ github.event.client_payload.package }}/${{ github.event.client_payload.owner }}/${{ github.event.client_payload.branch }}
19+
run: git push origin :${{ env.BRANCH }}

apps/svelte.dev/scripts/sync-docs/README.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,72 @@ You will need to add a `SYNC_REQUEST_TOKEN` to the repo. First, create a persona
8383
- under 'Repository permissions', change 'Contents' to 'Read and write'
8484

8585
Then, go to `https://github.com/<ORG>/<REPO>/settings/secrets/actions`, click 'New repository secret' and paste in your newly generated personal access token.
86+
87+
## Previews
88+
89+
Preview deployments will be created for pull requests to external repos that result in documentation changes. In the external repo, add a `.github/workflows/docs-preview-create-request.yml` workflow...
90+
91+
```yml
92+
# https://github.com/sveltejs/svelte.dev/blob/main/apps/svelte.dev/scripts/sync-docs/README.md
93+
name: Docs preview create request
94+
95+
on:
96+
pull_request:
97+
branches:
98+
- main
99+
100+
jobs:
101+
dispatch:
102+
runs-on: ubuntu-latest
103+
steps:
104+
- name: Repository Dispatch
105+
uses: peter-evans/repository-dispatch@v3
106+
with:
107+
token: ${{ secrets.SYNC_REQUEST_TOKEN }}
108+
repository: sveltejs/svelte.dev
109+
event-type: docs-preview-create
110+
client-payload: |-
111+
{
112+
"package": "<YOUR_PACKAGE_NAME>",
113+
"repo": "${{ github.repository }}",
114+
"owner": "${{ github.event.pull_request.head.repo.owner.login }}",
115+
"branch": "${{ github.event.pull_request.head.ref }}",
116+
"pr": ${{ github.event.pull_request.number }}
117+
}
118+
```
119+
120+
...and a `.github/workflows/docs-preview-delete-request.yml` workflow:
121+
122+
```yml
123+
# https://github.com/sveltejs/svelte.dev/blob/main/apps/svelte.dev/scripts/sync-docs/README.md
124+
name: Docs preview delete request
125+
126+
on:
127+
pull_request:
128+
branches:
129+
- main
130+
types: [closed]
131+
132+
jobs:
133+
dispatch:
134+
runs-on: ubuntu-latest
135+
steps:
136+
- name: Repository Dispatch
137+
uses: peter-evans/repository-dispatch@v3
138+
with:
139+
token: ${{ secrets.SYNC_REQUEST_TOKEN }}
140+
repository: sveltejs/svelte.dev
141+
event-type: docs-preview-delete
142+
client-payload: |-
143+
{
144+
"package": "cli",
145+
"repo": "${{ github.repository }}",
146+
"owner": "${{ github.event.pull_request.head.repo.owner.login }}",
147+
"branch": "${{ github.event.pull_request.head.ref }}",
148+
"pr": ${{ github.event.pull_request.number }}
149+
}
150+
```
151+
152+
These use the same `SYNC_REQUEST_TOKEN` as above.
153+
154+
Inside _this_ repo, the [`docs-preview-create.yml`](../../../../.github/workflows/docs-preview-create.yml) workflow creates a comment on the PR once the branch has been created, inferring the eventual Vercel preview deployment URL. It uses this repo's `COMMENTER_TOKEN` secret, which is a [personal access token](https://github.com/settings/personal-access-tokens/new) with write permissions on issues and pull requests.

0 commit comments

Comments
 (0)