Docs preview create #9607
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Docs preview create | |
on: | |
workflow_dispatch: | |
inputs: | |
repo: | |
description: 'Repository name (not fully-qualified, eg. `svelte` or `kit`)' | |
required: true | |
type: string | |
pr: | |
description: 'PR number' | |
required: true | |
type: string | |
owner: | |
description: 'Owner (eg. sveltejs)' | |
required: true | |
type: string | |
branch: | |
description: 'Branch (eg. my-feature-branch)' | |
required: true | |
type: string | |
check_id: | |
description: 'The ID of the check that triggered this workflow' | |
required: false | |
type: string | |
permissions: | |
contents: write | |
env: | |
BRANCH: preview-${{ inputs.repo }}-${{ inputs.pr }} | |
jobs: | |
Sync: | |
name: Sync | |
runs-on: ubuntu-latest | |
concurrency: | |
group: preview-${{ inputs.repo }}-${{ inputs.pr }} # can't reference env here | |
cancel-in-progress: true | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.GH_TOKEN }} | |
ref: main # Explicitly checkout main branch first | |
- uses: pnpm/action-setup@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: 22 | |
cache: pnpm | |
- run: pnpm install --frozen-lockfile | |
- name: Create or reset branch from main | |
run: | | |
git fetch origin | |
git checkout -B ${{ env.BRANCH }} # Force create/reset branch based on current main | |
- name: Sync | |
run: cd apps/svelte.dev && pnpm sync-docs --owner="${{ inputs.owner }}" -p "${{ inputs.repo }}#${{ inputs.branch }}" | |
- name: Configure Git | |
run: | | |
git config --global user.name "GitHub Actions Bot" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
- name: Push | |
id: push | |
run: git add -A && git commit -m "sync docs for check run ${{ inputs.check_id }}" && git push -u origin ${{ env.BRANCH }} --force | |
- name: Request preview comment | |
uses: peter-evans/repository-dispatch@v3 | |
with: | |
event-type: 'request-preview-comment' | |
client-payload: |- | |
{ | |
"repo": "${{ inputs.repo }}", | |
"pr": "${{ inputs.pr }}" | |
} |