diff --git a/.github/workflows/cxx-build.yml b/.github/workflows/cxx-build.yml index 1233cd8fa..221ef8b35 100644 --- a/.github/workflows/cxx-build.yml +++ b/.github/workflows/cxx-build.yml @@ -1,5 +1,7 @@ name: CXX build on: + repository_dispatch: + types: [trigger-workflow] workflow_dispatch: pull_request: branches: diff --git a/.github/workflows/run-standalone-mfos-tests.yml b/.github/workflows/run-standalone-mfos-tests.yml index 073376aa0..4ad784a31 100644 --- a/.github/workflows/run-standalone-mfos-tests.yml +++ b/.github/workflows/run-standalone-mfos-tests.yml @@ -1,12 +1,13 @@ name: MFOS standalone sanity report - CORE,MANAGE,DISCOVERY on: + repository_dispatch: + types: [trigger-workflow] pull_request: types: - opened - synchronize branches: [ next ] - jobs: RunStandaloneTests: runs-on: ubuntu-latest @@ -14,15 +15,26 @@ jobs: - name: Checkout uses: actions/checkout@v2 - #Run tests + # Set the branch if the workflow is triggered from external + - name: Set PR Branch based on the trigger + id: set-pr-branch + run: | + if [ "${{ github.event_name }}" == "repository_dispatch" ]; then + echo "OPENRPC_PR_BRANCH='${{ github.event.client_payload.OPENRPC_PR_BRANCH }}'" >> $GITHUB_ENV # Set from payload + else + echo "OPENRPC_PR_BRANCH=''" >> $GITHUB_ENV # Clear the variable for other events + fi + + # Run tests - name: Run Core Manage and Discovery tests and create assets env: EVENT_NAME: ${{ github.event_name }} GITHUB_REF: ${{ github.ref }} PR_HEAD_REF: ${{ github.event.pull_request.head.ref }} INTENT: ${{ vars.INTENT }} + OPENRPC_PR_BRANCH: ${{ env.OPENRPC_PR_BRANCH }} # Comes from OPENRPC repo if triggered externally run: | - ./.github/workflows/utils.sh runTests + ./.github/workflows/utils.sh runTests - name: Upload report.json as an artifact uses: actions/upload-artifact@v4 @@ -33,6 +45,3 @@ jobs: - name: Get results from report.json run: | ./.github/workflows/utils.sh getResults - - - \ No newline at end of file diff --git a/.github/workflows/utils.sh b/.github/workflows/utils.sh index 17d3f087d..535330363 100755 --- a/.github/workflows/utils.sh +++ b/.github/workflows/utils.sh @@ -8,22 +8,50 @@ cd .. current_dir=$(pwd) cd $current_apis_dir +# 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 "Clone firebolt-apis repo with pr branch" + echo "Determine the branch to checkout" + # Convert event name to lowercase PR_BRANCH=$(echo "$EVENT_NAME" | tr '[:upper:]' '[:lower:]') - if [ "${PR_BRANCH}" == "pull_request" ]; then - PR_BRANCH=$PR_HEAD_REF - elif [ "${PR_BRANCH}" == "push" ]; then - PR_BRANCH=$GITHUB_REF - PR_BRANCH="${PR_BRANCH#refs/heads/}" + + # Check if OPENRPC_PR_BRANCH is not empty and the event is repository_dispatch + if [ -n "$OPENRPC_PR_BRANCH" ] && [ "$PR_BRANCH" == "repository_dispatch" ]; then + # 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 + elif [ "$PR_BRANCH" == "push" ]; then + # For push events, extract the branch name + PR_BRANCH=$GITHUB_REF + PR_BRANCH="${PR_BRANCH#refs/heads/}" else - echo "Unsupported event: $EVENT_NAME" - exit 1 + 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" cd firebolt-apis + if [ "$EVENT_NAME" == "repository_dispatch" ]; then + # If OPENRPC_PR_BRANCH is set and is not 'next' + if [ -n "$OPENRPC_PR_BRANCH" ] && [ "$OPENRPC_PR_BRANCH" != "next" ]; then + echo "Updating OpenRPC dependency to branch: $OPENRPC_PR_BRANCH" + jq ".dependencies[\"@firebolt-js/openrpc\"] = \"file:../firebolt-openrpc#$OPENRPC_PR_BRANCH\"" package.json > package.json.tmp && mv package.json.tmp package.json + fi + fi npm i npm run compile npm run dist @@ -64,7 +92,7 @@ function runTests(){ const fs = require("fs"); (async () => { const browser = await puppeteer.launch({ headless: true, args: ["--no-sandbox", "--disable-gpu"] }); - const page = await browser.newPage(); + const page = await browser.newPage(); // Enable console logging page.on("console", (msg) => {