Skip to content

Commit

Permalink
Rename Zeit to Vercel (#213) (modified)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vadorequest committed Nov 21, 2020
1 parent a87b55e commit e668f9c
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 121 deletions.
4 changes: 2 additions & 2 deletions .github/WORKFLOW_DISPATCH.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ This call will return all your workflow, so make sure you use the right one.
##### Find our Next-Right-Now workflow id
- [Open https://api.github.com/repos/UnlyEd/next-right-now/actions/workflows](https://api.github.com/repos/UnlyEd/next-right-now/actions/workflows)
- `643638` here it is! (for `Deploy to Zeit (staging)` workflow)
- `643638` here it is! (for `Deploy to Vercel (staging)` workflow)
### Example
Expand All @@ -94,7 +94,7 @@ Make sure to adapt the **owner**, and the **repository name** to reflect yours.
curl -s \
-X GET \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/UnlyEd/next-right-now/actions/workflows | jq '.workflows[] | select(.path==".github/workflows/deploy-zeit-staging.yml") | .id'
https://api.github.com/repos/UnlyEd/next-right-now/actions/workflows | jq '.workflows[] | select(.path==".github/workflows/deploy-vercel-staging.yml") | .id'
```

**N.B**: You'll need to provide an `Authorization` header for private repositories. e.g: `-H "Authorization: token <YOUR_GITHUB_TOKEN>" \`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Summary:
# Creates a new deployment on Zeit's platform, when anything is pushed in any branch (except for the "master" branch).
# Creates a new deployment on Vercel's platform, when anything is pushed in any branch (except for the "master" branch).
# Read ./README.md for extensive documentation

name: Deploy to Zeit (production)
name: Deploy to Vercel (production)

on:
# There are several ways to trigger Github actions - See https://help.github.com/en/actions/reference/events-that-trigger-workflows#example-using-a-single-event for a comprehensive list:
Expand Down Expand Up @@ -32,18 +32,18 @@ jobs:
- name: Installing node.js
uses: actions/setup-node@v1 # Used to install node environment - XXX https://github.com/actions/setup-node
with:
node-version: '12.x' # Use the same node.js version as the one Zeit's uses (currently node12.x)
node-version: '12.x' # Use the same node.js version as the one Vercel's uses (currently node12.x)

# Starts a Zeit deployment, using the production configuration file of the default institution
# Starts a Vercel deployment, using the production configuration file of the default institution
# The default institution is the one defined in the `vercel.json` file (which is a symlink to the actual file)
# N.B: It's Zeit that will perform the actual deployment
# N.B: It's Vercel that will perform the actual deployment
start-production-deployment:
name: Starts Zeit deployment (production) (Ubuntu 18.04)
name: Starts Vercel deployment (production) (Ubuntu 18.04)
runs-on: ubuntu-18.04
needs: setup-environment
steps:
- uses: actions/checkout@v1 # Get last commit pushed - XXX See https://github.com/actions/checkout
- name: Deploying on Zeit (production)
- name: Deploying on Vercel (production)
# Workflow overview:
# - Resolve customer to deploy from github event input (falls back to resolving it from vercel.json file)
# - Deploy the customer in production
Expand All @@ -61,37 +61,37 @@ jobs:
echo "Customer to deploy: " $CUSTOMER_REF_TO_DEPLOY
# Deploy the customer on Vercel using the customer specified in vercel.json
CUSTOMER_REF=${CUSTOMER_REF_TO_DEPLOY} yarn deploy:customer:production:simple --token $ZEIT_TOKEN
CUSTOMER_REF=${CUSTOMER_REF_TO_DEPLOY} yarn deploy:customer:production:simple --token $VERCEL_TOKEN
# Find all custom aliases configured in the customer deployment configuration file (vercel.json)
ZEIT_DEPLOYMENT_ALIASES_JSON=$(cat vercel.$CUSTOMER_REF_TO_DEPLOY.production.json | jq --raw-output '.alias')
echo "Custom aliases: " $ZEIT_DEPLOYMENT_ALIASES_JSON
VERCEL_DEPLOYMENT_ALIASES_JSON=$(cat vercel.$CUSTOMER_REF_TO_DEPLOY.production.json | jq --raw-output '.alias')
echo "Custom aliases: " $VERCEL_DEPLOYMENT_ALIASES_JSON
# Convert the JSON array into a bash array - See https://unix.stackexchange.com/a/615717/60329
readarray -t ZEIT_DEPLOYMENT_ALIASES < <(jq --raw-output '.alias[]' < vercel.$CUSTOMER_REF_TO_DEPLOY.production.json)
readarray -t VERCEL_DEPLOYMENT_ALIASES < <(jq --raw-output '.alias[]' < vercel.$CUSTOMER_REF_TO_DEPLOY.production.json)
# Count the number of element in the array, will be 0 if it's an empty array, or if the "alias" key wasn't defined
ZEIT_DEPLOYMENT_ALIASES_COUNT=${#ZEIT_DEPLOYMENT_ALIASES[@]}
VERCEL_DEPLOYMENT_ALIASES_COUNT=${#VERCEL_DEPLOYMENT_ALIASES[@]}
# Check if there are no aliases configured
if [ "$ZEIT_DEPLOYMENT_ALIASES" > 0 ]
if [ "$VERCEL_DEPLOYMENT_ALIASES" > 0 ]
then
echo "$ZEIT_DEPLOYMENT_ALIASES_COUNT alias(es) found. Aliasing them now..."
echo "$VERCEL_DEPLOYMENT_ALIASES_COUNT alias(es) found. Aliasing them now..."
# For each alias configured, then assign it to the deployed domain
for DEPLOYMENT_ALIAS in "${ZEIT_DEPLOYMENT_ALIASES[@]}"; do
echo "npx vercel alias "$ZEIT_DEPLOYMENT_URL $DEPLOYMENT_ALIAS
npx vercel alias $ZEIT_DEPLOYMENT_URL $DEPLOYMENT_ALIAS --token $ZEIT_TOKEN || echo "Aliasing failed for '$DEPLOYMENT_ALIAS', but the build will continue regardless."
for DEPLOYMENT_ALIAS in "${VERCEL_DEPLOYMENT_ALIASES[@]}"; do
echo "npx vercel alias "$VERCEL_DEPLOYMENT_URL $DEPLOYMENT_ALIAS
npx vercel alias $VERCEL_DEPLOYMENT_URL $DEPLOYMENT_ALIAS --token $VERCEL_TOKEN || echo "Aliasing failed for '$DEPLOYMENT_ALIAS', but the build will continue regardless."
done
else
# $ZEIT_DEPLOYMENT_ALIASES is null, this happens when it was not defined in the vercel.json file
# $VERCEL_DEPLOYMENT_ALIASES is null, this happens when it was not defined in the vercel.json file
echo "There are no more aliases to configure. You can add more aliases from your vercel.json 'alias' property. See https://vercel.com/docs/configuration?query=alias%20domain#project/alias"
echo "$ZEIT_DEPLOYMENT_ALIASES"
echo "$VERCEL_DEPLOYMENT_ALIASES"
fi
env:
ZEIT_TOKEN: ${{ secrets.ZEIT_TOKEN }} # Passing github's secret to the worker
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} # Passing github's secret to the worker

# Runs E2E tests against the Zeit deployment
# Runs E2E tests against the Vercel deployment
run-2e2-tests:
name: Run end to end (E2E) tests (Ubuntu 18.04)
runs-on: ubuntu-18.04
Expand All @@ -101,14 +101,14 @@ jobs:
needs: start-production-deployment
steps:
- uses: actions/checkout@v1 # Get last commit pushed - XXX See https://github.com/actions/checkout
- name: Resolving deployment url from Zeit
- name: Resolving deployment url from Vercel
# Workflow overview:
# - Resolve customer to deploy from github event input (falls back to resolving it from vercel.json file)
# - Resolve $ZEIT_DEPLOYMENT_URL
# - Resolve $VERCEL_DEPLOYMENT_URL
# - Fetch all deployments data (by using the scope in `vercel.json`)
# - 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}`
# We need to set env the url for next step, formatted as `https://${$VERCEL_DEPLOYMENT}`
# XXX You can use https://jqplay.org/ if you want to play around with "jq" to manipulate JSON
run: |
apt update -y >/dev/null && apt install -y jq >/dev/null
Expand All @@ -135,24 +135,28 @@ jobs:
VERCEL_FETCH_DEPLOYMENTS_API_ENDPOINT="https://api.zeit.co/v5/now/deployments?teamId=$VERCEL_TEAM_ID"
echo "Fetching Vercel deployments using API endpoint: " $VERCEL_FETCH_DEPLOYMENTS_API_ENDPOINT
# Fetch all zeit deployment from this project
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
# Fetch all Vercel deployment from this project
ALL_VERCEL_DEPLOYMENTS=`curl -H 'Accept: application/json' -H 'Content-Type: application/json' -H 'Authorization: Bearer ${{ secrets.VERCEL_TOKEN }}' $VERCEL_FETCH_DEPLOYMENTS_API_ENDPOINT`
echo "Vercel deployments for current team: " $ALL_VERCEL_DEPLOYMENTS
# 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 \"`
ZEIT_DEPLOYMENT_URL="https://$ZEIT_DEPLOYMENT"
echo "Url where to run E2E tests (ZEIT_DEPLOYMENT_URL): " $ZEIT_DEPLOYMENT_URL
echo "ZEIT_DEPLOYMENT_URL=$ZEIT_DEPLOYMENT_URL" >> $GITHUB_ENV
VERCEL_DEPLOYMENT=`echo $ALL_VERCEL_DEPLOYMENTS | jq '.deployments [0].url' | tr -d \"`
VERCEL_DEPLOYMENT_URL="https://$VERCEL_DEPLOYMENT"
echo "Url where to run E2E tests (VERCEL_DEPLOYMENT_URL): " $VERCEL_DEPLOYMENT_URL
echo "VERCEL_DEPLOYMENT_URL=$VERCEL_DEPLOYMENT_URL" >> $GITHUB_ENV
# Run the E2E tests against the new Zeit deployment
# Run the E2E tests against the new Vercel deployment
- name: Run E2E tests (Cypress)
uses: cypress-io/github-action@v2 # XXX See https://github.com/cypress-io/github-action
with:
wait-on: ${{ env.ZEIT_DEPLOYMENT_URL }} # Be sure that the endpoint is ready by pinging it before starting tests, it has a timeout of 60seconds
wait-on: ${{ env.VERCEL_DEPLOYMENT_URL }} # Be sure that the endpoint is ready by pinging it before starting tests, it has a timeout of 60seconds
config-file: cypress/config-${{ env.CUSTOMER_REF_TO_DEPLOY }}.json # The config file itself doesn't matter because we will override most settings anyway. We just need `projectId` to run the tests.
config: baseUrl=${{ env.ZEIT_DEPLOYMENT_URL }} # Overriding baseUrl provided by config file to test the new deployment
config: baseUrl=${{ env.VERCEL_DEPLOYMENT_URL }} # Overriding baseUrl provided by config file to test the new deployment
env:
# Enables Cypress debugging logs, very useful if Cypress crashes, like out-of-memory issues.
# DEBUG: "cypress:*" # Enable all logs. See https://docs.cypress.io/guides/references/troubleshooting.html#Print-DEBUG-logs
DEBUG: "cypress:server:util:process_profiler" # Enable logs for "memory and CPU usage". See https://docs.cypress.io/guides/references/troubleshooting.html#Log-memory-and-CPU-usage

# On E2E failure, upload screenshots
- name: Upload screenshots artifacts (E2E failure)
Expand All @@ -177,14 +181,14 @@ jobs:
needs: start-production-deployment
steps:
- uses: actions/checkout@v1 # Get last commit pushed - XXX See https://github.com/actions/checkout
- name: Resolving deployment url from Zeit
- name: Resolving deployment url from Vercel
# Workflow overview:
# - Resolve customer to deploy from github event input (falls back to resolving it from vercel.json file)
# - Resolve $ZEIT_DEPLOYMENT_URL
# - Resolve $VERCEL_DEPLOYMENT_URL
# - Fetch all deployments data (by using the scope in `vercel.json`)
# - 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 /
# We need to set env the url for next step, formatted as `https://${$VERCEL_DEPLOYMENT}/en` using /en endpoint to improve perfs by avoiding the url redirect on /
# XXX You can use https://jqplay.org/ if you want to play around with "jq" to manipulate JSON
run: |
apt update -y >/dev/null && apt install -y jq >/dev/null
Expand All @@ -211,18 +215,18 @@ jobs:
VERCEL_FETCH_DEPLOYMENTS_API_ENDPOINT="https://api.zeit.co/v5/now/deployments?teamId=$VERCEL_TEAM_ID"
echo "Fetching Vercel deployments using API endpoint: " $VERCEL_FETCH_DEPLOYMENTS_API_ENDPOINT
# Fetch all zeit deployment from this project
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
# Fetch all Vercel deployment from this project
ALL_VERCEL_DEPLOYMENTS=`curl -H 'Accept: application/json' -H 'Content-Type: application/json' -H 'Authorization: Bearer ${{ secrets.VERCEL_TOKEN }}' $VERCEL_FETCH_DEPLOYMENTS_API_ENDPOINT`
echo "Vercel deployments for current team: " $ALL_VERCEL_DEPLOYMENTS
# 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 \"`
ZEIT_DEPLOYMENT_URL="https://$ZEIT_DEPLOYMENT"
echo "Url where to run LightHouse tests (ZEIT_DEPLOYMENT_URL): " $ZEIT_DEPLOYMENT_URL
echo "ZEIT_DEPLOYMENT_URL=$ZEIT_DEPLOYMENT_URL" >> $GITHUB_ENV
VERCEL_DEPLOYMENT=`echo $ALL_VERCEL_DEPLOYMENTS | jq '.deployments [0].url' | tr -d \"`
VERCEL_DEPLOYMENT_URL="https://$VERCEL_DEPLOYMENT"
echo "Url where to run LightHouse tests (VERCEL_DEPLOYMENT_URL): " $VERCEL_DEPLOYMENT_URL
echo "VERCEL_DEPLOYMENT_URL=$VERCEL_DEPLOYMENT_URL" >> $GITHUB_ENV
env:
ZEIT_TOKEN: ${{ secrets.ZEIT_TOKEN }} # Passing github's secret to the worker
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} # Passing github's secret to the worker
# In order to store reports and then upload it, we need to create the folder before any tests
- name: Create temporary folder for artifacts storage
run: mkdir /tmp/lighthouse-artifacts
Expand All @@ -236,7 +240,7 @@ jobs:
# XXX We don't enable comments, because there is no branch to write them into
outputDirectory: /tmp/lighthouse-artifacts # Used to upload artifacts.
emulatedFormFactor: all # Run LightHouse against "mobile", "desktop", or "all" devices
urls: ${{ env.ZEIT_DEPLOYMENT_URL }}, ${{ env.ZEIT_DEPLOYMENT_URL }}/en, ${{ env.ZEIT_DEPLOYMENT_URL }}/fr, ${{ env.ZEIT_DEPLOYMENT_URL }}/en-US, ${{ env.ZEIT_DEPLOYMENT_URL }}/fr-FR
urls: ${{ env.VERCEL_DEPLOYMENT_URL }}, ${{ env.VERCEL_DEPLOYMENT_URL }}/en, ${{ env.VERCEL_DEPLOYMENT_URL }}/fr, ${{ env.VERCEL_DEPLOYMENT_URL }}/en-US, ${{ env.VERCEL_DEPLOYMENT_URL }}/fr-FR

# Upload HTML report create by lighthouse, could be useful
- name: Upload artifacts
Expand Down
Loading

1 comment on commit e668f9c

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.