Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GHA] Filter Vercel deployments by project, when resolving latest deployment #177

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions .github/workflows/deploy-zeit-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ jobs:
# - Resolve the last url (from `response.deployments[0].url`)
# - Remove the `"` character to pre-format url
# We need to set env the url for next step, formatted as `https://${$ZEIT_DEPLOYMENT}`
# XXX If you need to play around with the "jq" library, check out https://jqplay.org/
run: |
apt update -y >/dev/null && apt install -y jq >/dev/null

Expand All @@ -107,10 +108,16 @@ jobs:
ALL_ZEIT_DEPLOYMENTS=`curl -H 'Accept: application/json' -H 'Content-Type: application/json' -H 'Authorization: Bearer ${{ secrets.ZEIT_TOKEN }}' $VERCEL_FETCH_DEPLOYMENTS_API_ENDPOINT`
echo "Vercel deployments for current team: " $ALL_ZEIT_DEPLOYMENTS

# Filter deployments by their "name" property in order to consider only deployments related to the current project
ZEIT_LATEST_DEPLOYMENT_FOR_CURRENT_PROJECT=`echo $ALL_ZEIT_DEPLOYMENTS | jq '.deployments[] | select(.name == "$VERCEL_PROJECT_NAME") | .url'`
echo "Latest Vercel deployment for current project: " $ZEIT_LATEST_DEPLOYMENT_FOR_CURRENT_PROJECT

# Extract the first element (which is the latest vercel deployment), and strip the double quotes from its value
ZEIT_LATEST_DEPLOYMENT_DOMAIN_FOR_CURRENT_PROJECT=`echo $ZEIT_LATEST_DEPLOYMENT_FOR_CURRENT_PROJECT | jq --raw-output '[].url'`
echo "Latest Vercel deployment domain url for current project: " $ZEIT_LATEST_DEPLOYMENT_DOMAIN_FOR_CURRENT_PROJECT

# Parse the deployments (as json) to find the latest deployment url, while stripping the double quotes
# TODO Do not use '.deployments [0].url' blindly, but filter the deployments array first to make sure to consider only the deployments where "name" is equal to $VERCEL_PROJECT_NAME
ZEIT_DEPLOYMENT=`echo $ALL_ZEIT_DEPLOYMENTS | jq '.deployments [0].url' | tr -d \"`
echo "ZEIT_DEPLOYMENT_URL=https://$ZEIT_DEPLOYMENT" >> $GITHUB_ENV
echo "ZEIT_DEPLOYMENT_URL=https://$ZEIT_LATEST_DEPLOYMENT_DOMAIN_FOR_CURRENT_PROJECT" >> $GITHUB_ENV
echo "Url where to run E2E tests (ZEIT_DEPLOYMENT_URL): " $ZEIT_DEPLOYMENT_URL

# Run the E2E tests against the new Zeit deployment
Expand Down Expand Up @@ -152,6 +159,7 @@ jobs:
# - Resolve the last url (from `response.deployments[0].url`)
# - Remove the `"` character to pre-format url
# We need to set env the url for next step, formatted as `https://${$ZEIT_DEPLOYMENT}/en` using /en endpoint to improve perfs by avoiding the url redirect on /
# XXX If you need to play around with the "jq" library, check out https://jqplay.org/
run: |
apt update -y >/dev/null && apt install -y jq >/dev/null

Expand All @@ -177,10 +185,16 @@ jobs:
ALL_ZEIT_DEPLOYMENTS=`curl -H 'Accept: application/json' -H 'Content-Type: application/json' -H 'Authorization: Bearer ${{ secrets.ZEIT_TOKEN }}' $VERCEL_FETCH_DEPLOYMENTS_API_ENDPOINT`
echo "Vercel deployments for current team: " $ALL_ZEIT_DEPLOYMENTS

# Filter deployments by their "name" property in order to consider only deployments related to the current project
ZEIT_LATEST_DEPLOYMENT_FOR_CURRENT_PROJECT=`echo $ALL_ZEIT_DEPLOYMENTS | jq '.deployments[] | select(.name == "$VERCEL_PROJECT_NAME") | .url'`
echo "Latest Vercel deployment for current project: " $ZEIT_LATEST_DEPLOYMENT_FOR_CURRENT_PROJECT

# Extract the first element (which is the latest vercel deployment), and strip the double quotes from its value
ZEIT_LATEST_DEPLOYMENT_DOMAIN_FOR_CURRENT_PROJECT=`echo $ZEIT_LATEST_DEPLOYMENT_FOR_CURRENT_PROJECT | jq --raw-output '[].url'`
echo "Latest Vercel deployment domain url for current project: " $ZEIT_LATEST_DEPLOYMENT_DOMAIN_FOR_CURRENT_PROJECT

# Parse the deployments (as json) to find the latest deployment url, while stripping the double quotes
# TODO Do not use '.deployments [0].url' blindly, but filter the deployments array first to make sure to consider only the deployments where "name" is equal to $VERCEL_PROJECT_NAME
ZEIT_DEPLOYMENT=`echo $ALL_ZEIT_DEPLOYMENTS | jq '.deployments [0].url' | tr -d \"`
echo "ZEIT_DEPLOYMENT_URL=https://$ZEIT_DEPLOYMENT" >> $GITHUB_ENV
echo "ZEIT_DEPLOYMENT_URL=https://$ZEIT_LATEST_DEPLOYMENT_DOMAIN_FOR_CURRENT_PROJECT" >> $GITHUB_ENV
echo "Url where to run LightHouse tests (ZEIT_DEPLOYMENT_URL): " $ZEIT_DEPLOYMENT_URL
env:
ZEIT_TOKEN: ${{ secrets.ZEIT_TOKEN }} # Passing github's secret to the worker
Expand Down
26 changes: 20 additions & 6 deletions .github/workflows/deploy-zeit-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ jobs:
# - Resolve the last url (from `response.deployments[0].url`)
# - Remove the `"` character to pre-format url
# We need to set env the url for next step, formatted as `https://${$ZEIT_DEPLOYMENT}`
# XXX If you need to play around with the "jq" library, check out https://jqplay.org/
run: |
apt update -y >/dev/null && apt install -y jq >/dev/null

