forked from Teradata/presto-checks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trigger_checks_for_latest_build.sh
executable file
·70 lines (58 loc) · 2.18 KB
/
trigger_checks_for_latest_build.sh
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
#!/usr/bin/env bash
if [[ $# -lt 4 ]]; then
echo 'Usage: trigger_checks_for_latest_build.sh $CHECKS_GITHUB_REPO $CHECKS_REPO_TRAVIS_TOKEN $CHECKS_BRANCH $PRESTO_BRANCH [force]'
echo ''
echo 'Passing $PRESTO_BRANCH = `@{LATEST_SPRINT_BRANCH}` will trigger checks for the latest sprint branch.'
exit 1
fi
CHECKS_GITHUB_REPO=${1/\//%2F}
CHECKS_REPO_TRAVIS_TOKEN=$2
CHECKS_BRANCH=$3
PRESTO_BRANCH=$4
FORCE=$5
ARTIFACTS_S3_BUCKET='teradata-presto'
ARTIFACTS_S3_PATH='travis_build_artifacts/Teradata/presto'
function aws_s3_ls() {
aws s3 ls "$1" --no-sign-request | awk '{print $NF}'
}
if [[ "$PRESTO_BRANCH" == '@{LATEST_SPRINT_BRANCH}' ]]; then
PRESTO_BRANCH=`aws_s3_ls s3://${ARTIFACTS_S3_BUCKET}/${ARTIFACTS_S3_PATH}/ | sed 's/[/]$//' | egrep '^sprint-[0-9]+$' | sort -n -t '-' -k 2 | tail -n1`
echo "Current sprint branch resolved to [${PRESTO_BRANCH}]"
fi
PRESTO_BUILD=`aws_s3_ls s3://${ARTIFACTS_S3_BUCKET}/${ARTIFACTS_S3_PATH}/${PRESTO_BRANCH}/ | sed 's/[/]$//' | sort -n | tail -n1`
if [[ -z $PRESTO_BUILD ]]; then
echo "No builds found for branch [$PRESTO_BRANCH]. Exiting."
exit 1
fi
CHECKS_RESULTS_DIR=`aws_s3_ls s3://${ARTIFACTS_S3_BUCKET}/${ARTIFACTS_S3_PATH}/${PRESTO_BRANCH}/${PRESTO_BUILD}/travis_checks/${CHECKS_BRANCH}/`
if [[ "$FORCE" == '' && "$CHECKS_RESULTS_DIR" != '' ]]; then
echo "Checks for checks branch: [${CHECKS_BRANCH}] already performed for build [${PRESTO_BUILD}], not triggering them again."
exit 0
fi
BODY=$(cat << EOF
{
"request": {
"message": "Checks for Presto branch [$PRESTO_BRANCH] build [$PRESTO_BUILD]",
"branch": "$CHECKS_BRANCH",
"config": {
"before_install": [
"export ARTIFACTS_S3_BUCKET='$ARTIFACTS_S3_BUCKET'",
"export ARTIFACTS_S3_PATH='$ARTIFACTS_S3_PATH'",
"export PRESTO_BRANCH='$PRESTO_BRANCH'",
"export PRESTO_BUILD='$PRESTO_BUILD'"
]
}
}
}
EOF
)
echo "Sending the following request:"
echo $BODY
echo "Response was:"
curl -s -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Travis-API-Version: 3" \
-H "Authorization: token $CHECKS_REPO_TRAVIS_TOKEN" \
-d "$BODY" \
https://api.travis-ci.org/repo/$CHECKS_GITHUB_REPO/requests