GitHub Action
Await for Vercel deployment
jobs:
wait-for-vercel-deployment:
runs-on: ubuntu-latest
steps:
- uses: UnlyEd/github-action-await-vercel@v1.1.0
id: await-vercel
env:
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
with:
deployment-url: nrn-v2-mst-aptd-gcms-lcz-sty-c1-hfq88g3jt.vercel.app
timeout: 10 # Wait for 10 seconds before failing
- name: Display deployment status
run: "echo My deployment is ${{ fromJson(steps.await-vercel.outputs.deploymentDetails).readyState }}"
See the Examples section for more advanced examples.
It waits until a Vercel deployment is marked as "ready". (See readyState === 'READY'
)
If you're using Vercel to deploy your apps and you use some custom deployment pipeline using GitHub Actions, you might need to wait for a deployment to be ready before running other processes (e.g: Your end-to-end tests using Cypress).
For instance, if you don't wait for the deployment to be ready, then you might sometimes run your E2E tests suite against the Vercel's login page, instead of your actual deployment.
If your GitHub Actions sometimes succeeds but sometimes fails, then you probably need to use this action, which will wait until the Vercel deployment is really ready, before starting your next GitHub Action step.
This action automatically forwards the Vercel API response, which contains additional information about the deployment. This can be quite helpful if you need them, and will avoid for you to have yet to make another call to the Vercel API. It's done for you! 🎉
Before building our own GitHub Action, we tried using
wait-for-vercel
, but it didn't work correctly.Part of the issue is that it fetches all deployments for a team/project, which leads to extra issues when you have multiple deployments running in parallel.
To get started with this GitHub Action, you'll need:
- To configure a Vercel secret, for the GitHub Action to be authorized to fetch your deployments
- To provide a few required options (like, the domain)
You should declare those variables as GitHub Secrets.
Name | Description |
---|---|
VERCEL_TOKEN |
Your vercel token is required to fetch the Vercel API on your behalf and get the status of your deployment. See usage in code |
N.B: You don't have to use a GitHub Secret to provide the
VERCEL_TOKEN
. But you should do so, as it's a good security practice, because this way the token will be hidden in the logs (encrypted).
Name | Required | Default | Description |
---|---|---|---|
deployment-url |
✅ | Deployment domain (e.g: my-app-hfq88g3jt.vercel.app ). |
|
timeout |
✖️ | 10 |
How long (in seconds) the action waits for the deployment status to reach either READY or ERROR state. |
Tip: You might want to adapt the
timeout
to your use case.
- For instance, if you're calling this action right after having triggered the Vercel deployment, then it'll go through
INITIALIZING > ANALYZING > BUILDING > DEPLOYING
phases before reachingREADY
orERROR
state. This might take quite some time (depending on your project), and increasing the timeout to600
(10mn) (or similar) is probably what you'll want to do in such case, because you need to take into account the time it'll take for Vercel to deploy.- The default of
10
seconds is because we assume you'll call this action after the deployment has reachedBUILDING
state, and the time it takes for Vercel to reachREADY
orERROR
fromBUILDING
is rather short.
This action forwards the Vercel API response as return value.
Name | Description |
---|---|
deploymentDetails |
JSON object. You can also use our TS type. |
In the below example, we show you how to:
- Step 1: Forward
VERCEL_DEPLOYMENT_URL
as an ENV variable, using>> $GITHUB_ENV"
which stores the value into the GitHub Actions env vars. Of course, you might do it differently. It doesn't really matter as long asVERCEL_DEPLOYMENT_URL
is set. - Step 2: Then, we use the
UnlyEd/github-action-await-vercel@v1.1.0
GitHub Action, which waits for the deployment url to be ready. - Step 3: Finally, we show an example on how to read the deployment's information returned by the Vercel API (which have been forwarded).
on:
pull_request:
push:
branches:
- main
jobs:
wait-for-vercel-deployment:
runs-on: ubuntu-latest
steps:
- name: Retrieve deployment URL (example on how to set an ENV var)
run: "echo VERCEL_DEPLOYMENT_URL=nrn-v2-mst-aptd-gcms-lcz-sty-c1-hfq88g3jt.vercel.app >> $GITHUB_ENV"
- uses: UnlyEd/github-action-await-vercel@v1.1.0
id: await-vercel
env:
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
with:
deployment-url: ${{ env.VERCEL_DEPLOYMENT_URL }}
timeout: 10 # Wait for 10 seconds before failing
- name: Displays the deployment name (example on how to read information about the deployment)
run: "echo My deployment is ${{ fromJson(steps.await-vercel.outputs.deploymentDetails).name }}"
Check the documentation to see what information deploymentDetails
contains.
Learn how to enable logging, from within the
github-action-await-vercel
action.
Our GitHub Action is written using the GitHub Actions native core.debug
API.
Therefore, it allows you to enable logging whenever you need to debug what's happening within our action.
To enable debug mode, you have to set a GitHub secret, such as:
ACTIONS_STEP_DEBUG
of valuetrue
Please see the official documentation for more information.
We gladly accept PRs, but please open an issue first, so we can discuss it beforehand.
You'll need to create a .env.test
file based on .env.test.example
.
Then, you'll need to create and add your own Vercel token there (VERCEL_TOKEN
).
This is required because local tests rely on VERCEL_TOKEN
.
(While integration tests on GitHub rely on the GitHub secret VERCEL_TOKEN
instead)
This project is being authored by:
- [Unly] Ambroise Dhenain (Vadorequest) (active)
- Hugo Martin (Demmonius) (active)
Unly is a socially responsible company, fighting inequality and facilitating access to higher education. Unly is committed to making education more inclusive, through responsible funding for students.
We provide technological solutions to help students find the necessary funding for their studies.
We proudly participate in many TechForGood initiatives. To support and learn more about our actions to make education accessible, visit :
- https://twitter.com/UnlyEd
- https://www.facebook.com/UnlyEd/
- https://www.linkedin.com/company/unly
- Interested to work with us?
Tech tips and tricks from our CTO on our Medium page!