Skip to content

Commit

Permalink
Merge branch 'v2-mst-aptd-gcms-lcz-sty' into next-v10.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Vadorequest committed May 8, 2021
2 parents e9a1f4d + e03b530 commit 69652f3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 185 deletions.
55 changes: 6 additions & 49 deletions .github/workflows/deploy-vercel-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,57 +119,14 @@ jobs:
no_override: true # Disables auto marking previous environments as "inactive", as they're still active (Vercel deployments don't auto-deactivate) and it would remove the previous deployment links needlessly

- name: Deploying on Vercel (${{ env.STAGE }})
# Workflow overview:
# - Deploys the customer and resolves the $VERCEL_DEPLOYMENT_URL from Vercel deployment output
# - Creates multiple deployment aliases based on the "alias" property defined in the vercel.json file, and link them to the deployment
# XXX You can use https://jqplay.org/ if you want to play around with "jq" to manipulate JSON
run: |
# Print the version of the "vercel" CLI being used (helps debugging)
vercel --version
echo "Deploying using git commit SHA: $GIT_COMMIT_SHA and branch/tag: $GIT_COMMIT_REF"
# Deploy the customer on Vercel using the customer ref
# Store the output in a variable so we can extract metadata from it
VERCEL_DEPLOYMENT_OUTPUT=`GIT_COMMIT_REF=${GIT_COMMIT_REF} GIT_COMMIT_SHA=${GIT_COMMIT_SHA} CUSTOMER_REF=${CUSTOMER_REF_TO_DEPLOY} yarn deploy:ci:gha:production --token $VERCEL_TOKEN`
# Extract the Vercel deployment url from the deployment output
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
echo "VERCEL_DEPLOYMENT_DOMAIN=${VERCEL_DEPLOYMENT_URL#https://}" >> $GITHUB_ENV
# Find all custom aliases configured in the customer deployment configuration file (vercel.json)
VERCEL_DEPLOYMENT_ALIASES_JSON=$(cat vercel.$CUSTOMER_REF_TO_DEPLOY.${{ env.STAGE }}.json | jq --raw-output '.alias')
echo "Custom aliases: " $VERCEL_DEPLOYMENT_ALIASES_JSON
if [[ "$VERCEL_DEPLOYMENT_ALIASES_JSON" != "null" ]]; then
# Convert the JSON array into a bash array - See https://unix.stackexchange.com/a/615717/60329
readarray -t VERCEL_DEPLOYMENT_ALIASES < <(jq --raw-output '.alias[]' < vercel.$CUSTOMER_REF_TO_DEPLOY.${{ env.STAGE }}.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
VERCEL_DEPLOYMENT_ALIASES_COUNT=${#VERCEL_DEPLOYMENT_ALIASES[@]}
# Check if there are no aliases configured
if [ "$VERCEL_DEPLOYMENT_ALIASES_COUNT" > 0 ]
then
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 "${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
# $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 "$VERCEL_DEPLOYMENT_ALIASES"
fi
fi
uses: UnlyEd/github-action-deploy-on-vercel@3e71d3e26fd56941fc24a6429fdd257598df2017 # Pin "v1.0.0" - See https://github.com/UnlyEd/github-action-deploy-on-vercel/commit/3e71d3e26fd56941fc24a6429fdd257598df2017
with:
command: "yarn deploy:ci:gha:production --token ${{ secrets.VERCEL_TOKEN }}"
env:
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} # Passing github's secret to the worker
GIT_COMMIT_REF: ${{ github.ref }} # Passing current branch/tag to the worker
GIT_COMMIT_SHA: ${{ github.sha }} # Passing current commit SHA to the worker
GIT_COMMIT_SHA: ${{ github.ref }} # Passing current commit SHA to the worker
CUSTOMER_REF: ${{ env.CUSTOMER_REF_TO_DEPLOY }} # Passing current customer to deploy

# Update the previously created GitHub deployment, and link it to our Vercel deployment
- name: Link GitHub deployment to Vercel
Expand Down Expand Up @@ -218,7 +175,7 @@ jobs:
uses: UnlyEd/github-action-await-vercel@v1.1.1 # See https://github.com/UnlyEd/github-action-await-vercel
id: await-vercel
env:
VERCEL_TOKEN: ${{ secrets.VERCEl_TOKEN }}
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
with:
deployment-url: ${{ env.VERCEL_DEPLOYMENT_DOMAIN }} # Must only contain the domain name (no http prefix, etc.)
timeout: 90 # Wait for 90 seconds before failing
Expand Down
90 changes: 6 additions & 84 deletions .github/workflows/deploy-vercel-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,92 +119,14 @@ jobs:
no_override: true # Disables auto marking previous environments as "inactive", as they're still active (Vercel deployments don't auto-deactivate) and it would remove the previous deployment links needlessly

- name: Deploying on Vercel (${{ env.STAGE }})
# Workflow overview:
# - Deploys the customer and resolves the $VERCEL_DEPLOYMENT_URL from Vercel deployment output
# - Creates 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)
# - Creates multiple deployment aliases based on the "alias" property defined in the vercel.json file, and link them to the deployment
# XXX You can use https://jqplay.org/ if you want to play around with "jq" to manipulate JSON
run: |
# Print the version of the "vercel" CLI being used (helps debugging)
vercel --version
echo "Deploying using git commit SHA: $GIT_COMMIT_SHA and branch/tag: $GIT_COMMIT_REF"
# Deploy the customer on Vercel using the customer ref
# Store the output in a variable so we can extract metadata from it
VERCEL_DEPLOYMENT_OUTPUT=`GIT_COMMIT_REF=${GIT_COMMIT_REF} GIT_COMMIT_SHA=${GIT_COMMIT_SHA} CUSTOMER_REF=${CUSTOMER_REF_TO_DEPLOY} yarn deploy:ci:gha --token $VERCEL_TOKEN`
# Extract the Vercel deployment url from the deployment output
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
echo "VERCEL_DEPLOYMENT_DOMAIN=${VERCEL_DEPLOYMENT_URL#https://}" >> $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 [[ ${GIT_COMMIT_REF##*/} =~ ^v[0-9]{1,}- ]]; then # Checking if pattern matches with "vX-" where X is a number
VERCEL_DEPLOYMENT_AUTO_BRANCH_ALIAS=${GIT_COMMIT_REF##*/}
else
VERCEL_DEPLOYMENT_AUTO_BRANCH_ALIAS=$(cat vercel.$CUSTOMER_REF_TO_DEPLOY.${{ env.STAGE }}.json | jq --raw-output '.name')-${GIT_COMMIT_REF##*/}
fi
echo "Resolved domain alias: " $VERCEL_DEPLOYMENT_AUTO_BRANCH_ALIAS
# 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 '-'
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 [[ "$VERCEL_DEPLOYMENT_AUTO_BRANCH_ALIAS" == *- ]]
do
VERCEL_DEPLOYMENT_AUTO_BRANCH_ALIAS=${VERCEL_DEPLOYMENT_AUTO_BRANCH_ALIAS::-1}
done
echo "Sanitized domain alias (2): " $VERCEL_DEPLOYMENT_AUTO_BRANCH_ALIAS
# Build alias url
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 "$VERCEL_DEPLOYMENT_URL $VERCEL_DEPLOYMENT_AUTO_BRANCH_ALIAS
# Create Vercel alias, use "||" to allow failure (keep the build going) even if the alias fails
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)
VERCEL_DEPLOYMENT_ALIASES_JSON=$(cat vercel.$CUSTOMER_REF_TO_DEPLOY.${{ env.STAGE }}.json | jq --raw-output '.alias')
echo "Custom aliases: " $VERCEL_DEPLOYMENT_ALIASES_JSON
if [[ "$VERCEL_DEPLOYMENT_ALIASES_JSON" != "null" ]]; then
# Convert the JSON array into a bash array - See https://unix.stackexchange.com/a/615717/60329
readarray -t VERCEL_DEPLOYMENT_ALIASES < <(jq --raw-output '.alias[]' < vercel.$CUSTOMER_REF_TO_DEPLOY.${{ env.STAGE }}.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
VERCEL_DEPLOYMENT_ALIASES_COUNT=${#VERCEL_DEPLOYMENT_ALIASES[@]}
# Check if there are no aliases configured
if [ "$VERCEL_DEPLOYMENT_ALIASES_COUNT" > 0 ]
then
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 "${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
# $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 "$VERCEL_DEPLOYMENT_ALIASES"
fi
fi
uses: UnlyEd/github-action-deploy-on-vercel@3e71d3e26fd56941fc24a6429fdd257598df2017 # Pin "v1.0.0" - See https://github.com/UnlyEd/github-action-deploy-on-vercel/commit/3e71d3e26fd56941fc24a6429fdd257598df2017
with:
command: "yarn deploy:ci:gha --token ${{ secrets.VERCEL_TOKEN }}"
env:
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} # Passing github's secret to the worker
GIT_COMMIT_REF: ${{ github.ref }} # Passing current branch/tag to the worker
GIT_COMMIT_SHA: ${{ github.sha }} # Passing current commit SHA to the worker
GIT_COMMIT_SHA: ${{ github.ref }} # Passing current commit SHA to the worker
CUSTOMER_REF: ${{ env.CUSTOMER_REF_TO_DEPLOY }} # Passing current customer to deploy

# Update the previously created GitHub deployment, and link it to our Vercel deployment
- name: Link GitHub deployment to Vercel
Expand Down Expand Up @@ -285,7 +207,7 @@ jobs:
uses: UnlyEd/github-action-await-vercel@v1.1.1 # See https://github.com/UnlyEd/github-action-await-vercel
id: await-vercel
env:
VERCEL_TOKEN: ${{ secrets.VERCEl_TOKEN }}
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
with:
deployment-url: ${{ env.VERCEL_DEPLOYMENT_DOMAIN }} # Must only contain the domain name (no http prefix, etc.)
timeout: 90 # Wait for 90 seconds before failing
Expand Down
57 changes: 7 additions & 50 deletions .github/workflows/deploy-vercel-storybook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,56 +84,13 @@ jobs:
env: storybook # Uses "storybook" as GitHub environment name, because we don't need to manage multiple environments for storybook
no_override: true # Disables auto marking previous environments as "inactive", as they're still active (Vercel deployments don't auto-deactivate) and it would remove the previous deployment links needlessly

- name: Deploying on Vercel
# Workflow overview:
# - Install yarn dependencies (necessary to build the Storybook static site)
# - Starts a Vercel deployment, using vercel.storybook.json
# - Creates multiple deployment aliases based on the "alias" property defined in the vercel.json file, and link them to the deployment
run: |
# Print the version of the "vercel" CLI being used (helps debugging)
vercel --version
echo "Current branch: ${GITHUB_REF_SLUG}"
echo "Installing dependencies"
yarn install
echo "Building and deploying StoryBook static site"
# Deploy the storybook static export on Vercel
# Store the output in a variable so we can extract metadata from it
VERCEL_DEPLOYMENT_OUTPUT=`yarn deploy:sb:gha --token $VERCEL_TOKEN`
# Extract the Vercel deployment url from the deployment output
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
echo "VERCEL_DEPLOYMENT_DOMAIN=${VERCEL_DEPLOYMENT_URL#https://}" >> $GITHUB_ENV
# Find all custom aliases configured in the customer deployment configuration file (vercel.json)
VERCEL_DEPLOYMENT_ALIASES_JSON=$(cat vercel.storybook.json | jq --raw-output '.alias')
echo "Custom aliases: " $VERCEL_DEPLOYMENT_ALIASES_JSON
- name: Install storybook dependencies
run: yarn install

# Convert the JSON array into a bash array - See https://unix.stackexchange.com/a/615717/60329
readarray -t VERCEL_DEPLOYMENT_ALIASES < <(jq --raw-output '.alias[]' < vercel.storybook.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
VERCEL_DEPLOYMENT_ALIASES_COUNT=${#VERCEL_DEPLOYMENT_ALIASES[@]}
# Check if there are no aliases configured
if [ "$VERCEL_DEPLOYMENT_ALIASES" > 0 ]
then
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 "${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
# $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 "$VERCEL_DEPLOYMENT_ALIASES"
fi
- name: Deploying on Vercel
uses: UnlyEd/github-action-deploy-on-vercel@3e71d3e26fd56941fc24a6429fdd257598df2017 # Pin "v1.0.0" - See https://github.com/UnlyEd/github-action-deploy-on-vercel/commit/3e71d3e26fd56941fc24a6429fdd257598df2017
with:
command: "yarn deploy:sb:gha --token ${{ secrets.VERCEL_TOKEN }}"
env:
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} # Passing github's secret to the worker
# Passing exposed GitHub environment variables - See https://github.com/rlespinasse/github-slug-action#exposed-github-environment-variables
Expand Down Expand Up @@ -216,7 +173,7 @@ jobs:
uses: UnlyEd/github-action-await-vercel@v1.1.1 # See https://github.com/UnlyEd/github-action-await-vercel
id: await-vercel
env:
VERCEL_TOKEN: ${{ secrets.VERCEl_TOKEN }}
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
with:
deployment-url: ${{ env.VERCEL_DEPLOYMENT_DOMAIN }} # Must only contain the domain name (no http prefix, etc.)
timeout: 90 # Wait for 90 seconds before failing
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"deploy:all:production": "yarn deploy:customer1:production && yarn deploy:customer2:production",
"deploy:all:production:simple": "yarn deploy:customer1:production:simple && yarn deploy:customer2:production:simple",
"deploy:all:all": "yarn deploy:all && yarn deploy:all:production",
"deploy:ci:gha": "yarn vercel:cleanup && yarn vercel:deploy --local-config=vercel.${CUSTOMER_REF}.staging.json",
"deploy:ci:gha:production": "yarn vercel:cleanup && yarn vercel:deploy --local-config=vercel.${CUSTOMER_REF}.production.json --prod",
"deploy:ci:gha": "yarn vercel:deploy --local-config=vercel.${CUSTOMER_REF}.staging.json",
"deploy:ci:gha:production": "yarn vercel:deploy --local-config=vercel.${CUSTOMER_REF}.production.json --prod",
"deploy:sb:gha": "yarn vercel:cleanup && yarn storybook:export && vercel storybook-static --local-config=vercel.storybook.json --confirm --debug",
"deploy:sb:gha:fast": "yarn vercel:cleanup && vercel storybook-static --local-config=vercel.storybook.json --confirm --debug",
"deploy:customer1:all": "yarn deploy:customer1 && yarn deploy:customer1:production",
Expand Down

0 comments on commit 69652f3

Please sign in to comment.