Unverified Commit a13a43bb authored by Roy Hadad's avatar Roy Hadad Committed by GitHub
Browse files

ci: add polling to wait until travis build is finished (#277)

parent 12b96133
Showing with 67 additions and 12 deletions
+67 -12
......@@ -45,7 +45,7 @@ jobs:
exit 1
fi
BODY="
REQUEST_BUILD_BODY="
{
\"request\": {
\"branch\": \"$branch_name\",
......@@ -62,23 +62,14 @@ jobs:
}
}
"
GH_ORGANIZATION_NAME="datreeio"
GH_REPOSITORY_NAME="datree"
curl -s -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Travis-API-Version: 3" \
-H "Authorization: token ${TRAVIS_API_TOKEN}" \
-d "$BODY" \
"https://api.travis-ci.com/repo/${GH_ORGANIZATION_NAME}%2F${GH_REPOSITORY_NAME}/requests"
REQUEST_BUILD_BODY=$REQUEST_BUILD_BODY ./request-travis-build-and-wait-until-finished.sh
release-docker:
env:
REPO_NAME: datree
IMAGE_NAME: datree
name: Release container image to public registries
needs: [release, define_version_job]
needs: [ release, define_version_job ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
......
#!/bin/bash
GH_ORGANIZATION_NAME="datreeio"
GH_REPOSITORY_NAME="datree"
GH_SLUG=${GH_ORGANIZATION_NAME}%2F${GH_REPOSITORY_NAME}
echo "Requesting a travis build..."
request_build_response=$(curl -s -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Travis-API-Version: 3" \
-H "Authorization: token ${TRAVIS_API_TOKEN}" \
-d "$REQUEST_BUILD_BODY" \
"https://api.travis-ci.com/repo/${GH_SLUG}/requests")
REQUEST_ID=$(echo $request_build_response | jq '.request.id')
echo "Travis request id: ${REQUEST_ID}"
is_travis_build_already_created=false
while true; do
sleep 10
echo "Polling travis build status..."
response=$(curl -s -X GET \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Travis-API-Version: 3" \
-H "Authorization: token ${TRAVIS_API_TOKEN}" \
"https://api.travis-ci.com/repo/${GH_SLUG}/request/${REQUEST_ID}")
build_status=$(echo $response | jq '.builds[0].state')
build_request_state=$(echo $response | jq '.state')
if [ $build_request_state = "\"pending\"" ]; then
echo "Build request pending..."
elif [ $build_status = "\"passed\"" ]; then
echo "Travis build passed!"
exit 0
elif [ $build_status = "\"failed\"" ]; then
echo "Travis build failed!"
exit 1
elif [ $build_status = "\"canceled\"" ]; then
echo "Travis build canceled!"
exit 1
elif [ $build_status = "\"created\"" ]; then
if [ $is_travis_build_already_created = true ]; then
echo "Travis build queued..."
else
echo "Travis build created!"
fi
is_travis_build_already_created=true
elif [ $build_status = "\"started\"" ]; then
echo "Travis build in progress..."
else
echo "Travis build unknown state!"
echo "build_status:${build_status}"
echo "REQUEST_ID:${REQUEST_ID}"
echo "response:${response}"
exit 1
fi
done
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment