Skip to content

Commit

Permalink
feat: CI support for native sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinshahfws committed Aug 26, 2024
1 parent c526525 commit f09ca71
Show file tree
Hide file tree
Showing 10 changed files with 319 additions and 126 deletions.
48 changes: 45 additions & 3 deletions .github/workflows/release-github.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:
release:
name: Release
runs-on: ubuntu-latest
container:
image: kevinshahfws/node-c:3.0
steps:
# Checkout/install project
- name: Checkout
Expand Down Expand Up @@ -64,13 +66,19 @@ jobs:
echo "NPM_DIST_TAG=test" >> $GITHUB_ENV
echo "DOCS_TAG=pr-$(node ./src/js/version.mjs branch-to-prerelease ${{ github.head_ref }})" >> $GITHUB_ENV
echo "FEATURE_BRANCH=${{ github.head_ref }}" >> $GITHUB_ENV
- name: Set file permissions
run: |
chmod -R 755 ./
chown -R $(id -u):$(id -g) ./
# Perform real (When not a PR) or dry-run (When PR) semantic-release
- name: Release mono-artifact to GitHub
if: (github.ref_name != 'main' && github.event_name != 'pull_request') || github.event_name == 'workflow_dispatch'
env:
GITHUB_TOKEN: ${{ secrets.SEMANTIC_RELEASE_BOT_PAT }} # <-- Allows semantic-release-bot to push changes to protected branches
run: npx semantic-release
DEBUG: semantic-release:*
run: |
git config --global --add safe.directory /__w/firebolt-apis/firebolt-apis
npx semantic-release
- name: Dry-run mono-artifact
if: (github.ref_name == 'main' && github.event_name != 'workflow_dispatch') || github.event_name == 'pull_request'
env:
Expand All @@ -89,13 +97,47 @@ jobs:
uses: andstor/file-existence-action@v2
with:
files: './src/sdks/core/dist/lib/firebolt.mjs'
- name: Get version from package.json
run: |
RELEASE_VERSION=$(node -p "require('./package.json').version")
echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_ENV
echo "build_cpp_source=true" >> $GITHUB_ENV
- name: Set cpp build source Condition
if: steps.check_build.outputs.files_exists == 'false' || (github.ref_name == 'main' && github.event_name != 'pull_request' && github.event_name != 'workflow_dispatch')
run: echo "build_cpp_source=false" >> $GITHUB_ENV

- name: Clone and Install Thunder
if: env.build_cpp_source == 'true'
id: install_thunder
run: |
.github/workflows/utils.sh cloneAndInstallThunder
- name: Generate native sdk source
if: env.build_cpp_source == 'true'
run: |
.github/workflows/utils.sh generateSource
- name: Build Core SDK CPP
if: env.build_cpp_source == 'true'
id: build_core_cpp
run: |
.github/workflows/utils.sh buildCoreCPPSDK $RELEASE_VERSION
- name: Build Manage SDK CPP
if: env.build_cpp_source == 'true'
id: build_manage_cpp
run: |
.github/workflows/utils.sh buildManageCPPSDK $RELEASE_VERSION
- name: Build Discovery SDK CPP
if: env.build_cpp_source == 'true'
id: build_discovery_cpp
run: |
.github/workflows/utils.sh buildDiscoveryCPPSDK $RELEASE_VERSION
- name: Release Firebolt SDKs to NPM
if: steps.check_build.outputs.files_exists == 'true' && github.event_name != 'pull_request' && (github.ref_name != 'main' || github.event_name == 'workflow_dispatch')
env:
NPM_TOKEN: ${{ secrets.SEMANTIC_RELEASE_NPM_TOKEN }} # <-- Allows semantic-release to publish to npm without 2 factor auth.
run: |
npm --version
echo "NPM DIST TAG :: " $NPM_DIST_TAG
echo "NPM DIST TAG ::: " $NPM_DIST_TAG
npm publish --tag $NPM_DIST_TAG --workspaces
- name: Dry-run Firebolt SDKs to NPM
if: steps.check_build.outputs.files_exists == 'true' && (github.ref_name == 'main' && github.event_name != 'workflow_dispatch')
Expand Down
206 changes: 206 additions & 0 deletions .github/workflows/utils.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
#!/bin/bash
set -o pipefail

