Skip to content

Commit f5f7b5b

Browse files
Add optional cleanup-preview workflow to preview changes page
(#5117) Co-authored-by: fern-api[bot] <115122769+fern-api[bot]@users.noreply.github.com> Co-authored-by: Devin Logan <devinannlogan@gmail.com>
1 parent 6916c81 commit f5f7b5b

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
tags: ["developer-tools"]
3+
---
4+
5+
## Clean up GitHub Actions preview deployments on merge
6+
7+
The [GitHub Actions preview workflow](/learn/docs/preview-publish/preview-changes#automate-with-github-actions) now has an optional companion `cleanup-preview.yml` workflow that deletes a pull request's preview deployment once the PR merges, so stale previews don't linger.
8+
9+
To adopt this workflow, add `.github/workflows/cleanup-preview.yml` alongside your existing preview workflow.
10+
11+
<Button intent="none" outlined rightIcon="arrow-right" href="/learn/docs/preview-publish/preview-changes#clean-up-preview-links-when-prs-merge">Read the docs</Button>

fern/products/docs/pages/preview-publish/preview-changes-locally.mdx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,3 +305,35 @@ jobs:
305305
</CodeBlock>
306306

307307
</Accordion>
308+
309+
#### Clean up preview links when PRs merge
310+
311+
To clean up preview links automatically after a PR is merged, add this workflow alongside the one above. It calls [`fern docs preview delete`](/learn/cli-api-reference/cli-reference/commands#fern-docs-preview-delete) with the PR's branch name as the `--id`, matching the identifier used when the preview was generated.
312+
313+
<CodeBlock title = ".github/workflows/cleanup-preview.yml">
314+
```yaml
315+
name: Clean up preview links
316+
317+
on:
318+
pull_request:
319+
types: [closed]
320+
321+
jobs:
322+
cleanup:
323+
if: github.event.pull_request.merged == true
324+
runs-on: ubuntu-latest
325+
steps:
326+
- name: Checkout repository
327+
uses: actions/checkout@v4
328+
329+
- name: Setup Fern CLI
330+
uses: fern-api/setup-fern-cli@v1
331+
332+
- name: Delete preview deployment
333+
env:
334+
FERN_TOKEN: ${{ secrets.FERN_TOKEN }}
335+
run: |
336+
echo "Deleting preview for branch: ${{ github.head_ref }}"
337+
fern docs preview delete --id "${{ github.head_ref }}" || echo "Preview deletion returned non-zero — it may already be gone"
338+
```
339+
</CodeBlock>

0 commit comments

Comments
 (0)