Set up an upstream project in Travis CI

I am working on a project where I have two Git Repos:

Repo1 - DevRepo, Rep02- TestRepo

My scenario: Whenever a commit or PR occurs on Repo1, follow these steps.

Step 1: Run Repo2 Directly

Step 2: After step 1 is successful, Repo1 must be started.

Basically, Repo1 should be built only if Repo2 is running and it becomes successful.

Can someone please help me how can I configure this, praised:

  • which .travis.yml file should be configured for my script.
  • the exact setup steps that I can write in my .travis.yml file
+4
source share
2

: :

  • : Repo2, travis api: trigger_build.sh :
`
body='{
"request": {
  "branch":"master"
}}'

curl -s -X POST \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -H "Travis-API-Version: 3" \
  -H "Authorization: token ..git_hub_login_token.." \
  -d "$body" \
  https://api.travis-ci.org/repo/xxxx%2Fyyyy/requests

#The 15s sleep is to allow Travis to trigger the dependent build:
sleep 15`
  1. get_build_status.sh. . Repo2, Repo1, Repo1:
# Polling for the Repo2 build status
# Setting a maximum time for the Repo2 build to run, however once we get the status to passed/failed, we will return to the Repo1 build run

`i=1
max=300
while [ $i -lt $max ]
do

echo "--------------------------------------------"
echo "Polling for the tests run build status..."`

curl -i -H "Accept: application/vnd.travis-ci.2+json" "https://api.travis-ci.org/repos/xxxx/yyyy/builds" > test.json
LATEST_STATE=$(grep -o '"state":.[a-z\"]*' test.json | head -1)
#LATEST_ID=$(grep -o '"id":.[0-9]*' test.json | head -1 | grep ':.[0-9]*')

get_state_value=${LATEST_STATE#*:}
STATE="${get_state_value//\"}"

if [ $STATE == "passed" ]
then
  echo "TESTS RUN... $STATE :-) "
  break #As soon as the Repo2 run pass, we break and return back to the Repo1 build run
elif [ $STATE == "failed" ]
then
 echo "TESTS RUN... $STATE :-("
 echo "Stop building elements"
 exit 1 #As soon as the Repo2 run fail, we stop building Repo1
fi

true $(( i++ ))
sleep 1 #This 1s is required to poll the build status for every second
done

  1. .travis.yml:
script:
- chmod 777 ./trigger_build.sh
- chmod 777 ./get_build_status.sh
- ./trigger_build.sh
- ./get_build_status.sh

+1

CI . : https://github.com/cesium-ml/dependent_build_server

:

  • , GitHub , PR .
  • API- Travis-CI , , .
  • Travis-CI , webhook, .
  • API GitHub, PR.

. , GitHub Travis-CI. GitHub, Travis-CI, .

GitHub:

import hmac

def verify_signature(payload, signature, secret):
    expected = 'sha1=' + hmac.new(secret.encode('ascii'),
                                  payload, 'sha1').hexdigest()   
    return hmac.compare_digest(signature, expected)

-CI:

from OpenSSL import crypto

def verify_signature(payload, signature):

    # Get this by querying the Travis-CI config API
    public_key = crypto.load_publickey(crypto.FILETYPE_PEM, pubkey)
    certificate = crypto.X509()
    certificate.set_pubkey(public_key)

    try:
        crypto.verify(certificate, signature, payload, 'sha1')
        return True
    except crypto.Error:
        return False
+1

Source: https://habr.com/ru/post/1627068/


All Articles