Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modified git hub flow to support exteranl trigger events #335

Merged
merged 12 commits into from
Oct 18, 2024
2 changes: 2 additions & 0 deletions .github/workflows/cxx-build.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
name: CXX build
on:
repository_dispatch:
types: [trigger-workflow]
workflow_dispatch:
pull_request:
branches:
Expand Down
21 changes: 15 additions & 6 deletions .github/workflows/run-standalone-mfos-tests.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,40 @@
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
steps:
- 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
Expand All @@ -33,6 +45,3 @@ jobs:
- name: Get results from report.json
run: |
./.github/workflows/utils.sh getResults



46 changes: 37 additions & 9 deletions .github/workflows/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) => {
Expand Down
Loading