This workflow automates the deployment of preview environments for pull requests using Vercel. It supports multiple projects and dynamically updates deployment URLs in a pull request comment.
To use this workflow in your repository:
- Copy this file into
.github/workflows/vercel-preview.ymlin your repository. - Ensure you have the necessary secrets and permissions configured.
Set the following secrets in your repository:
VERCEL_TOKEN: Your Vercel API token.VERCEL_ORG_ID: Your Vercel organization ID.VERCEL_[PROJECT_NAME]_PROJECT_ID: Project ID for your Vercel project(s).
Replace [PROJECT_NAME] and [PROJECT_NAME_2] with the actual names of your projects.
-
Organization and Project Details
Update the following placeholders:[PROJECT_NAME]and[PROJECT_NAME_2]with your project names.[path_to_project]and[path_to_project_2]with the relative paths to your projects.[org_name]with your Vercel organization name.
-
Matrix Configuration
Add or remove projects in thestrategy.matrix.includesection to deploy additional projects. -
Environment Variables
Ensure each project-specific variable, likeVERCEL_[PROJECT_NAME]_PROJECT_ID, matches your configuration.
- Deployment Artifacts: Each project is built and deployed separately.
- PR Comment Updates: The workflow comments on the pull request with deployment URLs, updating them as deployments complete.
- Concurrent Deployment Handling: Uses
concurrencyto manage simultaneous runs and prevent overlapping deployments.
- The workflow uses
actions/cachefor faster builds by caching thepnpmstore. - Deployment data is managed using artifacts to track existing deployments.
jqis used for JSON manipulation. Ensure your environment supports it.
After running the workflow, the pull request will include a comment like this: