# https://aka.ms/yaml jobs: - job: test displayName: 'Lint & Test' pool: vmImage: 'Ubuntu-16.04' steps: - script: | set -euo pipefail 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" printf '%s\n' "Retrieving latest successful build using ${REQUEST_URL}" response="$(curl -sSL "${REQUEST_URL}")" if [[ "$(printf '%s' "${response}" | jq -re '.count')" = 0 ]]; then (>&2 echo \ "No previous build was found." \ "Either the previous build is too old and was deleted" \ "or the branch was empty before this build." ) exit 0 fi prev_build="$(printf '%s' "${response}" | jq -re '.value[0].id')" printf '%s\n' "Most recent successful build: ${prev_build}" printf '%s\n' "##vso[task.setvariable variable=PREV_BUILD;isOutput=true]${prev_build}" if [[ "${BUILD_REASON}" = "PullRequest" ]]; then key='triggerInfo."pr.sourceSha"' else key='sourceVersion' fi prev_commit="$(printf '%s' "${response}" | jq -re ".value[0].${key}")" printf '%s\n' "Previous commit: ${prev_commit}" printf '%s\n' "##vso[task.setvariable variable=PREV_COMMIT;isOutput=true]${prev_commit}" displayName: 'Get Previous Successful Build' - script: echo $(PREV_BUILD) - task: ShellScript@2 inputs: scriptPath: './scripts/test.sh' args: $(PREV_BUILD) displayName: 'Print PREV_BUILD' - task: DownloadPipelineArtifact@2 inputs: buildType: 'specific' project: $(System.TeamProjectId) pipeline: $(System.DefinitionId) buildVersionToDownload: 'specific' buildId: $(PREV_BUILD) artifactName: 'base_id' displayName: 'Download Base ID Artifact' - script: | base_id="$(cat "${SYSTEM_ARTIFACTSDIRECTORY}"/base.sha256)" printf '%s\n' "##vso[task.setvariable variable=BASE_ID]${base_id}" displayName: 'Write Base ID to Variable' - script: docker build -t pythondiscord/snekbox-base:latest -f docker/base.Dockerfile . displayName: 'Build Base Image' - script: | id="$(docker images -q --no-trunc pythondiscord/snekbox-base:latest)" if [[ -z "${id}" ]]; then (>&2 echo 'failed to get ID of pythondiscord/snekbox-base:latest') exit 1 fi printf '%s\n' "Base ID is ${id}" printf '%s' "${id}" >> base.sha256 displayName: 'Create Base ID Artifact' - task: PublishPipelineArtifact@1 inputs: path: base.sha256 artifact: BaseId displayName: 'Publish Base ID Artifact' enabled: false