Docs preview create #9706
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 | |
sha: | |
description: 'The commit SHA responsible for triggering 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 | |
continue-on-error: true | |
run: git add -A && git commit -m "sync docs for repo ${{ inputs.repo }}, pr ${{ inputs.pr }}, commit ${{ inputs.sha }}" && git push -u origin ${{ env.BRANCH }} --force | |
- name: Request preview comment | |
if: ${{ steps.push.outcome == 'success' }} | |
uses: peter-evans/repository-dispatch@v3 | |
with: | |
event-type: 'request-preview-comment' | |
client-payload: |- | |
{ | |
"repo": "${{ inputs.repo }}", | |
"pr": "${{ inputs.pr }}" | |
} | |
- name: Dispatch docs-unaffected | |
if: ${{ steps.push.outcome != 'success' }} | |
uses: peter-evans/repository-dispatch@v3 | |
with: | |
event-type: 'docs-unaffected' | |
client-payload: |- | |
{ | |
"repo": "${{ inputs.repo }}", | |
"pr": "${{ inputs.pr }}", | |
"sha": "${{ inputs.sha }}" | |
} |