FIREBOLT_VERSION=1.0.0-next.0
current_apis_dir=$(pwd)

cd ..
current_dir=$(pwd)
cd $current_apis_dir

function runTests(){
echo "Clone firebolt-apis repo with pr branch"
PR_BRANCH=$(echo "$EVENT_NAME" | tr '[:upper:]' '[:lower:]')
Expand Down Expand Up @@ -147,6 +154,195 @@ function unzipArtifact(){
echo "Failures=$failures" >> "$GITHUB_ENV"
}

function generateSource() {
echo " ************ Generating CPP SDK Source ************"

echo "Generating source for Core SDK"
cd src/sdks/core
npm run cpp

if [ $? -eq 0 ]
then
echo "Native Core SDK generated successfully"
echo " Core SDK Location"
cd build/cpp/src/
ls -la
echo " ************ Source Generation Completed for Core SDK ************"
else
echo "Native Core SDK generation failed"
exit 1
fi

echo "Generating source for Manage SDK"
cd ../../../../manage
npm run cpp

if [ $? -eq 0 ]
then
echo "Native Manage SDK generated successfully"
echo " Manage SDK Location"
cd build/cpp/src/
ls -la
echo " ************ Source Generation Completed for Manage SDK ************"
else
echo "Native Manage SDK generation failed"
exit 1
fi

echo "Generate source for Discovery SDK"
cd ../discovery
npm run cpp

if [ $? -eq 0 ]
then
echo "Native Discovery SDK generated successfully"
else
echo "Native Discovery SDK generation failed"
exit 1
fi
}

function cloneAndInstallThunder() {
cd ..

git clone https://github.com/rdkcentral/Thunder.git

cd Thunder

git checkout 283b3d54334010403d85a4e69b3835de23e42331

cd ..

git clone https://github.com/rdkcentral/ThunderTools.git

cd ThunderTools

git checkout 64b72b5ed491436b0e6bc2327d8a7b0e75ee2870

cd ..

echo "current_dir is $current_dir"

mkdir -p $current_dir/data

if [ ! -d "$(pwd)/Thunder" ]
then
echo "Directory Thunder DOES NOT exist."
exit 9999
fi

if [ ! -d "$(pwd)/ThunderTools" ]
then
echo "Directory ThunderTools DOES NOT exist."
exit 9999
fi

if [ ! -d "$current_dir/firebolt-apis" ]
then
echo "Directory $current_dir/firebolt-apis DOES NOT exist."
exit 9999
fi

cd $current_dir

[ -d "$current_dir/build" ] && rm -rf $current_dir/build

echo "Building Thunder";

cmake -G Ninja -S ThunderTools -B build/ThunderTools -DCMAKE_INSTALL_PREFIX="install/usr" && echo "Tools Setup" || exit 9999

cmake --build build/ThunderTools --target install && echo "Thunder Tools Build succeeded" || exit 9999

#-G Ninja is the "Build system generator"
#-S is the source path
#-B is the output directory
cmake -G Ninja -S Thunder -B build/Thunder \
-DBUILD_SHARED_LIBS=ON \
-DBINDING="127.0.0.1" \
-DCMAKE_BUILD_TYPE="Debug" \
-DCMAKE_INSTALL_PREFIX="install/usr" \
-DCMAKE_MODULE_PATH="${PWD}/install/usr/include/WPEFramework/Modules" \
-DDATA_PATH="${PWD}/install/usr/share/WPEFramework" \
-DPERSISTENT_PATH="${PWD}/install/var/wpeframework" \
-DPORT="55555" \
-DPROXYSTUB_PATH="${PWD}/install/usr/lib/wpeframework/proxystubs" \
-DSYSTEM_PATH="${PWD}/install/usr/lib/wpeframework/plugins" \
-DVOLATILE_PATH="tmp" && echo "Thunder configure succeeded" || exit 9999

cmake --build build/Thunder --target install && echo "Thunder Build succeeded" || exit 9999
}

function buildCoreCPPSDK() {
echo " ************ Building Core CPP SDK ************"

FIREBOLT_VERSION=$(node -p "require('./package.json').version")
echo "The version from package.json is $FIREBOLT_VERSION"

cd src/sdks/core
ls -la build/cpp/src
cp build/cpp/src/firebolt-core-native-sdk-${FIREBOLT_VERSION}.tgz $current_dir/data
cd $current_dir/data
tar -zxvf firebolt-core-native-sdk-${FIREBOLT_VERSION}.tgz
cd firebolt-core-native-sdk-${FIREBOLT_VERSION}/
chmod +x ./build.sh
sed -i -e 's/prefix=/prefix /g' build.sh
cat ./build.sh

echo "***************** firebolt.h *****************"
cat include/firebolt.h

./build.sh -s "$current_dir/install" || exit 9999
./build.sh -f "$current_dir/data/firebolt-core-native-sdk-${FIREBOLT_VERSION}/build/Firebolt" -s "$current_dir/install"

cd $current_apis_dir
}

function buildManageCPPSDK() {
echo " ************ Build Manage CPP SDK ************"
FIREBOLT_VERSION=$(node -p "require('./package.json').version")
echo "The version from package.json is $FIREBOLT_VERSION"

cd $current_apis_dir
cd src/sdks/manage
ls -la build/cpp/src
cp build/cpp/src/firebolt-manage-native-sdk-${FIREBOLT_VERSION}.tgz $current_dir/data
cd $current_dir/data
tar -zxvf firebolt-manage-native-sdk-${FIREBOLT_VERSION}.tgz
cd firebolt-manage-native-sdk-${FIREBOLT_VERSION}/
chmod +x ./build.sh
sed -i -e 's/prefix=/prefix /g' build.sh
cat ./build.sh

echo "***************** firebolt.h *****************"
cat include/firebolt.h

./build.sh -s "$current_dir/install" || exit 9999
./build.sh -f "$current_dir/data/firebolt-manage-native-sdk-${FIREBOLT_VERSION}/build/Firebolt" -s "$current_dir/install"
}

function buildDiscoveryCPPSDK() {
echo " ************ Build Discovery CPP SDK ************"
FIREBOLT_VERSION=$(node -p "require('./package.json').version")
echo "The version from package.json is $FIREBOLT_VERSION"

cd $current_apis_dir
cd src/sdks/discovery
ls -la build/cpp/src
cp build/cpp/src/firebolt-discovery-native-sdk-${FIREBOLT_VERSION}.tgz $current_dir/data
cd $current_dir/data
tar -zxvf firebolt-discovery-native-sdk-${FIREBOLT_VERSION}.tgz
cd firebolt-discovery-native-sdk-${FIREBOLT_VERSION}/
chmod +x ./build.sh
sed -i -e 's/prefix=/prefix /g' build.sh
cat ./build.sh

echo "***************** firebolt.h *****************"
cat include/firebolt.h

./build.sh -s "$current_dir/install" || exit 9999
./build.sh -f "$current_dir/data/firebolt-discovery-native-sdk-${FIREBOLT_VERSION}/build/Firebolt" -s "$current_dir/install"
}

# Check argument and call corresponding function
if [ "$1" == "runTests" ]; then
runTests
Expand All @@ -156,6 +352,16 @@ elif [ "$1" == "getArtifactData" ]; then
getArtifactData
elif [ "$1" == "unzipArtifact" ]; then
unzipArtifact
elif [ "$1" == "generateSource" ]; then
generateSource
elif [ "$1" == "cloneAndInstallThunder" ]; then
cloneAndInstallThunder
elif [ "$1" == "buildCoreCPPSDK" ]; then
buildCoreCPPSDK
elif [ "$1" == "buildManageCPPSDK" ]; then
buildManageCPPSDK
elif [ "$1" == "buildDiscoveryCPPSDK" ]; then
buildDiscoveryCPPSDK
else
echo "Invalid function specified."
exit 1
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"devDependencies": {
"@commitlint/cli": "^17.0.3",
"@commitlint/config-conventional": "^17.0.3",
"@firebolt-js/openrpc": "3.1.1-next.2",
"@firebolt-js/openrpc": "rdkcentral/firebolt-openrpc#fix-safe-name-issue",
"@firebolt-js/schemas": "2.0.0",
"@saithodev/semantic-release-backmerge": "^3.2.0",
"@semantic-release/changelog": "^6.0.1",
Expand Down
Loading

0 comments on commit f09ca71

Please sign in to comment.