diff --git a/src/commands/monorepo/set-if-file-changed.yml b/src/commands/monorepo/set-if-file-changed.yml index 914fbdb6..503726d0 100644 --- a/src/commands/monorepo/set-if-file-changed.yml +++ b/src/commands/monorepo/set-if-file-changed.yml @@ -1,7 +1,7 @@ description: | Set the given env var to true if a changed file matches one of the given patterns. - The `CHANGED_FILES` environment variable must be set with the `get_changes_files` command prior - to running this command. + The `CHANGED_FILES_FILE` environment variable (a path to the changed-files list, set by the + `get_changed_files` command) must be set prior to running this command. parameters: file-patterns: description: | @@ -22,7 +22,7 @@ steps: << parameters.target-env-var >>=false for FILE_PATTERN in ${FILE_PATTERNS?}; do - if egrep "^.\s+$FILE_PATTERN\$" \<<< "$CHANGED_FILES"; then + if egrep "^.\s+$FILE_PATTERN\$" "${CHANGED_FILES_FILE:?}"; then << parameters.target-env-var >>=true echo "Found $FILE_PATTERN in changed files, setting << parameters.target-env-var >> to true" break diff --git a/src/commands/monorepo/set-service-data-json.yml b/src/commands/monorepo/set-service-data-json.yml index c855abb2..290d5529 100644 --- a/src/commands/monorepo/set-service-data-json.yml +++ b/src/commands/monorepo/set-service-data-json.yml @@ -1,7 +1,7 @@ description: | Set the service metadata array in a json file. - The `CHANGED_FILES` environment variable must be set with the `get_changes_files` command prior - to running this command. + The `CHANGED_FILES_FILE` environment variable (a path to the changed-files list, set by the + `get_changed_files` command) must be set prior to running this command. parameters: service-directories: description: | @@ -36,7 +36,7 @@ steps: echo "Checking if $SERVICE was modified..." MODIFIED=false - if grep "$DIRECTORY/$SERVICE" \<<< "${CHANGED_FILES?}"; then + if grep "$DIRECTORY/$SERVICE" "${CHANGED_FILES_FILE:?}"; then MODIFIED=true fi COMPONENT_NAME=$(jq --raw-output ".serviceName" $DIRECTORY/$SERVICE/package.json) diff --git a/src/commands/utils/get_changed_files.yml b/src/commands/utils/get_changed_files.yml index 4752e2c4..7a380824 100644 --- a/src/commands/utils/get_changed_files.yml +++ b/src/commands/utils/get_changed_files.yml @@ -1,11 +1,11 @@ parameters: - target_env_var: - description: Environment variable to set with the list of changed files - type: env_var_name - default: CHANGED_FILES + target_file: + description: Absolute path to write the list of changed files to. Absolute so it survives consumers that set a custom working_directory (e.g. helm). + type: string + default: /tmp/changed_files.txt steps: - run: - name: Put list of changed files in << parameters.target_env_var >> environment variable + name: Write list of changed files to << parameters.target_file >> command: | if [[ -z $COMPUTED_BASE_REVISION ]]; then BASE_REVISION="master" @@ -19,5 +19,5 @@ steps: if [[ $BASE == $CIRCLE_SHA1 ]]; then BASE="$(git rev-parse HEAD~1)" fi - FILE_CHANGES="$(git diff --name-status --no-commit-id -r $BASE...$CIRCLE_SHA1)" - echo "export << parameters.target_env_var >>=\"$FILE_CHANGES\"" >> "$BASH_ENV" + git diff --name-status --no-commit-id -r $BASE...$CIRCLE_SHA1 > "<< parameters.target_file >>" + echo "export CHANGED_FILES_FILE=\"<< parameters.target_file >>\"" >> "$BASH_ENV" diff --git a/src/scripts/helm/get_modified_charts.sh b/src/scripts/helm/get_modified_charts.sh index 6d1fec86..8bfe0ad2 100644 --- a/src/scripts/helm/get_modified_charts.sh +++ b/src/scripts/helm/get_modified_charts.sh @@ -1,7 +1,7 @@ #!/bin/bash # Expected environment variables: -echo "CHANGED_FILES: ${CHANGED_FILES?}" +echo "CHANGED_FILES_FILE: ${CHANGED_FILES_FILE:?}" echo "CHART_DIR: ${CHART_DIR:?}" echo "MODIFIED_CHARTS_ENV: ${MODIFIED_CHARTS_ENV:?}" @@ -26,7 +26,7 @@ done # Extract only modified charts MODIFIED_CHARTS=() for CHART in "${ALL_CHARTS[@]}"; do - if grep -q -oP "(M|A)\s*${CHART_DIR}${CHART}/${CHART}/.*" <<< "${CHANGED_FILES?}"; then + if grep -q -oP "(M|A)\s*${CHART_DIR}${CHART}/${CHART}/.*" "${CHANGED_FILES_FILE:?}"; then MODIFIED_CHARTS+=("$CHART") fi; done @@ -34,4 +34,4 @@ done echo "${MODIFIED_CHARTS[@]}" # shellcheck disable=SC2145 -echo "export ${MODIFIED_CHARTS_ENV:?}=\"${MODIFIED_CHARTS[@]}\"" >> "$BASH_ENV" \ No newline at end of file +echo "export ${MODIFIED_CHARTS_ENV:?}=\"${MODIFIED_CHARTS[@]}\"" >> "$BASH_ENV"