Skip to content

Commit 4479de4

Browse files
committed
ci: extract uploading artifacts into a script
1 parent 2dd4e73 commit 4479de4

File tree

3 files changed

+54
-30
lines changed

3 files changed

+54
-30
lines changed

src/ci/azure-pipelines/steps/run.yml

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -201,37 +201,21 @@ steps:
201201
condition: and(succeeded(), not(variables.SKIP_JOB))
202202
displayName: Run build
203203

204-
# If we're a deploy builder, use the `aws` command to publish everything to our
205-
# bucket.
206-
- bash: |
207-
set -e
208-
source src/ci/shared.sh
209-
if [ "$AGENT_OS" = "Linux" ]; then
210-
rm -rf obj/build/dist/doc
211-
upload_dir=obj/build/dist
212-
else
213-
rm -rf build/dist/doc
214-
upload_dir=build/dist
215-
fi
216-
ls -la $upload_dir
217-
deploy_dir=rustc-builds
218-
if [ "$DEPLOY_ALT" == "1" ]; then
219-
deploy_dir=rustc-builds-alt
220-
fi
221-
retry aws s3 cp --no-progress --recursive --acl public-read ./$upload_dir s3://$DEPLOY_BUCKET/$deploy_dir/$BUILD_SOURCEVERSION
204+
- bash: src/ci/scripts/upload-artifacts.sh
222205
env:
223206
AWS_ACCESS_KEY_ID: $(UPLOAD_AWS_ACCESS_KEY_ID)
224207
AWS_SECRET_ACCESS_KEY: $(UPLOAD_AWS_SECRET_ACCESS_KEY)
225-
condition: and(succeeded(), not(variables.SKIP_JOB), or(eq(variables.DEPLOY, '1'), eq(variables.DEPLOY_ALT, '1')))
226208
displayName: Upload artifacts
227-
228-
# Upload CPU usage statistics that we've been gathering this whole time. Always
229-
# execute this step in case we want to inspect failed builds, but don't let
230-
# errors here ever fail the build since this is just informational.
231-
- bash: aws s3 cp --acl public-read cpu-usage.csv s3://$DEPLOY_BUCKET/rustc-builds/$BUILD_SOURCEVERSION/cpu-$CI_JOB_NAME.csv
232-
env:
233-
AWS_ACCESS_KEY_ID: $(UPLOAD_AWS_ACCESS_KEY_ID)
234-
AWS_SECRET_ACCESS_KEY: $(UPLOAD_AWS_SECRET_ACCESS_KEY)
235-
condition: variables['UPLOAD_AWS_SECRET_ACCESS_KEY']
236-
continueOnError: true
237-
displayName: Upload CPU usage statistics
209+
# Adding a condition on DEPLOY=1 or DEPLOY_ALT=1 is not needed as all deploy
210+
# builders *should* have the AWS credentials available. Still, explicitly
211+
# adding the condition is helpful as this way CI will not silently skip
212+
# deploying artifacts from a dist builder if the variables are misconfigured,
213+
# erroring about invalid credentials instead.
214+
condition: |
215+
and(
216+
succeeded(), not(variables.SKIP_JOB),
217+
or(
218+
variables.UPLOAD_AWS_SECRET_ACCESS_KEY,
219+
eq(variables.DEPLOY, '1'), eq(variables.DEPLOY_ALT, '1')
220+
)
221+
)

src/ci/scripts/upload-artifacts.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
# Upload all the artifacts to our S3 bucket. All the files inside ${upload_dir}
3+
# will be uploaded to the deploy bucket and eventually signed and released in
4+
# static.rust-lang.org.
5+
6+
set -euo pipefail
7+
IFS=$'\n\t'
8+
9+
source "$(cd "$(dirname "$0")" && pwd)/../shared.sh"
10+
11+
upload_dir="$(mktemp -d)"
12+
13+
# Release tarballs produced by a dist builder.
14+
if [[ "${DEPLOY-0}" = "1" ]] || [[ "${DEPLOY_ALT-0}" = "1" ]]; then
15+
dist_dir=build/dist
16+
if isLinux; then
17+
dist_dir=obj/build/dist
18+
fi
19+
rm -rf "${dist_dir}/doc"
20+
cp -r "${dist_dir}"/* "${upload_dir}"
21+
fi
22+
23+
# CPU usage statistics.
24+
cp cpu-usage.csv "${upload_dir}/cpu-${CI_JOB_NAME}.csv"
25+
26+
echo "Files that will be uploaded:"
27+
ls -lah "${upload_dir}"
28+
echo
29+
30+
deploy_dir="rustc-builds"
31+
if [[ "${DEPLOY_ALT-0}" = "1" ]]; then
32+
deploy_dir="rustc-builds-alt"
33+
fi
34+
deploy_url="s3://${DEPLOY_BUCKET}/${deploy_dir}/$(ciCommit)"
35+
36+
retry aws s3 cp --no-progress --recursive --acl public-read "${upload_dir}" "${deploy_url}"

src/ci/shared.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ function getCIBranch {
4646
echo "$BUILD_SOURCEBRANCHNAME"
4747
}
4848

49+
function ciCommit {
50+
echo "${BUILD_SOURCEVERSION}"
51+
}
52+
4953
function ciCommandAddPath {
5054
if [[ $# -ne 1 ]]; then
5155
echo "usage: $0 <path>"

0 commit comments

Comments
 (0)