1977ce05dSgerardnico#!/bin/bash 223be6a68Sgerardnico 3*0bba9e16Sgerardnico 423be6a68Sgerardnico 5977ce05dSgerardnico# https://docs.github.com/en/actions/learn-github-actions/contexts#example-usage-of-the-github-context 6977ce05dSgerardnico# https://docs.github.com/en/actions/learn-github-actions/variables#using-the-vars-context-to-access-configuration-variable-values 7977ce05dSgerardnico# https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables 804fd306cSNickeauif [ "${GITHUB_EVENT_NAME}" == 'pull_request' ]; then 9977ce05dSgerardnico # The head ref or source branch of the pull request in a workflow run. 10977ce05dSgerardnico # This property is only set when the event that triggers a workflow run is either pull_request or pull_request_target. 11977ce05dSgerardnico # For example, feature-branch-1 1204fd306cSNickeau BUILD_BRANCH=${GITHUB_HEAD_REF} 13977ce05dSgerardnico # The name of the base ref or target branch of the pull request in a workflow run. 14977ce05dSgerardnico # This is only set when the event that triggers a workflow run is either pull_request or pull_request_target. 15977ce05dSgerardnico # For example, main 1604fd306cSNickeau BUILD_TARGET_BRANCH=${GITHUB_BASE_REF} 1704fd306cSNickeau echo -e "\nPull request from the branch (${BUILD_BRANCH}) to the branch (${BUILD_TARGET_BRANCH})" 1804fd306cSNickeauelse 19977ce05dSgerardnico # The short ref name of the branch or tag that triggered the workflow run. 20977ce05dSgerardnico # This value matches the branch or tag name shown on GitHub. 2104fd306cSNickeau # For example, feature-branch-1 or 57/merge for a pull request 2204fd306cSNickeau BUILD_BRANCH=${GITHUB_REF_NAME} 2304fd306cSNickeaufi 2404fd306cSNickeau 2504fd306cSNickeau# ${TRAVIS_BRANCH} in a PR build is the target branch 2604fd306cSNickeau# ${TRAVIS_PULL_REQUEST_BRANCH} is not empty in a PR build 2704fd306cSNickeau#if [ "${TRAVIS_PULL_REQUEST_BRANCH}" == "" ]; then 2804fd306cSNickeau# BUILD_BRANCH=${TRAVIS_BRANCH} 2904fd306cSNickeau# echo -e "\nPush Build on the branch (${BUILD_BRANCH})" 3004fd306cSNickeau#else 3104fd306cSNickeau# BUILD_BRANCH=${TRAVIS_PULL_REQUEST_BRANCH} 3204fd306cSNickeau# echo -e "\nPull Request Build from the branch (${TRAVIS_PULL_REQUEST_BRANCH})" 3304fd306cSNickeau#fi 3404fd306cSNickeau 3504fd306cSNickeauecho -e "\nGet boot.sh from from the branch (${BUILD_BRANCH})" 3628a00737Sgerardnicourl="https://raw.githubusercontent.com/ComboStrap/combo_test/${BUILD_BRANCH}/resources/script/ci/boot.sh" 37*0bba9e16Sgerardnicoif [ -z "$TOKEN" ]; then 38*0bba9e16Sgerardnico echo 'The token variable is mandatory as first parameter' 39*0bba9e16Sgerardnico echo 'Did you inherit the secret when calling your workflow: https://docs.github.com/en/actions/using-workflows/reusing-workflows#passing-inputs-and-secrets-to-a-reusable-workflow' 40*0bba9e16Sgerardnico exit 1 41*0bba9e16Sgerardnicofi 4228a00737Sgerardnicoresponse=$(curl -H "Authorization: token ${TOKEN}" -s -w "%{http_code}" -o "boot.sh" "$url") 4328a00737Sgerardnico# -s silence 4428a00737Sgerardnico# -w ask to print the http code 4528a00737Sgerardnico# -o write the body to this file 4628a00737Sgerardnicoif [ "$response" != "200" ]; then 4728a00737Sgerardnico echo "Error when getting the boot.sh script at $url." 4828a00737Sgerardnico echo "HTTP status was not 200 but $response" 4928a00737Sgerardnico exit 1 5028a00737Sgerardnicoelse 5128a00737Sgerardnico echo "boot.sh successfully downloaded" 5228a00737Sgerardnicofi 5304fd306cSNickeauecho -e "\nRun boot.sh" 54977ce05dSgerardnicochmod +x boot.sh 55977ce05dSgerardnicosource boot.sh 56