blob: 5352aa94953da39a1841558ad610ca2dd85a53a6 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# 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
|