Terminus code that looks for multidev and creates one if needed

PHOTO EMBED

Mon Aug 15 2022 19:26:33 GMT+0000 (UTC)

Saved by @MattMoniz #yaml #terminus

    # Node.js
# Build a general Node.js project with npm.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/javascript

trigger:
- none

variables:
- name: src
  value: $(System.DefaultWorkingDirectory)/tests/visual_regression_tests
- name: branchName
  value: $(Build.SourceBranchName)
  
pool:
  vmImage: ubuntu-latest

steps:
- task: NodeTool@0
  inputs:
    versionSpec: '14.x'
  displayName: 'Install Node.js'

- task: Bash@3
  inputs:
    targetType: 'inline'
    script: 'brew install pantheon-systems/external/terminus'

- script: |
    terminus auth:login --machine-token=$(TERMINUS_TOKEN)
  displayName: 'Terminus Authentication'
  workingDirectory: $(src)

- script: |
    PANTHEON_MULTIDEV_LIST="$(terminus multidev:list -n bmc-org --format=list --field=Name)"
    echo PANTHEON_MULTIDEV_LIST
  displayName: 'Terminus check available multidevs'
  workingDirectory: $(src)

- task: Bash@3
  inputs:
    targetType: 'inline'
    script: |
      #!/bin/bash
      
      # Exit on error
      set -e

      # Stash list of all Pantheon sites in the org
      PANTHEON_SITES="$(terminus multidev:list -n bmc-org --format=list --field=Name)"
        FOUND="false"
        
      # Loop through each site in the list
      while read -r PANTHEON_SITES
      do
      # if the branch is found then let user know that this branch exists and exit the script.
        if [ $PANTHEON_SITES == $(branchName) ];
        then
            echo "Multidev was found!"
            FOUND="true"
            echo "Existing multidev URL: https://$(branchName)-bmc-org.pantheonsite.io/"
            break
        fi

      done <<< "$PANTHEON_SITES"

      #if the branch was not found then create a branch with the desired name
      if [ $FOUND == "false" ];
      then
        terminus multidev:create bmc-org.live $(branchName)
        echo "New multidev URL: https://$(branchName)-bmc-org.pantheonsite.io/"
      fi

- script: |
    npm install
    export PERCY_TOKEN=$(PERCY_TOKEN)
    export PERCY_TARGET_BRANCH=$(PERCY_TARGET_BRANCH)
    npx percy exec -- cypress run --config baseUrl="https://$(branchName)-bmc-org.pantheonsite.io/"
  displayName: 'NPM Install and Percy Setup and Execute'
  workingDirectory: $(src)
content_copyCOPY