xref: /template/strap/.github/bootstrap.sh (revision 28a0073700e27a5e5b86db990d6aaeddadb34981)
1977ce05dSgerardnico#!/bin/bash
2977ce05dSgerardnico# https://docs.github.com/en/actions/learn-github-actions/contexts#example-usage-of-the-github-context
3977ce05dSgerardnico# https://docs.github.com/en/actions/learn-github-actions/variables#using-the-vars-context-to-access-configuration-variable-values
4977ce05dSgerardnico# https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables
504fd306cSNickeauif [ "${GITHUB_EVENT_NAME}" == 'pull_request' ]; then
6977ce05dSgerardnico  # The head ref or source branch of the pull request in a workflow run.
7977ce05dSgerardnico  # This property is only set when the event that triggers a workflow run is either pull_request or pull_request_target.
8977ce05dSgerardnico  # For example, feature-branch-1
904fd306cSNickeau  BUILD_BRANCH=${GITHUB_HEAD_REF}
10977ce05dSgerardnico  # The name of the base ref or target branch of the pull request in a workflow run.
11977ce05dSgerardnico  # This is only set when the event that triggers a workflow run is either pull_request or pull_request_target.
12977ce05dSgerardnico  # For example, main
1304fd306cSNickeau  BUILD_TARGET_BRANCH=${GITHUB_BASE_REF}
1404fd306cSNickeau  echo -e "\nPull request from the branch (${BUILD_BRANCH}) to the branch (${BUILD_TARGET_BRANCH})"
1504fd306cSNickeauelse
16977ce05dSgerardnico  # The short ref name of the branch or tag that triggered the workflow run.
17977ce05dSgerardnico  # This value matches the branch or tag name shown on GitHub.
1804fd306cSNickeau  # For example, feature-branch-1 or 57/merge for a pull request
1904fd306cSNickeau  BUILD_BRANCH=${GITHUB_REF_NAME}
2004fd306cSNickeaufi
2104fd306cSNickeau
2204fd306cSNickeau# ${TRAVIS_BRANCH} in a PR build is the target branch
2304fd306cSNickeau# ${TRAVIS_PULL_REQUEST_BRANCH} is not empty in a PR build
2404fd306cSNickeau#if [ "${TRAVIS_PULL_REQUEST_BRANCH}" == "" ]; then
2504fd306cSNickeau#  BUILD_BRANCH=${TRAVIS_BRANCH}
2604fd306cSNickeau#  echo -e "\nPush Build on the branch (${BUILD_BRANCH})"
2704fd306cSNickeau#else
2804fd306cSNickeau#  BUILD_BRANCH=${TRAVIS_PULL_REQUEST_BRANCH}
2904fd306cSNickeau#  echo -e "\nPull Request Build from the branch (${TRAVIS_PULL_REQUEST_BRANCH})"
3004fd306cSNickeau#fi
3104fd306cSNickeau
3204fd306cSNickeauecho -e "\nGet boot.sh from from the branch (${BUILD_BRANCH})"
33*28a00737Sgerardnicourl="https://raw.githubusercontent.com/ComboStrap/combo_test/${BUILD_BRANCH}/resources/script/ci/boot.sh"
34*28a00737Sgerardnicoif [ -z "$TOKEN" ]; then
35*28a00737Sgerardnico  echo 'The token is mandatory and was not found'
36*28a00737Sgerardnico  exit 1
37*28a00737Sgerardnicofi
38*28a00737Sgerardnicoresponse=$(curl -H "Authorization: token ${TOKEN}" -s -w "%{http_code}" -o "boot.sh" "$url")
39*28a00737Sgerardnico# -s silence
40*28a00737Sgerardnico# -w ask to print the http code
41*28a00737Sgerardnico# -o write the body to this file
42*28a00737Sgerardnicoif [ "$response" != "200" ]; then
43*28a00737Sgerardnico  echo "Error when getting the boot.sh script at $url."
44*28a00737Sgerardnico  echo "HTTP status was not 200 but $response"
45*28a00737Sgerardnico  exit 1
46*28a00737Sgerardnicoelse
47*28a00737Sgerardnico  echo "boot.sh successfully downloaded"
48*28a00737Sgerardnicofi
4904fd306cSNickeauecho -e "\nRun boot.sh"
50977ce05dSgerardnicochmod +x boot.sh
51977ce05dSgerardnicosource boot.sh
52