Skip to content

Commit 10e1a55

Browse files
Update PR Preview Workflow to Redeploy on Changes
1 parent 741bfc0 commit 10e1a55

2 files changed

Lines changed: 31 additions & 11 deletions

File tree

.github/workflows/pr-preview.yml

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010

1111
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
1212
permissions:
13-
contents: write
13+
contents: read
1414
pages: write
1515
id-token: write
1616
pull-requests: write
@@ -21,7 +21,8 @@ concurrency:
2121
cancel-in-progress: true
2222

2323
jobs:
24-
deploy-preview:
24+
# Build job
25+
build:
2526
runs-on: ubuntu-latest
2627
# Don't run on closed PRs
2728
if: github.event.action != 'closed'
@@ -57,15 +58,20 @@ jobs:
5758
exit 1
5859
fi
5960
60-
# Deploy to GitHub Pages in a PR-specific directory
61-
- name: Deploy PR Preview
62-
uses: JamesIves/github-pages-deploy-action@v4
61+
# Create PR-specific directory structure
62+
- name: Create PR-specific directory
63+
run: |
64+
mkdir -p pr-preview
65+
cp -r apps/docs/storybook-static pr-preview/pr-${{ github.event.pull_request.number }}
66+
67+
- name: Setup Pages
68+
uses: actions/configure-pages@v5
69+
70+
- name: Upload artifact
71+
uses: actions/upload-pages-artifact@v3
6372
with:
64-
folder: apps/docs/storybook-static
65-
target-folder: pr-preview/pr-${{ github.event.pull_request.number }}
66-
clean: true
67-
clean-exclude: |
68-
pr-preview/pr-*
73+
path: pr-preview
74+
retention-days: 30
6975

7076
# Add a comment to the PR with the preview URL
7177
- name: Comment PR
@@ -108,6 +114,20 @@ jobs:
108114
});
109115
}
110116
117+
# Deploy job
118+
deploy:
119+
needs: build
120+
runs-on: ubuntu-latest
121+
if: github.event.action != 'closed'
122+
environment:
123+
name: github-pages
124+
url: ${{ steps.deployment.outputs.page_url }}
125+
126+
steps:
127+
- name: Deploy to GitHub Pages
128+
id: deployment
129+
uses: actions/deploy-pages@v4
130+
111131
# Clean up when PR is closed
112132
cleanup:
113133
runs-on: ubuntu-latest

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ The PR preview system:
3535
1. Builds the Storybook documentation for each PR
3636
2. Deploys it to a PR-specific directory on the `gh-pages` branch
3737
3. Adds a comment to the PR with a link to the preview
38-
4. Automatically updates the preview when you push new changes to the PR
38+
4. **Automatically updates the preview when you push new changes to the PR**
3939
5. Cleans up the preview when the PR is closed
4040

4141
#### Troubleshooting PR Previews

0 commit comments

Comments
 (0)