This document describes how preview deployments work for pull requests and how to configure them.
Preview deployments automatically create a live, temporary deployment of the web application for each pull request. This allows reviewers to:
- Test UI changes in a real environment
- Verify functionality without running the app locally
- Share a live link with stakeholders for feedback
- Catch integration issues before merging
- Trigger: When a PR is opened or updated with changes to the
web/directory - Build: The workflow builds the Next.js application
- Deploy: Deploys to Vercel as a preview environment
- Comment: Posts the preview URL as a comment on the PR
- Update: Subsequent pushes update the same preview deployment
- A Vercel account (free tier works)
- Admin access to the GitHub repository
- Go to Vercel and sign in
- Click "Add New..." → "Project"
- Import your GitHub repository
- Configure the project:
- Framework Preset: Next.js
- Root Directory:
web - Build Command:
npm run build - Output Directory:
.next
- Important: Do NOT enable automatic deployments (we'll use GitHub Actions instead)
- Go to your Vercel project settings
- Navigate to "Settings" → "General"
- Copy the following values:
- Project ID: Found in project settings
- Org ID: Found in team/account settings
- Create a Vercel token:
- Go to Account Settings → Tokens
- Click "Create Token"
- Name it "GitHub Actions Preview Deployments"
- Copy the token (you won't see it again)
Add the following secrets to your GitHub repository:
- Go to your repository → Settings → Secrets and variables → Actions
- Click "New repository secret" and add:
| Secret Name | Description | Where to Find |
|---|---|---|
VERCEL_TOKEN |
Vercel authentication token | Created in Step 2 |
VERCEL_ORG_ID |
Your Vercel organization ID | Vercel project settings |
VERCEL_PROJECT_ID |
Your Vercel project ID | Vercel project settings |
Set up environment variables for preview deployments:
- Go to your Vercel project → Settings → Environment Variables
- Add the following variables for Preview environment:
| Variable | Value | Notes |
|---|---|---|
NEXT_PUBLIC_NETWORK |
testnet |
Use testnet for previews |
NEXT_PUBLIC_APP_URL |
(auto-set by Vercel) | Preview URL |
NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID |
Your WalletConnect ID | Optional but recommended |
NEXT_PUBLIC_STACKS_API_URL |
https://api.testnet.hiro.so |
Testnet API |
NEXT_PUBLIC_SOROBAN_CONTRACT_ID |
Your testnet contract ID | If using Stellar |
Security Note: Never add production secrets or mainnet configurations to preview environments.
- Create a pull request with your changes
- Wait for the preview deployment workflow to complete (~2-3 minutes)
- Find the preview URL in the PR comment
- Share the URL with reviewers
- Open the pull request
- Look for the "🚀 Preview Deployment" comment
- Click the preview URL to test the changes
- Provide feedback on the PR
The preview deployment workflow runs when:
- A PR is opened targeting the
mainbranch - New commits are pushed to an open PR
- Changes affect files in the
web/directory
- Only one preview deployment runs per PR at a time
- New commits cancel in-progress deployments
- Each PR gets its own isolated preview environment
Preview deployments are automatically deleted when:
- The PR is merged
- The PR is closed
- After 30 days of inactivity (Vercel default)
Solution: Regenerate your Vercel token and update the VERCEL_TOKEN secret in GitHub.
Solution: Check environment variables in Vercel project settings. Ensure NEXT_PUBLIC_NETWORK=testnet is set for preview environment.
Solution:
- Ensure
package-lock.jsonis committed - Check that all dependencies are in
package.json - Review build logs in the GitHub Actions tab
Solution:
- Verify the GitHub Actions bot has write permissions
- Check workflow permissions in repository settings
- Review the workflow run logs for errors
Solution:
- Verify variables are set in Vercel for the "Preview" environment
- Ensure variable names start with
NEXT_PUBLIC_for client-side access - Redeploy the preview after updating variables
While this setup uses Vercel, you can adapt the workflow for other platforms:
Replace the Vercel steps with:
- name: Deploy to Netlify
uses: nwtgck/actions-netlify@v2.0
with:
publish-dir: './web/.next'
production-deploy: falseUse the Cloudflare Pages GitHub Action:
- name: Deploy to Cloudflare Pages
uses: cloudflare/pages-action@v1
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
projectName: predinex
directory: ./web/.nextFor self-hosted previews:
- Set up a preview server with Docker
- Use GitHub Actions to build and deploy containers
- Use a reverse proxy (nginx/Traefik) for PR-specific subdomains
- Preview deployments use testnet configuration only
- Never expose production secrets or API keys
- Use separate contract addresses for preview environments
- Preview URLs are public but unguessable (long random strings)
- Consider adding basic auth for sensitive projects
- Review Vercel's security settings for additional protection
- Store all secrets in GitHub Secrets (encrypted at rest)
- Rotate tokens periodically
- Use least-privilege access for service accounts
- Never commit secrets to the repository
- Preview deployments may contain unreleased features
- Avoid sharing preview URLs publicly before release
- Consider adding a banner indicating "Preview Environment"
- 100 GB bandwidth per month
- 100 hours of build time per month
- Unlimited preview deployments
- 6,000 minutes of serverless function execution
For most projects, the free tier is sufficient for preview deployments.
- Limit workflow triggers: Only run on
web/changes - Cancel in-progress builds: Use concurrency groups
- Cache dependencies: Use npm cache in workflow
- Optimize build: Use Next.js build cache
Check deployment status in:
- GitHub Actions tab (workflow runs)
- PR checks (status badges)
- Vercel dashboard (deployment history)
- Average deployment time
- Success/failure rate
- Build duration trends
- Preview environment usage
For issues or questions:
- Check the GitHub Actions logs
- Review Vercel documentation
- Open an issue in the repository
- Contact the maintainers