Skip to content

Commit

Permalink
add details on docs previews (#783)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris authored Nov 3, 2024
1 parent 37fa59a commit 8a57a6c
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .github/workflows/docs-preview-delete.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ on:
repository_dispatch:
types: [docs-preview-delete]

env:
BRANCH: preview-${{ github.event.client_payload.package }}-${{ github.event.client_payload.pr }}

jobs:
Sync:
runs-on: ubuntu-latest
Expand All @@ -13,4 +16,4 @@ jobs:
token: ${{ secrets.GH_TOKEN }}

- name: Delete branch
run: git push origin :sync/${{ github.event.client_payload.package }}/${{ github.event.client_payload.owner }}/${{ github.event.client_payload.branch }}
run: git push origin :${{ env.BRANCH }}
69 changes: 69 additions & 0 deletions apps/svelte.dev/scripts/sync-docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,72 @@ You will need to add a `SYNC_REQUEST_TOKEN` to the repo. First, create a persona
- under 'Repository permissions', change 'Contents' to 'Read and write'

Then, go to `https://github.com/<ORG>/<REPO>/settings/secrets/actions`, click 'New repository secret' and paste in your newly generated personal access token.

## Previews

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...

```yml
# https://github.com/sveltejs/svelte.dev/blob/main/apps/svelte.dev/scripts/sync-docs/README.md
name: Docs preview create request
on:
pull_request:
branches:
- main
jobs:
dispatch:
runs-on: ubuntu-latest
steps:
- name: Repository Dispatch
uses: peter-evans/repository-dispatch@v3
with:
token: ${{ secrets.SYNC_REQUEST_TOKEN }}
repository: sveltejs/svelte.dev
event-type: docs-preview-create
client-payload: |-
{
"package": "<YOUR_PACKAGE_NAME>",
"repo": "${{ github.repository }}",
"owner": "${{ github.event.pull_request.head.repo.owner.login }}",
"branch": "${{ github.event.pull_request.head.ref }}",
"pr": ${{ github.event.pull_request.number }}
}
```

...and a `.github/workflows/docs-preview-delete-request.yml` workflow:

```yml
# https://github.com/sveltejs/svelte.dev/blob/main/apps/svelte.dev/scripts/sync-docs/README.md
name: Docs preview delete request
on:
pull_request:
branches:
- main
types: [closed]
jobs:
dispatch:
runs-on: ubuntu-latest
steps:
- name: Repository Dispatch
uses: peter-evans/repository-dispatch@v3
with:
token: ${{ secrets.SYNC_REQUEST_TOKEN }}
repository: sveltejs/svelte.dev
event-type: docs-preview-delete
client-payload: |-
{
"package": "cli",
"repo": "${{ github.repository }}",
"owner": "${{ github.event.pull_request.head.repo.owner.login }}",
"branch": "${{ github.event.pull_request.head.ref }}",
"pr": ${{ github.event.pull_request.number }}
}
```

These use the same `SYNC_REQUEST_TOKEN` as above.

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 comments on commit 8a57a6c

Please sign in to comment.