aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar MarkKoz <[email protected]>2019-05-12 15:19:12 -0700
committerGravatar MarkKoz <[email protected]>2019-05-12 15:19:12 -0700
commit21c75763345876c0909a300d3a5832bde1cede8d (patch)
treed42cc58d6692ea5a49e0be81d0e1dc0d2c108361
parentRemove pushing images for testing CI (diff)
Retrieve previous build's commit using a REST API
The "Builds - List" endpoint is used to retrieve only the most recent successful build. Builds will be fetched for the target branch if the current build is for a PR. Otherwise, the current build's source branch is used. * Remove variable group and COMMIT_HASH stuff * Add logging to the "Check Changed Files" step
-rw-r--r--azure-pipelines.yml18
1 files changed, 10 insertions, 8 deletions
diff --git a/azure-pipelines.yml b/azure-pipelines.yml
index b5a6860..883f554 100644
--- a/azure-pipelines.yml
+++ b/azure-pipelines.yml
@@ -33,9 +33,6 @@ jobs:
displayName: 'Build'
dependsOn: test
- variables:
- - group: snekbox
-
steps:
- task: Docker@1
displayName: 'Login: Docker Hub'
@@ -46,11 +43,19 @@ jobs:
command: 'login'
- script: |
- if [[ -z $COMMIT_HASH ]] || [[ -n "$(git diff $COMMIT_HASH -- docker/base.Dockerfile)" ]]; then
+ 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=${SYSTEM_PULLREQUEST_TARGETBRANCH:-BUILD_SOURCEBRANCH}&api-version=5.0"
+ echo "Retrieving previous build's commit using $REQUEST_URL"
+
+ PREV_COMMIT="$(curl -sSL "${REQUEST_URL}" | grep -Po '"sourceVersion":"\K.*?[^\\](?=",)')"
+ echo "Retrieved $PREV_COMMIT as previous build's commit."
+
+ if [[ -z $PREV_COMMIT ]] || [[ -n "$(git diff $PREV_COMMIT -- docker/base.Dockerfile)" ]]; then
+ echo "Detected changes in docker/base.Dockerfile"
echo "##vso[task.setvariable variable=BASE_CHANGED]1"
fi
- if [[ -z $COMMIT_HASH ]] || [[ -n "$(git diff $COMMIT_HASH -- Pipfile* docker/venv.Dockerfile)" ]]; then
+ if [[ -z $PREV_COMMIT ]] || [[ -n "$(git diff $PREV_COMMIT -- Pipfile* docker/venv.Dockerfile)" ]]; then
+ echo "Detected changes in Pipfile, Pipfile.lock, and/or docker/venv.Dockerfile"
echo "##vso[task.setvariable variable=VENV_CHANGED]1"
fi
displayName: 'Check Changed Files'
@@ -74,8 +79,5 @@ jobs:
displayName: 'Push Virtual Environment Image to Dockerhub'
condition: and(succeeded(), or(variables.BASE_CHANGED, variables.VENV_CHANGED))
- - script: echo "##vso[task.setvariable variable=COMMIT_HASH]$Build.SourceVersion"
- displayName: 'Update Saved Commit Hash'
-
- script: echo "Final image push simulation"
displayName: 'Push Final Image to Dockerhub'