Skip to content

Commit

Permalink
MOEN-32286: Updated with base branch
Browse files Browse the repository at this point in the history
  • Loading branch information
RakshithaAcharya committed Aug 2, 2024
2 parents 697f8f0 + 40211e5 commit ced0a25
Show file tree
Hide file tree
Showing 45 changed files with 612 additions and 148 deletions.
66 changes: 66 additions & 0 deletions .github/scripts/common-utils.main.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env kotlin

import java.io.BufferedReader
import java.io.File
import java.io.InputStreamReader

private val pluginsPath = setOf(
"/sdk/cards",
"/sdk/core",
"/sdk/geofence",
"/sdk/inbox"
)

/**
* Executes the provided command in working directory on the bash shell.
*/
fun executeCommandOnShell(command: String): Int {
val process = ProcessBuilder("/bin/bash", "-c", command).inheritIO().start()
return process.waitFor()
}

/**
* Executes the provided command in given directory on the bash shell.
*/
fun executeCommandOnShell(directory: String, command: String): Int {
val process = ProcessBuilder("/bin/bash", "-c", command).inheritIO()
.directory(File(directory)).start()
return process.waitFor()
}

/**
* Executes the given command on bash shell and returns the output as a string.
*/
fun executeShellCommandWithStringOutput(command: String): String {
val process = ProcessBuilder("/bin/bash", "-c", command).start()
val reader = BufferedReader(InputStreamReader(process.inputStream))
var line: String?
val builder = StringBuilder()
while (reader.readLine().also { line = it } != null) {
builder.append(line).append(System.getProperty("line.separator"))
}
return builder.toString().trim()
}

/**
* Returns all the plugins list
*/
fun getAllPluginsPath(): Set<String> = pluginsPath

/**
* Returns the install-local command to install all plugins into sampleapp directory
*/
fun getInstallLocalCommand(): String {
var command = "install-local "
pluginsPath.forEach { module ->
command += "../$module "
}
return command
}

