|
| 1 | +name: 'Generate Fern Docs Preview' |
| 2 | +description: 'Generates a Fern documentation preview and comments the URL in a PR' |
| 3 | + |
| 4 | +inputs: |
| 5 | + github-token: |
| 6 | + description: 'GitHub token for creating deployments and comments' |
| 7 | + required: true |
| 8 | + fern-token: |
| 9 | + description: 'Fern API token for publishing docs' |
| 10 | + required: true |
| 11 | + ref: |
| 12 | + description: 'Git ref to create deployment for (usually github.head_ref for PRs)' |
| 13 | + required: true |
| 14 | + environment: |
| 15 | + description: 'Deployment environment name' |
| 16 | + required: false |
| 17 | + default: 'docs-preview' |
| 18 | + |
| 19 | +outputs: |
| 20 | + preview-url: |
| 21 | + description: 'The URL where the preview documentation was published' |
| 22 | + value: ${{ steps.generate-preview.outputs.url }} |
| 23 | + status: |
| 24 | + description: 'The outcome of the preview generation (success, failure, etc.)' |
| 25 | + value: ${{ steps.generate-preview.outcome }} |
| 26 | + |
| 27 | +runs: |
| 28 | + using: "composite" |
| 29 | + steps: |
| 30 | + - name: Setup Docs |
| 31 | + uses: ./.github/actions/setup-docs |
| 32 | + with: |
| 33 | + docs-github-token: ${{ inputs.github-token }} |
| 34 | + |
| 35 | + - name: Set Build Comment to In Progress |
| 36 | + uses: actions/github-script@v7 |
| 37 | + with: |
| 38 | + github-token: ${{ inputs.github-token }} |
| 39 | + script: | |
| 40 | + const workspace = process.env.GITHUB_WORKSPACE; |
| 41 | + const { updatePreviewComment } = await import(`${workspace}/docs-site/scripts/preview-comment.js`); |
| 42 | +
|
| 43 | + await updatePreviewComment({ |
| 44 | + github, |
| 45 | + context, |
| 46 | + status: 'building', |
| 47 | + }); |
| 48 | +
|
| 49 | + - name: Generate Fern Docs Preview |
| 50 | + id: generate-preview |
| 51 | + uses: ./.github/actions/publish-fern |
| 52 | + with: |
| 53 | + github-token: ${{ inputs.github-token }} |
| 54 | + fern-token: ${{ inputs.fern-token }} |
| 55 | + environment: ${{ inputs.environment }} |
| 56 | + ref: ${{ inputs.ref }} |
| 57 | + preview: "true" |
| 58 | + |
| 59 | + - name: Comment Preview URL in PR |
| 60 | + uses: actions/github-script@v7 |
| 61 | + if: always() |
| 62 | + with: |
| 63 | + github-token: ${{ inputs.github-token }} |
| 64 | + script: | |
| 65 | + const workspace = process.env.GITHUB_WORKSPACE; |
| 66 | + const { updatePreviewComment } = await import(`${workspace}/docs-site/scripts/preview-comment.js`); |
| 67 | +
|
| 68 | + await updatePreviewComment({ |
| 69 | + github, |
| 70 | + context, |
| 71 | + previewUrl: '${{ steps.generate-preview.outputs.url }}', |
| 72 | + status: '${{ steps.generate-preview.outcome }}', |
| 73 | + }); |
0 commit comments