Docs preview create (kit #17022) #30713
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 | |
| run-name: 'Docs preview create (${{ inputs.upstream }} #${{ inputs.pr }})' | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| upstream: | |
| description: 'Upstream repository (eg. `svelte` or `kit`)' | |
| required: true | |
| type: choice | |
| options: | |
| - svelte | |
| - kit | |
| - cli | |
| - ai-tools | |
| downstream: | |
| description: 'Downstream repository (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.upstream }}-${{ inputs.pr }} | |
| jobs: | |
| Sync: | |
| name: Sync | |
| runs-on: ubuntu-latest | |
| concurrency: | |
| group: preview-${{ inputs.upstream }}-${{ inputs.pr }} # can't reference env here | |
| cancel-in-progress: true | |
| steps: | |
| - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| # TODO: revert this to 'main' when we merge kit next docs | |
| ref: ${{ inputs.upstream == 'kit' && 'next' || 'main' }} # Explicitly checkout main branch first | |
| - uses: pnpm/action-setup@b906affcce14559ad1aafd4ab0e942779e9f58b1 # v4 | |
| - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4 | |
| with: | |
| node-version: 24 | |
| 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: Resolve commit SHA | |
| id: resolve | |
| run: | | |
| sha="${{ inputs.sha }}" | |
| if [ -z "$sha" ]; then | |
| sha=$(git ls-remote "https://github.com/${{ inputs.owner }}/${{ inputs.downstream }}.git" "refs/heads/${{ inputs.branch }}" | cut -f1) | |
| fi | |
| if [ -z "$sha" ]; then | |
| echo "Could not resolve commit SHA for ${{ inputs.owner }}/${{ inputs.downstream }}@${{ inputs.branch }}" >&2 | |
| exit 1 | |
| fi | |
| echo "ref=c/$sha" >> "$GITHUB_OUTPUT" | |
| - name: Install Svelte upstream | |
| if: ${{ inputs.upstream == 'svelte' }} | |
| run: pnpm add https://pkg.svelte.dev/svelte/${{ steps.resolve.outputs.ref }} --filter "docs-types" | |
| - name: Install SvelteKit upstream | |
| if: ${{ inputs.upstream == 'kit' }} | |
| run: pnpm add https://pkg.svelte.dev/@sveltejs/kit/${{ steps.resolve.outputs.ref }} https://pkg.svelte.dev/@sveltejs/adapter-vercel/${{ steps.resolve.outputs.ref }} https://pkg.svelte.dev/@sveltejs/enhanced-img/${{ steps.resolve.outputs.ref }} --filter "docs-types" | |
| - name: Install Svelte CLI upstream | |
| if: ${{ inputs.upstream == 'cli' }} | |
| run: pnpm add https://pkg.svelte.dev/sv/${{ steps.resolve.outputs.ref }} https://pkg.svelte.dev/@sveltejs/sv-utils/${{ steps.resolve.outputs.ref }} --filter "docs-types" | |
| - name: Sync | |
| run: cd apps/svelte.dev && pnpm sync-docs --owner="${{ inputs.owner }}" -p "${{ format('{0}#{1}#{2}', inputs.upstream, inputs.downstream, 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.upstream }}, 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@ff45666b9427631e3450c54a1bcbee4d9ff4d7c0 # v3 | |
| with: | |
| event-type: 'request-preview-comment' | |
| client-payload: |- | |
| { | |
| "repo": "${{ inputs.upstream }}", | |
| "pr": "${{ inputs.pr }}" | |
| } | |
| - name: Dispatch docs-unaffected | |
| if: ${{ steps.push.outcome != 'success' }} | |
| uses: peter-evans/repository-dispatch@ff45666b9427631e3450c54a1bcbee4d9ff4d7c0 # v3 | |
| with: | |
| event-type: 'docs-unaffected' | |
| client-payload: |- | |
| { | |
| "repo": "${{ inputs.upstream }}", | |
| "pr": "${{ inputs.pr }}", | |
| "sha": "${{ inputs.sha }}" | |
| } |