Skip to content

Commit

Permalink
Update utils.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
kdivya153 authored Oct 12, 2024
1 parent 0ff06fa commit f0253c2
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions .github/workflows/utils.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
#!/bin/bash
set -o pipefail

# Function to check if a branch exists in the remote repository
function branch_exists() {
local branch=$1
git ls-remote --heads https://github.com/rdkcentral/firebolt-apis.git "$branch" | grep -q "$branch"
}

function runTests(){
echo "Determine the branch to checkout"

# Convert event name to lowercase
PR_BRANCH=$(echo "$EVENT_NAME" | tr '[:upper:]' '[:lower:]')

# Check if OPENRPC_PR_BRANCH is not empty and event is repository_dispatch
# Check if OPENRPC_PR_BRANCH is not empty and the event is repository_dispatch
if [ -n "$OPENRPC_PR_BRANCH" ] && [ "$PR_BRANCH" == "repository_dispatch" ]; then
PR_BRANCH=$OPENRPC_PR_BRANCH
echo "Using branch from OPENRPC_PR_BRANCH: $OPENRPC_PR_BRANCH"
# Check if the branch exists in firebolt-apis
if branch_exists "$OPENRPC_PR_BRANCH"; then
PR_BRANCH=$OPENRPC_PR_BRANCH
echo "Using branch from OPENRPC_PR_BRANCH: $OPENRPC_PR_BRANCH"
else
echo "Branch '$OPENRPC_PR_BRANCH' does not exist in firebolt-apis. Defaulting to 'next'."
PR_BRANCH="next"
fi
elif [ "$PR_BRANCH" == "pull_request" ]; then
# If it's a pull request event, use the PR branch
PR_BRANCH=$PR_HEAD_REF
Expand All @@ -19,9 +30,10 @@ function runTests(){
PR_BRANCH=$GITHUB_REF
PR_BRANCH="${PR_BRANCH#refs/heads/}"
else
echo "No OPENRPC_PR_BRANCH set, defaulting to branch 'next'"
PR_BRANCH="next"
echo "Unsupported event: $EVENT_NAME"
exit 1
fi

echo "Cloning firebolt-apis repo with branch: $PR_BRANCH"
git clone --branch ${PR_BRANCH} https://github.com/rdkcentral/firebolt-apis.git
echo "cd to firebolt-apis repo and compile firebolt-open-rpc.json"
Expand Down

0 comments on commit f0253c2

Please sign in to comment.