From 64b67e099d96c816de88501827fd29845e462dd9 Mon Sep 17 00:00:00 2001 From: "Kandasamy, Divya" Date: Thu, 19 Sep 2024 13:48:38 -0400 Subject: [PATCH] Added --- .../workflows/run-standalone-mfos-tests.yml | 66 +--- .github/workflows/utils.sh | 367 ++---------------- 2 files changed, 43 insertions(+), 390 deletions(-) diff --git a/.github/workflows/run-standalone-mfos-tests.yml b/.github/workflows/run-standalone-mfos-tests.yml index 0dbd0ae4c..dd4b0eced 100644 --- a/.github/workflows/run-standalone-mfos-tests.yml +++ b/.github/workflows/run-standalone-mfos-tests.yml @@ -14,37 +14,16 @@ jobs: - name: Checkout uses: actions/checkout@v2 - - #Run Core tests - - name: Run Core tests and create assets + #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: ${{ secrets.INTENT }} + INTENT: ${{ var.INTENT }} run: | ./.github/workflows/utils.sh runTests - # Run Manage tests - # - name: Run Manage tests and create assets - # env: - # EVENT_NAME: ${{ github.event_name }} - # GITHUB_REF: ${{ github.ref }} - # PR_HEAD_REF: ${{ github.event.pull_request.head.ref }} - # INTENT: ${{ secrets.INTENT }} - # run: | - # ./.github/workflows/utils.sh runTests manage - - - - - # - name: Compress all reports - # run: | - # mkdir -p ${{ github.workspace }}/combined-reports - # cp ${{ github.workspace }}/report/core/report.json ${{ github.workspace }}/combined-reports/core-report.json - # cp ${{ github.workspace }}/report/manage/report.json ${{ github.workspace }}/combined-reports/manage-report.json - # tar -czvf combined-reports.tar.gz -C ${{ github.workspace }}/combined-reports . - - name: Upload report.json as an artifact uses: actions/upload-artifact@v4 with: @@ -56,41 +35,4 @@ jobs: ./.github/workflows/utils.sh getResults - # # Upload Core report as an artifact - # - name: Upload Core report.json as an artifact - # uses: actions/upload-artifact@v4 - # with: - # name: core-report - # path: ${{ github.workspace }}/report/core-report.json - - # # Get results from Core report.json - # - name: Get results from Core report.json - # run: | - # ./.github/workflows/utils.sh getResults - - - - # # Upload Manage report as an artifact - # - name: Upload Manage report.json as an artifact - # uses: actions/upload-artifact@v4 - # with: - # name: manage-report - # path: ${{ github.workspace }}/report/manage-report.json - - # # Get results from Manage report.json - # - name: Get results from Manage report.json - # run: | - # ./.github/workflows/utils.sh getResults - - - # # Upload Discovery report as an artifact - # - name: Upload Discovery report.json as an artifact - # uses: actions/upload-artifact@v4 - # with: - # name: discovery-report - # path: ${{ github.workspace }}/report/discovery-report.json - - # # Get results from Discovery report.json - # - name: Get results from Discovery report.json - # run: | - # ./.github/workflows/utils.sh getResults \ No newline at end of file + \ No newline at end of file diff --git a/.github/workflows/utils.sh b/.github/workflows/utils.sh index ee9c7a4ce..d6175fb9a 100755 --- a/.github/workflows/utils.sh +++ b/.github/workflows/utils.sh @@ -1,289 +1,55 @@ #!/bin/bash set -o pipefail -# function runTests(){ -# MODULE="$1" # Pass the module name (core, manage, discovery) - -# echo "Clone firebolt-apis repo with pr branch" -# 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/}" -# else -# echo "Unsupported event: $EVENT_NAME" -# exit 1 -# fi - -# 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 -# npm i -# npm run compile -# npm run dist -# cd .. - -# echo "clone mfos repo and start it in the background" -# git clone https://github.com/rdkcentral/mock-firebolt.git -# cd mock-firebolt/server -# cp ../../firebolt-apis/dist/firebolt-open-rpc.json ../../mock-firebolt/server/src/firebolt-open-rpc.json -# jq 'del(.supportedOpenRPCs[] | select(.name == "core"))' src/.mf.config.SAMPLE.json > src/.mf.config.SAMPLE.json.tmp && mv src/.mf.config.SAMPLE.json.tmp src/.mf.config.SAMPLE.json -# jq '.supportedOpenRPCs += [{"name": "core","cliFlag": null,"cliShortFlag": null,"fileName": "firebolt-open-rpc.json","enabled": true}]' src/.mf.config.SAMPLE.json > src/.mf.config.SAMPLE.json.tmp && mv src/.mf.config.SAMPLE.json.tmp src/.mf.config.SAMPLE.json -# cp src/.mf.config.SAMPLE.json src/.mf.config.json -# npm install -# npm start & -# cd ..//.. - -# echo "clone fca repo and start it in the background" -# git clone --branch main https://github.com/rdkcentral/firebolt-certification-app.git -# cd firebolt-certification-app - -# if [ "$MODULE" == "manage" ]; then -# echo "Updating dependency to Manage SDK" -# jq '.dependencies["@firebolt-js/sdk"] = "file:../firebolt-apis/src/sdks/manage"' package.json > package.json.tmp && mv package.json.tmp package.json -# elif [ "$MODULE" == "discovery" ]; then -# echo "Updating dependency to Discovery SDK" -# jq '.dependencies["@firebolt-js/sdk"] = "file:../firebolt-apis/src/sdks/discovery"' package.json > package.json.tmp && mv package.json.tmp package.json -# else -# echo "Running Core by default" -# jq '.dependencies["@firebolt-js/sdk"] = "file:../firebolt-apis/src/sdks/core"' package.json > package.json.tmp && mv package.json.tmp package.json -# fi - -# npm install -# npm start & -# sleep 5s -# cd .. - -# echo "curl request with runTest install on initialization" -# response=$(curl -X POST -H "Content-Type: application/json" -d "$INTENT" http://localhost:3333/api/v1/state/method/parameters.initialization/result) - -# echo "run mfos tests in a headless browser" -# npm install puppeteer -# echo "Start xvfb" -# Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 & -# export DISPLAY=:99 - -# echo "Run headless browser script with puppeteer" -# node -e ' -# const puppeteer = require("puppeteer"); -# const fs = require("fs"); -# (async () => { -# const browser = await puppeteer.launch({ headless: true, args: ["--no-sandbox", "--disable-gpu"] }); -# const page = await browser.newPage(); - -# // Enable console logging -# page.on("console", (msg) => { -# let logMessage=""; -# if (msg.type().includes("log")) { -# logMessage = `${msg.text()}`; -# console.log(logMessage); -# } -# if (logMessage.includes("Response String:")) { -# const jsonStringMatch = logMessage.match(/Response String:(.*)/); -# if (jsonStringMatch && jsonStringMatch[1]) { -# try { -# const jsonString = jsonStringMatch[1].trim(); -# const responseString = JSON.parse(jsonString); -# console.log("Parsed JSON:", responseString); -# const filePath="report.json" -# fs.writeFileSync(filePath, JSON.stringify(responseString), "utf-8"); -# console.log(`Parsed JSON written to ${filePath}`); -# // Exit the Node.js script -# process.exit(0); - -# } catch (error) { -# console.error("Error parsing JSON:", error); -# } -# } -# } -# }); -# // Navigate to the URL -# await page.goto("http://localhost:8081/?mf=ws://localhost:9998/12345&standalone=true"); - -# // Sleep for 80 seconds (80,000 milliseconds) -# await new Promise(resolve => setTimeout(resolve, 80000)); - -# // Close the browser -# await browser.close(); -# })(); -# ' -# echo "Create HTML and JSON assets for ${MODULE}" -# npm i mochawesome-report-generator -# echo $MODULE -# echo "report/$MODULE" -# echo "report/${MODULE}" -# mkdir -p report/$MODULE -# # Move the report.json to the correct location -# if [ -f report.json ]; then -# mv report.json report/$MODULE/ -# else -# echo "report.json not found for $MODULE" -# exit 1 -# fi - -# # Check if the module directory exists -# if [ ! -d report/$MODULE ]; then -# echo "Module directory report/$MODULE does not exist." -# exit 1 -# fi - -# # Debugging output to see the directory contents -# ls -ltr report/$MODULE/ - -# # Process report.json -# echo "HELLO" -# # Check if the module directory exists -# echo "Checking if directory report/${MODULE} exists" -# if [ ! -d report/${MODULE} ]; then -# echo "Module directory report/${MODULE} does not exist." -# exit 1 -# fi - -# # Now check for the report.json file in the correct directory -# echo "Checking for report.json at report/${MODULE}/report.json" -# if [ -f report/${MODULE}/report.json ]; then -# echo "Found report.json" -# jq -r '.' report/${MODULE}/report.json > tmp.json && mv tmp.json report/${MODULE}/report.json -# jq '.report' report/${MODULE}/report.json > tmp.json && mv tmp.json report/${MODULE}/report.json -# else -# echo "report.json not found at report/${MODULE}/report.json" -# exit 1 -# fi -# echo "Checking for report generator" - -# node -e " -# const marge = require('mochawesome-report-generator/bin/cli-main'); -# marge({ -# _: ['report/${MODULE}/report.json'], -# reportFileName: 'report.json', -# reportTitle: 'FireboltCertificationTestReport', -# reportPageTitle: 'FireboltCertificationTestReport', -# reportDir: './report/${MODULE}', -# }); -# " -# } - -function check_port() { - local PORT=$1 - # Check if port is in use - if lsof -i :$PORT > /dev/null; then - echo "Port $PORT is already in use" - # Kill the process using the port - PID=$(lsof -t -i :$PORT) - if [ ! -z "$PID" ]; then - echo "Killing process $PID using port $PORT" - kill -9 $PID - echo "Port $PORT is now free" - fi - else - echo "Port $PORT is available" - fi -} - function runTests(){ - # MODULE="$1" # Pass the module name - - # Clone firebolt-apis repo if it doesn't already exist - # if [ ! -d "firebolt-apis" ]; then - echo "Clone firebolt-apis repo with PR branch" - 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/}" - else - echo "Unsupported event: $EVENT_NAME" - exit 1 - fi - - 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 - npm i - npm run compile - npm run dist - cd .. - # else - # echo "firebolt-apis repo already exists. Skipping clone." - # fi - - # Clone mock-firebolt repo if it doesn't already exist - if [ ! -d "mock-firebolt" ]; then - echo "Cloning mfos repo and start it in the background" - git clone https://github.com/rdkcentral/mock-firebolt.git - cd mock-firebolt/server - cp ../../firebolt-apis/dist/firebolt-open-rpc.json ../../mock-firebolt/server/src/firebolt-open-rpc.json - # jq --arg MODULE "$MODULE" 'del(.supportedOpenRPCs[] | select(.name == $MODULE))' src/.mf.config.SAMPLE.json > src/.mf.config.SAMPLE.json.tmp && mv src/.mf.config.SAMPLE.json.tmp src/.mf.config.SAMPLE.json - # jq --arg MODULE "$MODULE" '.supportedOpenRPCs += [{"name": $MODULE, "cliFlag": null, "cliShortFlag": null, "fileName": "firebolt-open-rpc.json", "enabled": true}]' src/.mf.config.SAMPLE.json > src/.mf.config.SAMPLE.json.tmp && mv src/.mf.config.SAMPLE.json.tmp src/.mf.config.SAMPLE.json - jq 'del(.supportedOpenRPCs[] | select(.name == "core"))' src/.mf.config.SAMPLE.json > src/.mf.config.SAMPLE.json.tmp && mv src/.mf.config.SAMPLE.json.tmp src/.mf.config.SAMPLE.json - jq '.supportedOpenRPCs += [{"name": "core","cliFlag": null,"cliShortFlag": null,"fileName": "firebolt-open-rpc.json","enabled": true}]' src/.mf.config.SAMPLE.json > src/.mf.config.SAMPLE.json.tmp && mv src/.mf.config.SAMPLE.json.tmp src/.mf.config.SAMPLE.json - cp src/.mf.config.SAMPLE.json src/.mf.config.json - npm install - npm start & - cd ../.. + echo "Clone firebolt-apis repo with pr branch" + 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/}" else - echo "mock-firebolt repo already exists. Skipping clone." + echo "Unsupported event: $EVENT_NAME" + exit 1 fi - # Clone Firebolt Certification App (FCA) if it doesn't exist - # if [ ! -d "firebolt-certification-app" ]; then - echo "Clone FCA repo" - git clone --branch main https://github.com/rdkcentral/firebolt-certification-app.git - # fi - - echo "Updating dependency for ${MODULE} in FCA" - cd firebolt-certification-app + 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 + npm i + npm run compile + npm run dist + cd .. - # check_port 8081 - - # if [ "$MODULE" == "manage" ]; then - echo "Updating dependency to Manage SDK" - jq '.dependencies["@firebolt-js/manage-sdk"] = "file:../firebolt-apis/src/sdks/manage"' package.json > package.json.tmp && mv package.json.tmp package.json - # elif [ "$MODULE" == "discovery" ]; then - echo "Updating dependency to Discovery SDK" - jq '.dependencies["@firebolt-js/discovery-sdk"] = "file:../firebolt-apis/src/sdks/discovery"' package.json > package.json.tmp && mv package.json.tmp package.json - # else - echo "Running Core by default" - jq '.dependencies["@firebolt-js/sdk"] = "file:../firebolt-apis/src/sdks/core"' package.json > package.json.tmp && mv package.json.tmp package.json -# fi + echo "clone mfos repo and start it in the background" + git clone https://github.com/rdkcentral/mock-firebolt.git + cd mock-firebolt/server + cp ../../firebolt-apis/dist/firebolt-open-rpc.json ../../mock-firebolt/server/src/firebolt-open-rpc.json + jq 'del(.supportedOpenRPCs[] | select(.name == "core"))' src/.mf.config.SAMPLE.json > src/.mf.config.SAMPLE.json.tmp && mv src/.mf.config.SAMPLE.json.tmp src/.mf.config.SAMPLE.json + jq '.supportedOpenRPCs += [{"name": "core","cliFlag": null,"cliShortFlag": null,"fileName": "firebolt-open-rpc.json","enabled": true}]' src/.mf.config.SAMPLE.json > src/.mf.config.SAMPLE.json.tmp && mv src/.mf.config.SAMPLE.json.tmp src/.mf.config.SAMPLE.json + cp src/.mf.config.SAMPLE.json src/.mf.config.json + npm install + npm start & + cd ..//.. + echo "clone fca repo and start it in the background" + git clone --branch main https://github.com/rdkcentral/firebolt-certification-app.git + cd firebolt-certification-app + echo "Updating Core SDK dependency" + jq '.dependencies["@firebolt-js/sdk"] = "file:../firebolt-apis/src/sdks/core"' package.json > package.json.tmp && mv package.json.tmp package.json + echo "Updating Manage SDK dependency" + jq '.dependencies["@firebolt-js/manage-sdk"] = "file:../firebolt-apis/src/sdks/manage"' package.json > package.json.tmp && mv package.json.tmp package.json + echo "Updating Discovery SDK dependency" + jq '.dependencies["@firebolt-js/discovery-sdk"] = "file:../firebolt-apis/src/sdks/discovery"' package.json > package.json.tmp && mv package.json.tmp package.json npm install npm start & sleep 5s cd .. - #Define the INTENT1 variable correctly -INTENT1=$(cat < tmp.json && mv tmp.json report/${MODULE}/report.json -# jq '.report' report/${MODULE}/report.json > tmp.json && mv tmp.json report/${MODULE}/report.json -# else -# echo "report.json not found at report/${MODULE}/report.json" -# exit 1 -# fi -# echo "Checking for report generator" - -# node -e " -# const marge = require('mochawesome-report-generator/bin/cli-main'); -# marge({ -# _: ['report/${MODULE}/report.json'], -# reportFileName: 'report.json', -# reportTitle: 'FireboltCertificationTestReport', -# reportPageTitle: 'FireboltCertificationTestReport', -# reportDir: './report/${MODULE}', -# }); -# " -# } - echo "create html and json assets" + echo "create html and json assets" npm i mochawesome-report-generator mkdir report mv report.json report/