aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--azure-pipelines.yml35
-rwxr-xr-xscripts/check_dockerfiles.sh31
2 files changed, 35 insertions, 31 deletions
diff --git a/azure-pipelines.yml b/azure-pipelines.yml
index 591f87f..bbca0b7 100644
--- a/azure-pipelines.yml
+++ b/azure-pipelines.yml
@@ -96,37 +96,10 @@ jobs:
dockerRegistryEndpoint: 'DockerHub'
command: 'login'
- - script: |
- REQUEST_URL="https://dev.azure.com/python-discord/${SYSTEM_TEAMPROJECTID}/_apis/build/builds?queryOrder=finishTimeDescending&resultFilter=succeeded&\$top=1&repositoryType=${BUILD_REPOSITORY_PROVIDER}&repositoryId=${BUILD_REPOSITORY_NAME}&branchName=${BUILD_SOURCEBRANCH}&api-version=5.0"
- echo "Retrieving previous build's commit using $REQUEST_URL"
- RESPONSE="$(curl -sSL "${REQUEST_URL}")"
-
- if [[ $BUILD_REASON = "PullRequest" ]]; then
- PREV_COMMIT="$(echo "${RESPONSE}" | grep -Po '"pr\.sourceSha"\s*:\s*"\K.*?[^\\](?="\s*[,}])')"
- if [[ -z $PREV_COMMIT ]]; then
- echo "Could not retrieve the previous build's commit. Falling back to the head of the target branch."
- PREV_COMMIT="origin/$SYSTEM_PULLREQUEST_TARGETBRANCH"
- fi
- else
- PREV_COMMIT="$(echo "${RESPONSE}" | grep -Po '"sourceVersion"\s*:\s*"\K.*?[^\\](?="\s*[,}])')"
- fi
-
- if [[ -n $PREV_COMMIT ]]; then
- echo "Using $PREV_COMMIT to compare diffs."
-
- if [[ -z "$(git diff $PREV_COMMIT -- docker/base.Dockerfile)" ]]; then
- echo "No changes detected in docker/base.Dockerfile. The base image will not be built."
- echo "##vso[task.setvariable variable=BASE_CHANGED]false"
- fi
-
- if [[ -z "$(git diff $PREV_COMMIT -- docker/venv.Dockerfile Pipfile*)" ]]; then
- echo "No changes detected in docker/venv.Dockerfile or the Pipfiles. The venv image will not be built."
- echo "##vso[task.setvariable variable=VENV_CHANGED]false"
- fi
- else
- echo "No previous commit was retrieved. Either the previous build is too old and was deleted or the branch was empty before this build. All images will be built."
- fi
- displayName: 'Check Changed Files'
+ - task: ShellScript@2
+ displayName: 'Check If Images Need to Be Built'
+ inputs:
+ scriptPath: scripts/check_dockerfiles.sh
- task: Docker@2
displayName: 'Build Base Image'
diff --git a/scripts/check_dockerfiles.sh b/scripts/check_dockerfiles.sh
new file mode 100755
index 0000000..07e76f8
--- /dev/null
+++ b/scripts/check_dockerfiles.sh
@@ -0,0 +1,31 @@
+#!/usr/bin/env bash
+
+REQUEST_URL="https://dev.azure.com/python-discord/${SYSTEM_TEAMPROJECTID}/_apis/build/builds?queryOrder=finishTimeDescending&resultFilter=succeeded&\$top=1&repositoryType=${BUILD_REPOSITORY_PROVIDER}&repositoryId=${BUILD_REPOSITORY_NAME}&branchName=${BUILD_SOURCEBRANCH}&api-version=5.0"
+echo "Retrieving previous build's commit using $REQUEST_URL"
+RESPONSE="$(curl -sSL "${REQUEST_URL}")"
+
+if [[ $BUILD_REASON = "PullRequest" ]]; then
+ PREV_COMMIT="$(echo "${RESPONSE}" | grep -Po '"pr\.sourceSha"\s*:\s*"\K.*?[^\\](?="\s*[,}])')"
+ if [[ -z $PREV_COMMIT ]]; then
+ echo "Could not retrieve the previous build's commit. Falling back to the head of the target branch."
+ PREV_COMMIT="origin/$SYSTEM_PULLREQUEST_TARGETBRANCH"
+ fi
+else
+ PREV_COMMIT="$(echo "${RESPONSE}" | grep -Po '"sourceVersion"\s*:\s*"\K.*?[^\\](?="\s*[,}])')"
+fi
+
+if [[ -n $PREV_COMMIT ]]; then
+ echo "Using $PREV_COMMIT to compare diffs."
+
+ if [[ -z "$(git diff $PREV_COMMIT -- docker/base.Dockerfile)" ]]; then
+ echo "No changes detected in docker/base.Dockerfile. The base image will not be built."
+ echo "##vso[task.setvariable variable=BASE_CHANGED]false"
+ fi
+
+ if [[ -z "$(git diff $PREV_COMMIT -- docker/venv.Dockerfile Pipfile*)" ]]; then
+ echo "No changes detected in docker/venv.Dockerfile or the Pipfiles. The venv image will not be built."
+ echo "##vso[task.setvariable variable=VENV_CHANGED]false"
+ fi
+else
+ echo "No previous commit was retrieved. Either the previous build is too old and was deleted or the branch was empty before this build. All images will be built."
+fi