Expand All @@ -176,10 +177,16 @@ jobs:
ALL_ZEIT_DEPLOYMENTS=`curl -H 'Accept: application/json' -H 'Content-Type: application/json' -H 'Authorization: Bearer ${{ secrets.ZEIT_TOKEN }}' $VERCEL_FETCH_DEPLOYMENTS_API_ENDPOINT`
echo "Vercel deployments for current team: " $ALL_ZEIT_DEPLOYMENTS

# Filter deployments by their "name" property in order to consider only deployments related to the current project
ZEIT_LATEST_DEPLOYMENT_FOR_CURRENT_PROJECT=`echo $ALL_ZEIT_DEPLOYMENTS | jq '.deployments[] | select(.name == "$VERCEL_PROJECT_NAME") | .url'`
echo "Latest Vercel deployment for current project: " $ZEIT_LATEST_DEPLOYMENT_FOR_CURRENT_PROJECT

# Extract the first element (which is the latest vercel deployment), and strip the double quotes from its value
ZEIT_LATEST_DEPLOYMENT_DOMAIN_FOR_CURRENT_PROJECT=`echo $ZEIT_LATEST_DEPLOYMENT_FOR_CURRENT_PROJECT | jq --raw-output '[].url'`
echo "Latest Vercel deployment domain url for current project: " $ZEIT_LATEST_DEPLOYMENT_DOMAIN_FOR_CURRENT_PROJECT

# Parse the deployments (as json) to find the latest deployment url, while stripping the double quotes
# TODO Do not use '.deployments [0].url' blindly, but filter the deployments array first to make sure to consider only the deployments where "name" is equal to $VERCEL_PROJECT_NAME
ZEIT_DEPLOYMENT=`echo $ALL_ZEIT_DEPLOYMENTS | jq '.deployments [0].url' | tr -d \"`
echo "ZEIT_DEPLOYMENT_URL=https://$ZEIT_DEPLOYMENT" >> $GITHUB_ENV
echo "ZEIT_DEPLOYMENT_URL=https://$ZEIT_LATEST_DEPLOYMENT_DOMAIN_FOR_CURRENT_PROJECT" >> $GITHUB_ENV
echo "Url where to run E2E tests (ZEIT_DEPLOYMENT_URL): " $ZEIT_DEPLOYMENT_URL

# Run the E2E tests against the new Zeit deployment
Expand Down Expand Up @@ -252,6 +259,7 @@ jobs:
# - Resolve the last url (from `response.deployments[0].url`)
# - Remove the `"` character to pre-format url
# We need to set env the url for next step, formatted as `https://${$ZEIT_DEPLOYMENT}/en` using /en endpoint to improve perfs by avoiding the url redirect on /
# XXX If you need to play around with the "jq" library, check out https://jqplay.org/
run: |
apt update -y >/dev/null && apt install -y jq >/dev/null

Expand All @@ -277,10 +285,16 @@ jobs:
ALL_ZEIT_DEPLOYMENTS=`curl -H 'Accept: application/json' -H 'Content-Type: application/json' -H 'Authorization: Bearer ${{ secrets.ZEIT_TOKEN }}' $VERCEL_FETCH_DEPLOYMENTS_API_ENDPOINT`
echo "Vercel deployments for current team: " $ALL_ZEIT_DEPLOYMENTS

# Filter deployments by their "name" property in order to consider only deployments related to the current project
ZEIT_LATEST_DEPLOYMENT_FOR_CURRENT_PROJECT=`echo $ALL_ZEIT_DEPLOYMENTS | jq '.deployments[] | select(.name == "$VERCEL_PROJECT_NAME") | .url'`
echo "Latest Vercel deployment for current project: " $ZEIT_LATEST_DEPLOYMENT_FOR_CURRENT_PROJECT

# Extract the first element (which is the latest vercel deployment), and strip the double quotes from its value
ZEIT_LATEST_DEPLOYMENT_DOMAIN_FOR_CURRENT_PROJECT=`echo $ZEIT_LATEST_DEPLOYMENT_FOR_CURRENT_PROJECT | jq --raw-output '[].url'`
echo "Latest Vercel deployment domain url for current project: " $ZEIT_LATEST_DEPLOYMENT_DOMAIN_FOR_CURRENT_PROJECT

# Parse the deployments (as json) to find the latest deployment url, while stripping the double quotes
# TODO Do not use '.deployments [0].url' blindly, but filter the deployments array first to make sure to consider only the deployments where "name" is equal to $VERCEL_PROJECT_NAME
ZEIT_DEPLOYMENT=`echo $ALL_ZEIT_DEPLOYMENTS | jq '.deployments [0].url' | tr -d \"`
echo "ZEIT_DEPLOYMENT_URL=https://$ZEIT_DEPLOYMENT" >> $GITHUB_ENV
echo "ZEIT_DEPLOYMENT_URL=https://$ZEIT_LATEST_DEPLOYMENT_DOMAIN_FOR_CURRENT_PROJECT" >> $GITHUB_ENV
echo "Url where to run LightHouse tests (ZEIT_DEPLOYMENT_URL): " $ZEIT_DEPLOYMENT_URL
env:
ZEIT_TOKEN: ${{ secrets.ZEIT_TOKEN }} # Passing github's secret to the worker
Expand Down