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