github.com/web-platform-tests/wpt.fyi@v0.0.0-20240530210107-70cf978996f1/util/deploy-staging.sh (about) 1 #!/bin/bash 2 3 # Helper script for posting a GitHub comment pointing to the deployed environment, 4 # from GitHub Actions. Also see deploy.sh 5 6 usage() { 7 USAGE="Usage: deploy-staging.sh [-f] [app path] 8 -f : Always deploy (even if no changes detected) 9 app path: wpt.fyi relative path for the app, e.g. \"webapp\"" 10 echo "${USAGE}" 11 } 12 13 APP_PATH=${@: -1} 14 while getopts ':fhq' flag; do 15 case "${flag}" in 16 f) FORCE_PUSH='true' ;; 17 h|*) usage && exit 0;; 18 esac 19 done 20 21 if [[ "${APP_PATH}" == "" ]]; then fatal "app path not specified."; fi 22 23 APP_DEPS="${APP_PATH}" 24 if [[ "${APP_PATH}" == webapp/web* ]]; then APP_DEPS="webapp|api|shared"; fi 25 # Be more conservative: only deploy searchcache when it's directly modified. 26 if [[ "${APP_PATH}" == api/query/cache/service* ]]; then APP_DEPS="api/query"; fi 27 if [[ "${APP_PATH}" == "results-processor/app.staging.yaml" ]]; then APP_DEPS="results-processor"; fi 28 APP_DEPS_REGEX="^(${APP_DEPS})/" 29 30 EXCLUSIONS="_test.go$|webapp/components/test/" 31 32 UTIL_DIR="$(dirname "${BASH_SOURCE[0]}")" 33 source "${UTIL_DIR}/logging.sh" 34 35 # Skip if nothing under $APP_PATH was modified. 36 if [ "${FORCE_PUSH}" != "true" ]; 37 then 38 git diff --name-only HEAD^..HEAD | egrep -v "${EXCLUSIONS}" | egrep "${APP_DEPS_REGEX}" || { 39 info "No changes detected under ${APP_DEPS}. Skipping deploying ${APP_PATH}." 40 exit 0 41 } 42 fi 43 44 debug "Copying output to ${TEMP_FILE:=$(mktemp)}" 45 # NOTE: Most gcloud output is stderr, so need to redirect it to stdout. 46 docker exec -t -u $(id -u $USER):$(id -g $USER) "${DOCKER_INSTANCE}" \ 47 make deploy_staging \ 48 PROJECT=wptdashboard-staging \ 49 APP_PATH="${APP_PATH}" \ 50 BRANCH_NAME="${GITHUB_HEAD_REF:-$GITHUB_REF}" 2>&1 \ 51 | tee ${TEMP_FILE} 52 if [ "${EXIT_CODE:=${PIPESTATUS[0]}}" != "0" ]; then exit ${EXIT_CODE}; fi 53 DEPLOYED_URL=$(tr -d "\r" < ${TEMP_FILE} | sed -ne 's/^Deployed service.*to \[\(.*\)\]$/\1/p') 54 55 # TODO(kyle): Fix deploy-comment.sh; rewrite to GitHub Actions equivalent. 56 # Add a GitHub comment to the PR (if there is a PR). 57 #if [[ -n "${GITHUB_HEAD_REF}" ]]; 58 #then 59 # ${UTIL_DIR}/deploy-comment.sh -e "${APP_PATH}" "${DEPLOYED_URL}"; 60 #fi