Skip to content

Commit 420aadb

Browse files
Setup PR Previews for Storybook Documentation with Environment Protection
1 parent 10e1a55 commit 420aadb

2 files changed

Lines changed: 41 additions & 19 deletions

File tree

.github/workflows/pr-preview.yml

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,6 @@ jobs:
5858
exit 1
5959
fi
6060
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
72-
with:
73-
path: pr-preview
74-
retention-days: 30
75-
7661
# Add a comment to the PR with the preview URL
7762
- name: Comment PR
7863
uses: actions/github-script@v6
@@ -81,7 +66,9 @@ jobs:
8166
const previewUrl = `https://lambda-curry.github.io/forms/pr-preview/pr-${context.issue.number}/`;
8267
const commentBody = `📝 **Storybook Preview**: [View Storybook](${previewUrl})
8368
84-
This preview will be updated automatically when you push new changes to this PR.`;
69+
This preview will be updated automatically when you push new changes to this PR.
70+
71+
> Note: The preview will be available after the workflow completes and the PR is approved for deployment.`;
8572
8673
// Get existing comments
8774
const comments = await github.rest.issues.listComments({
@@ -114,16 +101,35 @@ jobs:
114101
});
115102
}
116103
104+
# Create PR-specific directory structure
105+
- name: Create PR-specific directory
106+
run: |
107+
mkdir -p pr-preview/pr-${{ github.event.pull_request.number }}
108+
cp -r apps/docs/storybook-static/* pr-preview/pr-${{ github.event.pull_request.number }}/
109+
110+
# Upload the artifact for the deployment job
111+
- name: Upload artifact
112+
uses: actions/upload-pages-artifact@v3
113+
with:
114+
path: pr-preview
115+
retention-days: 30
116+
117117
# Deploy job
118118
deploy:
119119
needs: build
120120
runs-on: ubuntu-latest
121121
if: github.event.action != 'closed'
122+
123+
# Use a specific environment with protection rules
124+
# This ensures only approved PRs can deploy
122125
environment:
123-
name: github-pages
126+
name: pr-preview
124127
url: ${{ steps.deployment.outputs.page_url }}
125-
128+
126129
steps:
130+
- name: Setup Pages
131+
uses: actions/configure-pages@v5
132+
127133
- name: Deploy to GitHub Pages
128134
id: deployment
129135
uses: actions/deploy-pages@v4

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Checkout our [Storybook Documentation](https://lambda-curry.github.io/forms/?pat
44

55
A form library for React applications.
66

7+
78
## Getting Started
89

910
Step 1: Install dependencies
@@ -38,14 +39,29 @@ The PR preview system:
3839
4. **Automatically updates the preview when you push new changes to the PR**
3940
5. Cleans up the preview when the PR is closed
4041

42+
#### GitHub Environment Setup
43+
44+
For PR previews to work properly, you need to set up a GitHub environment:
45+
46+
1. Go to your repository settings
47+
2. Navigate to "Environments"
48+
3. Create a new environment named `pr-preview`
49+
4. Configure environment protection rules as needed:
50+
- You can require reviewers to approve deployment
51+
- You can limit deployment to specific branches
52+
- You can add wait timers before deployment
53+
54+
The main branch will continue to deploy to the `github-pages` environment.
55+
4156
#### Troubleshooting PR Previews
4257

4358
If you encounter a 404 error when accessing the PR preview:
4459

4560
1. Make sure the PR build has completed successfully by checking the GitHub Actions tab
4661
2. Verify that the repository has GitHub Pages enabled and configured to deploy from the `gh-pages` branch
4762
3. Check that the PR preview comment contains the correct URL
48-
4. Try clearing your browser cache or using an incognito window
63+
4. Ensure the PR has been approved for deployment if environment protection rules are enabled
64+
5. Try clearing your browser cache or using an incognito window
4965

5066
The PR preview is deployed to the `gh-pages` branch in a directory structure like:
5167
```

0 commit comments

Comments
 (0)