menu

ZEIT

Our mission is to make cloud computing as easy and accessible as mobile computing. You can find our Next.js community here.

Channels
Team

Help with targeting a staging URL on a deployment_status success

October 31, 2019 at 4:31pm
The ZEIT community has a new home. This thread is preserved for historical purposes. The content of this conversation may be innaccurrate or out of date. Go to new community home →

Help with targeting a staging URL on a deployment_status success

October 31, 2019 at 4:31pm
Hello! I'm working on a GH Action that runs e2e tests against Zeit deployments. I'm able to target the preview URL by running my workflow on the deployment_status event. But what I really want is to run the tests against the staging URL.
I don't see the staging URL anywhere in the payload. As far as I can tell, the only place to find it is in a comment on the pull request. I think I'd need to parse that to get the URL, and I'd prefer to avoid that. How can I accomplish my goal of targeting the staging URL after a deployment?

October 31, 2019 at 5:17pm
Alternatively, if our preview URLs had .manifold.now.sh instead of just .manifold.sh, that could also work. Any way to change that?
  • reply
  • like

November 1, 2019 at 12:51pm
Hmm, thanks for the suggestion! That could potentially work. There are a couple things that are unclear to me though, any chance you can provide more detail?
  1. Do you know how I'd get the auth token from the GitHub action?
  2. Do you know how I'd get the deployment ID from the GitHub action?
I think if I could access those two things, I might be able to make this suggestion work.
  • reply
  • like
After some doc & blog post review I think I have some stuff to try out :)
  • reply
  • like
  1. You can issue a token and add it as a secret on your environment: https://zeit.co/account/tokens
  • reply
  • like
  1. Use GET /v10/now/deployments/get?url=[deployment URL or alias] https://zeit.co/docs/api#endpoints/deployments/get-a-single-deployment
  • reply
  • like
Thanks! Those are exactly the things I was going to try! Really appreciate your tips.
  • reply
  • like
Do you know if there's any way to generate a team token though? It looks like I can only generate one for my personal account. I'd prefer for the token to have a team scope.
  • reply
  • like
But I see there's an open issue around adding support for this so maybe it's not possible yet?
  • reply
  • like
Do you know if there's any way to generate a team token though? It looks like I can only generate one for my personal account. I'd prefer for the token to have a team scope.
We don't have this ability yet for security concerns. We need to pint point a single user for any action (security first!), and that include tokens.
  • reply
  • like

November 7, 2019 at 1:32am
Not sure if you were able to set this up successfully or not, but we've been able to set up something similar in GitHub Actions using just the context payload. Figured I'd post it here in case it's useful for you or others in a similar position:
  • reply
  • like
You'll need to be using on: deployment_status for your workflow, and in your job you can use the value in github.event.deployment_status.target_url to get the staging URL for your ZEIT deployment.
  • reply
  • like
We're doing this with a job that only runs on deployment success and assigning to an environment variable that can be used in any of the steps:
jobs:
test:
if: github.event.deployment_status.state == 'success'
name: Smoke tests
runs-on: ubuntu-latest
env:
DEPLOY_URL: ${{ github.event.deployment_status.target_url }}
like-fill
1
  • reply
  • like
Keep in mind, if this is the only job in your workflow, that the if condition can cause other deployment_status updates to add a failed workflow run to your Actions history.
  • reply
  • like
Hi Albert, thanks for the suggestion. That's actually exactly what we were doing! But the URL we actually want to target is an alias of the target_url. Our target_url points to a now.sh domain, but the staging URL that we want to target is on a manifold.now.sh domain. This is why Paulo was suggesting that we use the API to get the alias.
  • reply
  • like

February 21, 2020 at 4:15pm
awesome!!! I was able to get the target_url using on: deployment_status perfectly, but this kind of action doesn't seem to have and effect on "commits checks". Were you able to push this status back to the PR workflow?
  • reply
  • like
I was able to achieve this posting directly to Github's API, for example:
steps:
- name: Trigger pending status event
run: |
curl -L -X POST \
--url https://api.github.com/repos/${{ github.repository }}/statuses/${{ github.sha }} \
--header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
--header 'content-type: application/json' \
--data '{ "state": "pending" }'
  • reply
  • like

March 10, 2020 at 1:38am
awesome!!! I was able to get the target_url using on: deployment_status perfectly, but this kind of action doesn't seem to have and effect on "commits checks". Were you able to push this status back to the PR workflow?
Unfortunately, no, which definitely doesn't make this very useful. I've been back and forth with GitHub support and haven't gotten anywhere. It's a bit inconsistent because if you open up the Actions page for the workflow, the run is shown with the correct status. It just doesn't show up on the checks for the PR even on failures.
  • reply
  • like
It works perfectly when I do pull requests, but if someone else does via a fork against my repo, it doesn't work. I'm trying to understand what's happening, because on their's fork, it works.
  • reply
  • like
This looks similar to the result that GitHub eventually recommended--manually posting the status back to the GitHub API. Seems to do the job but a bit overly complicated considering all other checks work by reporting the status of the job in the form of a check automatically. FWIW here's an example they provided which uses a script step instead of curl: https://github.com/actions-packages-examples/deployment-status-in-checks/blob/master/.github/workflows/mock-deploy.yml
  • reply
  • like

March 10, 2020 at 10:15pm
That's awesome, thanks for the script tip!!!! 🤝
  • reply
  • like