1#!/bin/bash 2# https://docs.github.com/en/actions/learn-github-actions/contexts#example-usage-of-the-github-context 3# https://docs.github.com/en/actions/learn-github-actions/variables#using-the-vars-context-to-access-configuration-variable-values 4# https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables 5if [ "${GITHUB_EVENT_NAME}" == 'pull_request' ]; then 6 # The head ref or source branch of the pull request in a workflow run. 7 # This property is only set when the event that triggers a workflow run is either pull_request or pull_request_target. 8 # For example, feature-branch-1 9 BUILD_BRANCH=${GITHUB_HEAD_REF} 10 # The name of the base ref or target branch of the pull request in a workflow run. 11 # This is only set when the event that triggers a workflow run is either pull_request or pull_request_target. 12 # For example, main 13 BUILD_TARGET_BRANCH=${GITHUB_BASE_REF} 14 echo -e "\nPull request from the branch (${BUILD_BRANCH}) to the branch (${BUILD_TARGET_BRANCH})" 15else 16 # The short ref name of the branch or tag that triggered the workflow run. 17 # This value matches the branch or tag name shown on GitHub. 18 # For example, feature-branch-1 or 57/merge for a pull request 19 BUILD_BRANCH=${GITHUB_REF_NAME} 20fi 21 22# ${TRAVIS_BRANCH} in a PR build is the target branch 23# ${TRAVIS_PULL_REQUEST_BRANCH} is not empty in a PR build 24#if [ "${TRAVIS_PULL_REQUEST_BRANCH}" == "" ]; then 25# BUILD_BRANCH=${TRAVIS_BRANCH} 26# echo -e "\nPush Build on the branch (${BUILD_BRANCH})" 27#else 28# BUILD_BRANCH=${TRAVIS_PULL_REQUEST_BRANCH} 29# echo -e "\nPull Request Build from the branch (${TRAVIS_PULL_REQUEST_BRANCH})" 30#fi 31 32echo -e "\nGet boot.sh from from the branch (${BUILD_BRANCH})" 33url="https://raw.githubusercontent.com/ComboStrap/combo_test/${BUILD_BRANCH}/resources/script/ci/boot.sh" 34if [ -z "$TOKEN" ]; then 35 echo 'The token is mandatory and was not found' 36 exit 1 37fi 38response=$(curl -H "Authorization: token ${TOKEN}" -s -w "%{http_code}" -o "boot.sh" "$url") 39# -s silence 40# -w ask to print the http code 41# -o write the body to this file 42if [ "$response" != "200" ]; then 43 echo "Error when getting the boot.sh script at $url." 44 echo "HTTP status was not 200 but $response" 45 exit 1 46else 47 echo "boot.sh successfully downloaded" 48fi 49echo -e "\nRun boot.sh" 50chmod +x boot.sh 51source boot.sh 52