/**
* Create the local.properties file in given directory
*/
fun createLocalPropertiesFile(directory: String) {
executeCommandOnShell(directory, "echo moengageAppId=\"Dummy MoEngage Key\" >> ./local.properties")
}
11 changes: 7 additions & 4 deletions .github/scripts/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ git push origin master
latestTag=$(git describe --tags `git rev-list --tags --max-count=1`)
lastReleaseCommitId=$(git rev-parse $latestTag)
masterCommitId=$(git rev-parse master)
echo "latestTag: $latestTag"
echo "lastReleaseCommitId: $lastReleaseCommitId"
echo "masterCommitId: $masterCommitId"
echo "::notice::latestTag: $latestTag"
echo "::notice::lastReleaseCommitId: $lastReleaseCommitId"
echo "::notice::masterCommitId: $masterCommitId"
diffFiles=$(git diff --name-only $masterCommitId $lastReleaseCommitId)
filesArray=( $diffFiles )
moduleNameArray=()
Expand All @@ -28,16 +28,19 @@ do
fi
done
filteredModules=($(echo "${moduleNameArray[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' '))
echo "## Released Modules! :rocket:" >> $GITHUB_STEP_SUMMARY
for modulePath in "${filteredModules[@]}"
do
moduleName=$(cut -f 2 -d "/"<<<$modulePath)
echo "Releasing path: $modulePath name:$moduleName"
echo "::group::Releasing path: $modulePath name:$moduleName"
cd $modulePath
publishingVersion=$(node -p "require('./package.json').version")
npm publish
git tag -a $moduleName-v$publishingVersion -m "$publishingVersion"
cd $workingDir
echo "Released version: $publishingVersion for $moduleName"
echo "::endgroup::"
echo "### $moduleName: $publishingVersion" >> $GITHUB_STEP_SUMMARY
done

# push tags to remote
Expand Down
100 changes: 100 additions & 0 deletions .github/scripts/verify-plugins.main.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#!/usr/bin/env kotlin

@file:Import("common-utils.main.kts")

import kotlin.system.exitProcess

val sampleAppDirectory = "SampleApp"
val androidAppDirectory = "android"
val iOSAppDirectory = "ios"

val workingDirectory = executeShellCommandWithStringOutput("pwd")
println(workingDirectory)

/**
* Verify the react-native plugins
* Verification:
* 1. Install
* 2. Testcases
* 2. Tsc Configuration
*/
getAllPluginsPath().forEach { module ->
println("::group::Verifying: $module")
val moduleDirectory = workingDirectory + module
executeCommandOnShell(moduleDirectory, "npm install")

if (executeCommandOnShell(moduleDirectory, "npm test") != 0) {
println("::error::Test Cases Failed: $module")
exitProcess(1)
}

if (executeCommandOnShell(moduleDirectory, "tsc --noEmit") != 0) {
println("::error::Typescript Config Failed: $module")
exitProcess(1)
}

println("::notice::Verified: $module")
println("::endgroup::")
}

// SampleApp Setup
executeCommandOnShell("$workingDirectory/$sampleAppDirectory", "npm install -g install-local")
executeCommandOnShell("$workingDirectory/$sampleAppDirectory", "npm install")
executeCommandOnShell("$workingDirectory/$sampleAppDirectory", getInstallLocalCommand())
createLocalPropertiesFile("$workingDirectory/$sampleAppDirectory/$androidAppDirectory")

/**
* Verify the Android SampleApp
*/
println("::group::Verifying: SampleApp/Android")
if (executeCommandOnShell("$workingDirectory/$sampleAppDirectory/$androidAppDirectory", "./gradlew assemble") != 0) {
println("::error::Android Assemble Failed")
exitProcess(1)
}

println("::notice::Verified: SampleApp/Android")
println("::endgroup::")

/**
* Verify the iOS SampleApp
*/

println("::group::Verifying: SampleApp/iOS")

// Attempt to install CocoaPods
if (executeCommandOnShell("$workingDirectory/$sampleAppDirectory/$iOSAppDirectory", "sudo gem install cocoapods") != 0) {
println("::error::Failed to install CocoaPods")
exitProcess(1)
} else {
println("::notice::CocoaPods installed successfully")
}


// Remove Podfile Lock
val removePodfileLockResult = executeCommandOnShell("$workingDirectory/$sampleAppDirectory/$iOSAppDirectory", "rm -f Podfile.lock")
if (removePodfileLockResult != 0) {
println("::error::Failed to delete Podfile.lock")
exitProcess(1)
}

// Update the pod repository
val updateRepoResult = executeCommandOnShell("$workingDirectory/$sampleAppDirectory/$iOSAppDirectory", "pod repo update")
if (updateRepoResult != 0) {
println("::error::Failed to update pod repo")
exitProcess(1)
}

if (executeCommandOnShell("$workingDirectory/$sampleAppDirectory/$iOSAppDirectory", "NO_FLIPPER=1 pod install") != 0) {
println("::error::iOS Pod install Failed")
exitProcess(1)
}

if (executeCommandOnShell("$workingDirectory/$sampleAppDirectory/$iOSAppDirectory",
"xcodebuild -workspace SampleApp.xcworkspace " +
"-scheme SampleApp " +
"-sdk iphonesimulator") != 0) {
exitProcess(1)
}
println("::notice::Verified: SampleApp/ios")
println("::endgroup::")

39 changes: 39 additions & 0 deletions .github/workflows/pull_request_verification.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Verify Pull Request

on:
workflow_dispatch:
pull_request:
types: [ opened, reopened, ready_for_review, synchronize ]
branches: [ "development", "master" ]
jobs:
verify:
runs-on: macos-latest
if: ${{ !github.event.pull_request.draft }}
strategy:
fail-fast: false
matrix:
xcode: ["15.3"]
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 20.5.1
registry-url: 'https://registry.npmjs.org'
- name: Set up JDK
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 17
- name: Set up gradle cache
uses: gradle/gradle-build-action@v2
with:
cache-read-only: ${{ github.ref != 'refs/heads/master' && github.ref != 'refs/heads/development'}}
- name: Setup script
run: |
chmod +x .github/scripts/common-utils.main.kts
chmod +x .github/scripts/verify-plugins.main.kts
- name: Verify
run: |
kotlinc -script .github/scripts/verify-plugins.main.kts
4 changes: 3 additions & 1 deletion SampleApp/TrackEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ export class TrackEvent extends React.Component {
booked.addAttribute("price", 699);
booked.addAttribute("new_item", true);
booked.addDateAttribute("purchase_date", "2020-06-10T12:42:10Z");

booked.addAttribute("object", { "strKey": "str", "intKey": 1, "boolKey": false });
booked.addAttribute("nestedObject", { "strKey": "str", "intKey": 1, "boolKey": false, "nestedKey": { "nestedKeyStr": "str" } });
booked.addAttribute("objectJsonArray", [{ "strKey": "str", "intKey": 1, "boolKey": false}]);
ReactMoE.trackEvent("samplevent", booked);
},
},
Expand Down
Loading

0 comments on commit ced0a25

Please sign in to comment.