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