DEV Community

Cover image for I've made a GitHub action to get deployment URL on pull requests
Dor Shinar
Dor Shinar

Posted on

I've made a GitHub action to get deployment URL on pull requests

My blog is hosted on Vercel (formerly Zeit Now), and while Vercel does a great job deploying my blog on every change (which in itself is super convenient), I could not figure out how to run tests against said deployments.

I've explored GitHub actions previously, and even wrote about it here, so I was familiar with the concept, but it still baffled me, so I've decided to give up on it and just run a local server as part of my CI pipeline.

Some months past, and I've had more time to experiment with it, and what I ended up with was an action I wrote myself, to query GitHub's GraphQL API and get the deployment url as a step output, so I could consume it in later steps.

You can find the action on the GitHub Marketplace. Using it is very straight forward:

# Rest of your workflow.yml...

- name: Get deployment URL
  id: deployment
  uses: dorshinar/get-deployment-url@v1.0.0
  timeout-minutes: 5 
  with:
    token: ${{ secrets.GITHUB_TOKEN }}

- name: Run end-to-end tests
  run: npm run test:e2e
  env:
    deployment: ${{ steps.deployment.outputs.deployment }}

# Rest of your workflow.yml...

The action should (hopefully) work with all CI pipelines, given that they use GitHub's Deployment API. Please note that the action waits for the deployment to complete, and so I added timeout-minutes to it, so it doesn't run for too long.

That all. I'm planning on writing a more technical article explaining exactly how I accomplished it, but I just wanted to share it with you.

Oldest comments (2)

Collapse
 
drptbl profile image
Jakub Mucha • Edited

Hey Dor,
It's a great example. However I think that Vercel deployment should be integrated in to the CI with Vercel CLI instead of being separate entity (GitHub app). Makes life a lot easier, in all aspects. Also gives you more ability to control deployments, for example if you don't want to deploy an app if vulnernability was found in node dependencies.
Cheers,
Jakub.

Collapse
 
dorshinar profile image
Dor Shinar

I'm sure that's a great option too. I chose to stick with a GitHub App for the simplicity.