diff --git a/.github/WORKFLOW_DISPATCH.md b/.github/WORKFLOW_DISPATCH.md index f96d165d7..2d9859067 100644 --- a/.github/WORKFLOW_DISPATCH.md +++ b/.github/WORKFLOW_DISPATCH.md @@ -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 @@ -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 " \` diff --git a/.github/workflows/deploy-zeit-production.yml b/.github/workflows/deploy-vercel-production.yml similarity index 73% rename from .github/workflows/deploy-zeit-production.yml rename to .github/workflows/deploy-vercel-production.yml index 9690e9e96..eea2b39a1 100644 --- a/.github/workflows/deploy-zeit-production.yml +++ b/.github/workflows/deploy-vercel-production.yml @@ -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: @@ -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 @@ -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 @@ -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 @@ -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) @@ -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 @@ -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 @@ -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 diff --git a/.github/workflows/deploy-zeit-staging.yml b/.github/workflows/deploy-vercel-staging.yml similarity index 72% rename from .github/workflows/deploy-zeit-staging.yml rename to .github/workflows/deploy-vercel-staging.yml index d44f30dc2..e546cc39d 100644 --- a/.github/workflows/deploy-zeit-staging.yml +++ b/.github/workflows/deploy-vercel-staging.yml @@ -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 (staging) +name: Deploy to Vercel (staging) 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: @@ -32,21 +32,21 @@ 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 staging configuration file of the default institution + # Starts a Vercel deployment, using the staging 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-staging-deployment: - name: Starts Zeit deployment (staging) (Ubuntu 18.04) + name: Starts Vercel deployment (staging) (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 (staging) + - name: Deploying on Vercel (staging) # 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 # - Get stdout from deploy command (stderr prints build steps and stdout prints deployment url, which is what we are really looking for) # - Set the deployment url that will be included in the eventual PR comment # - Create a deployment alias based on the branch name, and link it to the deployment (so that each branch has its own domain automatically aliased to the latest commit) @@ -67,74 +67,74 @@ jobs: # Deploy the customer on Vercel using the customer ref # Store the output in a variable so we can extract metadata from it - ZEIT_DEPLOYMENT_OUTPUT=`CUSTOMER_REF=${CUSTOMER_REF_TO_DEPLOY} yarn deploy:customer --token $ZEIT_TOKEN` + VERCEL_DEPLOYMENT_OUTPUT=`CUSTOMER_REF=${CUSTOMER_REF_TO_DEPLOY} yarn deploy:customer --token $VERCEL_TOKEN` # Extract the Vercel deployment url from the deployment output - ZEIT_DEPLOYMENT_URL=`echo $ZEIT_DEPLOYMENT_OUTPUT | egrep -o 'https?://[^ ]+.vercel.app'` - echo "Deployment url: " $ZEIT_DEPLOYMENT_URL - echo "ZEIT_DEPLOYMENT_URL=$ZEIT_DEPLOYMENT_URL" >> $GITHUB_ENV + VERCEL_DEPLOYMENT_URL=`echo $VERCEL_DEPLOYMENT_OUTPUT | egrep -o 'https?://[^ ]+.vercel.app'` + echo "Deployment url: " $VERCEL_DEPLOYMENT_URL + echo "VERCEL_DEPLOYMENT_URL=$VERCEL_DEPLOYMENT_URL" >> $GITHUB_ENV # Build the alias domain based on our own rules (NRN own rules) # Basically, if a branch starts with "v[0-9]" then we consider it to be a "preset branch" and we use the branch name as alias (e.g: "v2-mst-xxx") # Otherwise, we use the deployment name and suffix it using the branch name (e.g: "v2-mst-xxx-branch-name") if [[ ${CURRENT_BRANCH##*/} =~ ^v[0-9]{1,}- ]]; then # Checking if pattern matches with "vX-" where X is a number - ZEIT_DEPLOYMENT_AUTO_BRANCH_ALIAS=${CURRENT_BRANCH##*/} + VERCEL_DEPLOYMENT_AUTO_BRANCH_ALIAS=${CURRENT_BRANCH##*/} else - ZEIT_DEPLOYMENT_AUTO_BRANCH_ALIAS=$(cat vercel.$CUSTOMER_REF_TO_DEPLOY.staging.json | jq --raw-output '.name')-${CURRENT_BRANCH##*/} + VERCEL_DEPLOYMENT_AUTO_BRANCH_ALIAS=$(cat vercel.$CUSTOMER_REF_TO_DEPLOY.staging.json | jq --raw-output '.name')-${CURRENT_BRANCH##*/} fi - echo "Resolved domain alias: " $ZEIT_DEPLOYMENT_AUTO_BRANCH_ALIAS + echo "Resolved domain alias: " $VERCEL_DEPLOYMENT_AUTO_BRANCH_ALIAS - # Zeit alias only allows 41 characters in the domain name, so we only keep the first 41 (41 = 53 - 11 - 1) characters (because Zeit needs 7 chars for ".vercel.app" at the end of the domain name, and count starts at 1, not 0) + # Vercel alias only allows 41 characters in the domain name, so we only keep the first 41 (41 = 53 - 11 - 1) characters (because Vercel needs 7 chars for ".vercel.app" at the end of the domain name, and count starts at 1, not 0) # Also, in order to remove forbidden characters, we transform every characters which are not a "alnum" and \n or \r into '-' - ZEIT_DEPLOYMENT_AUTO_BRANCH_ALIAS=$(echo $ZEIT_DEPLOYMENT_AUTO_BRANCH_ALIAS | head -c 41 | tr -c '[:alnum:]\r\n' - | tr '[:upper:]' '[:lower:]') - echo "Sanitized domain alias (1): " $ZEIT_DEPLOYMENT_AUTO_BRANCH_ALIAS + VERCEL_DEPLOYMENT_AUTO_BRANCH_ALIAS=$(echo $VERCEL_DEPLOYMENT_AUTO_BRANCH_ALIAS | head -c 41 | tr -c '[:alnum:]\r\n' - | tr '[:upper:]' '[:lower:]') + echo "Sanitized domain alias (1): " $VERCEL_DEPLOYMENT_AUTO_BRANCH_ALIAS # Recursively remove any trailing dash ('-') to protect against invalid alias domain (not allowed to end with a trailing slash) - while [[ "$ZEIT_DEPLOYMENT_AUTO_BRANCH_ALIAS" == *- ]] + while [[ "$VERCEL_DEPLOYMENT_AUTO_BRANCH_ALIAS" == *- ]] do - ZEIT_DEPLOYMENT_AUTO_BRANCH_ALIAS=${ZEIT_DEPLOYMENT_AUTO_BRANCH_ALIAS::-1} + VERCEL_DEPLOYMENT_AUTO_BRANCH_ALIAS=${VERCEL_DEPLOYMENT_AUTO_BRANCH_ALIAS::-1} done - echo "Sanitized domain alias (2): " $ZEIT_DEPLOYMENT_AUTO_BRANCH_ALIAS + echo "Sanitized domain alias (2): " $VERCEL_DEPLOYMENT_AUTO_BRANCH_ALIAS # Build alias url - ZEIT_DEPLOYMENT_AUTO_BRANCH_ALIAS="${ZEIT_DEPLOYMENT_AUTO_BRANCH_ALIAS}.vercel.app" - echo "ZEIT_DEPLOYMENT_AUTO_BRANCH_ALIAS=$ZEIT_DEPLOYMENT_AUTO_BRANCH_ALIAS" >> $GITHUB_ENV - echo "Alias domain: "$ZEIT_DEPLOYMENT_AUTO_BRANCH_ALIAS + VERCEL_DEPLOYMENT_AUTO_BRANCH_ALIAS="${VERCEL_DEPLOYMENT_AUTO_BRANCH_ALIAS}.vercel.app" + echo "VERCEL_DEPLOYMENT_AUTO_BRANCH_ALIAS=$VERCEL_DEPLOYMENT_AUTO_BRANCH_ALIAS" >> $GITHUB_ENV + echo "Alias domain: "$VERCEL_DEPLOYMENT_AUTO_BRANCH_ALIAS echo "Aliasing the deployment using the git branch alias:" - echo "npx vercel alias "$ZEIT_DEPLOYMENT_URL $ZEIT_DEPLOYMENT_AUTO_BRANCH_ALIAS + echo "npx vercel alias "$VERCEL_DEPLOYMENT_URL $VERCEL_DEPLOYMENT_AUTO_BRANCH_ALIAS # Create Vercel alias, use "||" to allow failure (keep the build going) even if the alias fails - ZEIT_ALIASING_OUTPUT=`npx vercel alias $ZEIT_DEPLOYMENT_URL $ZEIT_DEPLOYMENT_AUTO_BRANCH_ALIAS --token $ZEIT_TOKEN || echo "Aliasing failed for '$ZEIT_DEPLOYMENT_AUTO_BRANCH_ALIAS', but the build will continue regardless."` - echo $ZEIT_ALIASING_OUTPUT + VERCEL_ALIASING_OUTPUT=`npx vercel alias $VERCEL_DEPLOYMENT_URL $VERCEL_DEPLOYMENT_AUTO_BRANCH_ALIAS --token $VERCEL_TOKEN || echo "Aliasing failed for '$VERCEL_DEPLOYMENT_AUTO_BRANCH_ALIAS', but the build will continue regardless."` + echo $VERCEL_ALIASING_OUTPUT # TODO Resolve whether the aliasing has worked and change the GitHub comment "Comment PR (Deployment success)" # Find all custom aliases configured in the customer deployment configuration file (vercel.json) - ZEIT_DEPLOYMENT_ALIASES_JSON=$(cat vercel.$CUSTOMER_REF_TO_DEPLOY.staging.json | jq --raw-output '.alias') - echo "Custom aliases: " $ZEIT_DEPLOYMENT_ALIASES_JSON + VERCEL_DEPLOYMENT_ALIASES_JSON=$(cat vercel.$CUSTOMER_REF_TO_DEPLOY.staging.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.staging.json) + readarray -t VERCEL_DEPLOYMENT_ALIASES < <(jq --raw-output '.alias[]' < vercel.$CUSTOMER_REF_TO_DEPLOY.staging.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 CURRENT_BRANCH: ${{ github.ref }} # Passing current branch to the worker # We need to find the PR id. Will be used later to comment on that PR. @@ -154,7 +154,7 @@ jobs: issue-number: ${{ steps.pr_id_finder.outputs.number }} body: | :x:  Deployment **FAILED** - Commit ${{ github.sha }} failed to deploy to [${{ env.ZEIT_DEPLOYMENT_URL }}](${{ env.ZEIT_DEPLOYMENT_URL }}) + Commit ${{ github.sha }} failed to deploy to [${{ env.VERCEL_DEPLOYMENT_URL }}](${{ env.VERCEL_DEPLOYMENT_URL }}) [click to see logs](https://github.com/UnlyEd/next-right-now/pull/${{ steps.pr_id_finder.outputs.number }}/checks) # On deployment success, add a comment to the PR, if there is an open PR for the current branch @@ -166,10 +166,10 @@ jobs: issue-number: ${{ steps.pr_id_finder.outputs.number }} body: | :white_check_mark:  Deployment **SUCCESS** - Commit ${{ github.sha }} successfully deployed to [${{ env.ZEIT_DEPLOYMENT_URL }}](${{ env.ZEIT_DEPLOYMENT_URL }}) - Deployment aliased as [${{ env.ZEIT_DEPLOYMENT_AUTO_BRANCH_ALIAS }}](https://${{ env.ZEIT_DEPLOYMENT_AUTO_BRANCH_ALIAS }}) + Commit ${{ github.sha }} successfully deployed to [${{ env.VERCEL_DEPLOYMENT_URL }}](${{ env.VERCEL_DEPLOYMENT_URL }}) + Deployment aliased as [${{ env.VERCEL_DEPLOYMENT_AUTO_BRANCH_ALIAS }}](https://${{ env.VERCEL_DEPLOYMENT_AUTO_BRANCH_ALIAS }}) - # 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 @@ -179,14 +179,14 @@ jobs: needs: start-staging-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 @@ -213,24 +213,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-customer-ci-cd.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) @@ -264,7 +268,7 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} issue-number: ${{ steps.pr_id_finder.outputs.number }} body: | - :x:  E2E tests **FAILED** for commit ${{ github.sha }} previously deployed at [${{ env.ZEIT_DEPLOYMENT_URL }}](${{ env.ZEIT_DEPLOYMENT_URL }}) + :x:  E2E tests **FAILED** for commit ${{ github.sha }} previously deployed at [${{ env.VERCEL_DEPLOYMENT_URL }}](${{ env.VERCEL_DEPLOYMENT_URL }}) Download artifacts (screenshots + videos) from [`checks`](https://github.com/UnlyEd/next-right-now/pull/${{ steps.pr_id_finder.outputs.number }}/checks) section # On E2E success, add a comment to the PR, if there is an open PR for the current branch @@ -275,7 +279,7 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} issue-number: ${{ steps.pr_id_finder.outputs.number }} body: | - :white_check_mark:  E2E tests **SUCCESS** for commit ${{ github.sha }} previously deployed at [${{ env.ZEIT_DEPLOYMENT_URL }}](${{ env.ZEIT_DEPLOYMENT_URL }}) + :white_check_mark:  E2E tests **SUCCESS** for commit ${{ github.sha }} previously deployed at [${{ env.VERCEL_DEPLOYMENT_URL }}](${{ env.VERCEL_DEPLOYMENT_URL }}) env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -286,14 +290,14 @@ jobs: needs: start-staging-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 @@ -320,18 +324,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 @@ -348,7 +352,7 @@ jobs: prCommentSaveOld: true # If true, then add a new comment for each commit. Otherwise, update the latest comment (default: false). 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 + urls: ${{ env.VERCEL_DEPLOYMENT_URL }}, ${{ env.VERCEL_DEPLOYMENT_URL }}/en, ${{ env.VERCEL_DEPLOYMENT_URL }}/fr locale: en # Upload HTML report create by lighthouse, could be useful diff --git a/.github/workflows/update-codeclimate-coverage.yml b/.github/workflows/update-codeclimate-coverage.yml index fba843a60..93e7e33ec 100644 --- a/.github/workflows/update-codeclimate-coverage.yml +++ b/.github/workflows/update-codeclimate-coverage.yml @@ -19,7 +19,7 @@ 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) run-tests-coverage: name: Run tests coverage and send report to Code Climate runs-on: ubuntu-latest diff --git a/.gitignore b/.gitignore index 16d256a0a..e58d8bedc 100644 --- a/.gitignore +++ b/.gitignore @@ -137,7 +137,7 @@ cypress/videos src/svg/*.js src/svg/*.tsx -# Zeit +# Vercel .now .vercel diff --git a/src/components/pageLayouts/Head.tsx b/src/components/pageLayouts/Head.tsx index 1701ca2b5..a4b8afbe4 100644 --- a/src/components/pageLayouts/Head.tsx +++ b/src/components/pageLayouts/Head.tsx @@ -21,7 +21,7 @@ export type HeadProps = { * https://github.com/vercel/next.js#populating-head */ const Head: React.FunctionComponent = (props): JSX.Element => { - const defaultDescription = 'Flexible production-grade boilerplate with Next.js 9, Zeit and TypeScript. Includes multiple opt-in presets using GraphQL, Analytics, CSS-in-JS, Monitoring, End-to-end testing, Internationalization, CI/CD and SaaS B2B multiple single-tenants (monorepo) support'; + const defaultDescription = 'Flexible production-grade boilerplate with Next.js 9, Vercel and TypeScript. Includes multiple opt-in presets using GraphQL, Analytics, CSS-in-JS, Monitoring, End-to-end testing, Internationalization, CI/CD and SaaS B2B multiple single-tenants (monorepo) support'; const defaultOGURL = 'https://github.com/UnlyEd/next-right-now'; const defaultOGImage = 'https://storage.googleapis.com/the-funding-place/assets/images/Logo_TFP_quadri_horizontal.svg'; const defaultFavicon = 'https://storage.googleapis.com/the-funding-place/assets/images/default_favicon.ico';