-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Converted set-cicd-flag to a YAML template with inline script (#325)
* Converted set-cicd-flag to a YAML template with inline script * Removed replaced script.
- Loading branch information
1 parent
731ac5b
commit 44dbfcf
Showing
4 changed files
with
67 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 0 additions & 46 deletions
46
devops/providers/azure-devops/templates/infrastructure/scripts/set-cicd-flag.sh
This file was deleted.
Oops, something went wrong.
59 changes: 59 additions & 0 deletions
59
devops/providers/azure-devops/templates/infrastructure/scripts/set-cicd-flag.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
parameters: | ||
terraformTemplatePath: '' | ||
jobName: '' | ||
|
||
steps: | ||
- task: Bash@3 | ||
name: ${{ parameters.jobName }} | ||
displayName: Determine if ${{ parameters.jobName }} needs CI/CD | ||
env: | ||
TERRAFORM_TEMPLATE_PATH: ${{ parameters.terraformTemplatePath }} | ||
inputs: | ||
targetType: 'inline' | ||
script: | | ||
#!/usr/bin/env bash | ||
# Note: Omitting `set -euo pipefail` as it makes using grep to filter for changes a nightmare! | ||
declare readonly GIT_DIFF_EXTENSION_WHITE_LIST="*.go|*.tf|*.sh|Dockerfile*|*.tfvars|*.yaml|*.yml" | ||
function setCICDFlag() { | ||
echo "Template $TERRAFORM_TEMPLATE_PATH needs CI/CD" | ||
echo "##vso[task.setvariable variable=needs_cicd;isOutput=true]true" | ||
} | ||
MASTER="remotes/origin/master" | ||
GIT_DIFF_SOURCEBRANCH="HEAD" | ||
# we should always use master as a comparison, except in the case that this is | ||
# a build for master. In this case we can use HEAD~ (1 commit behind master) | ||
# because all merges will be squash merges | ||
if [[ $(git diff "$MASTER") ]]; then | ||
GIT_DIFF_UPSTREAMBRANCH="$MASTER" | ||
else | ||
GIT_DIFF_UPSTREAMBRANCH="$MASTER~" | ||
fi | ||
echo "GIT_DIFF_UPSTREAMBRANCH: $GIT_DIFF_UPSTREAMBRANCH" | ||
echo "GIT_DIFF_SOURCEBRANCH: $GIT_DIFF_SOURCEBRANCH" | ||
FILE_CHANGE_SET=$(git diff "$GIT_DIFF_SOURCEBRANCH" "$GIT_DIFF_UPSTREAMBRANCH" --name-only) | ||
echo "Files changed since last commit..." | ||
echo "$FILE_CHANGE_SET" | ||
FILTERED_FILE_CHANGE_SET=$(grep -E "$GIT_DIFF_EXTENSION_WHITE_LIST" <<< "$FILE_CHANGE_SET" || true) | ||
echo "Files changed since last commit, filtered for build-relevant files..." | ||
echo "$FILTERED_FILE_CHANGE_SET" | ||
TEST_HARNESS_CHANGES=$(grep "$TEST_HARNESS_DIR" <<< "$FILTERED_FILE_CHANGE_SET" || true) | ||
TEMPLATE_CHANGES=$(grep "$TERRAFORM_TEMPLATE_PATH" <<< "$FILTERED_FILE_CHANGE_SET" || true) | ||
PIPELINE_CHANGES=$(grep "$PIPELINE_ROOT_DIR" <<< "$FILTERED_FILE_CHANGE_SET" || true) | ||
MODULE_CHANGES=$(grep "$TF_ROOT_DIR/modules" <<< "$FILTERED_FILE_CHANGE_SET" || true) | ||
# if relevant files have been changed, CICD for this template needs to run | ||
[ ! -z "${TEST_HARNESS_CHANGES}" ] && setCICDFlag | ||
[ ! -z "${TEMPLATE_CHANGES}" ] && setCICDFlag | ||
[ ! -z "${PIPELINE_CHANGES}" ] && setCICDFlag | ||
[ ! -z "${MODULE_CHANGES}" ] && setCICDFlag | ||
exit 0 |