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

TestApp build with CodeQL analysis #1052

Open
wants to merge 74 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 70 commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
8d11dc8
create yaml for build demo app
MikhailSuendukov Oct 1, 2024
1913772
fix script path
MikhailSuendukov Oct 2, 2024
4ceb4f1
remove npm install node-gyp
MikhailSuendukov Oct 2, 2024
f414a1a
install watchman
MikhailSuendukov Oct 2, 2024
ed3eebd
add gradleWrapperFile directory
MikhailSuendukov Oct 2, 2024
83276db
use java 7
MikhailSuendukov Oct 2, 2024
be9d723
fix "use java"
MikhailSuendukov Oct 2, 2024
15ae409
fix typo
MikhailSuendukov Oct 2, 2024
6bb803d
use PreInstalled JDK
MikhailSuendukov Oct 2, 2024
8ce2f62
dont bundle before gradle assembling
MikhailSuendukov Oct 3, 2024
cbdd973
appComponentFactory tools replace for DemoApp
MikhailSuendukov Oct 3, 2024
605be68
add tools namespace
MikhailSuendukov Oct 3, 2024
9998b09
use AGP 7.2
MikhailSuendukov Oct 3, 2024
91d6220
revert "use AGP 7.2"
MikhailSuendukov Oct 3, 2024
ed57da6
use ndk 20.1.5948944
MikhailSuendukov Oct 3, 2024
af5ce84
revert "use ndk 20.1.5948944"
MikhailSuendukov Oct 3, 2024
5ec2925
use AGP 7.0
MikhailSuendukov Oct 3, 2024
5ba8566
install @react-native-async-storage/async-storage@latest
MikhailSuendukov Oct 3, 2024
126202f
implement use-android-manifest-namespaces.sh for DemoApp
MikhailSuendukov Oct 4, 2024
e8620a3
Run Use-android-manifest-namespaces script
MikhailSuendukov Oct 4, 2024
151ff46
fix typo
MikhailSuendukov Oct 4, 2024
85d7064
use gradle 4.2.2
MikhailSuendukov Oct 7, 2024
faed0e7
use agp 6.1.1
MikhailSuendukov Oct 7, 2024
7f28aa8
#include <cstdlib> to TestApp cpp file
MikhailSuendukov Oct 8, 2024
aa42ed0
add versionName to build.gradle
MikhailSuendukov Oct 8, 2024
f54c552
update scripts
MikhailSuendukov Oct 8, 2024
35f474b
build testapp via pipeline
MikhailSuendukov Oct 8, 2024
dabe08e
use node 14
MikhailSuendukov Oct 8, 2024
4ba8d2b
use workaround for macs on arm64 for update npm packages script
MikhailSuendukov Oct 8, 2024
97a5607
temp comment pod install (revert before merge)
MikhailSuendukov Oct 8, 2024
3e84439
use ndk 16.1.4479499
MikhailSuendukov Oct 8, 2024
1558271
add comment for Removing versionName and versionCode from build.gradle
MikhailSuendukov Oct 9, 2024
fc31110
revert "use ndk 16.1.4479499"
MikhailSuendukov Oct 9, 2024
2c2a0e9
remove unused ndks before TestApp build
MikhailSuendukov Oct 9, 2024
444b67a
use ndk 20.0.5594570
MikhailSuendukov Oct 9, 2024
4dd19e8
fix typo
MikhailSuendukov Oct 9, 2024
67d1dd3
use use-ndk-version script
MikhailSuendukov Oct 9, 2024
cf53d53
fix typo
MikhailSuendukov Oct 9, 2024
b5eaec9
fix script
MikhailSuendukov Oct 9, 2024
8268735
implement install-ndk-version script
MikhailSuendukov Oct 9, 2024
a2c7a12
improve install-ndk-version script
MikhailSuendukov Oct 9, 2024
a0c3229
try to set ndk without install
MikhailSuendukov Oct 10, 2024
5eb9659
fix typo
MikhailSuendukov Oct 10, 2024
4c65d3a
show all founded versions
MikhailSuendukov Oct 10, 2024
28deb70
rever DemoApp changes
MikhailSuendukov Oct 10, 2024
87354d9
download and install NDK 20
MikhailSuendukov Oct 10, 2024
5adde5c
rename test app build config
MikhailSuendukov Oct 10, 2024
404d212
try to add repo manually
MikhailSuendukov Oct 11, 2024
c472651
Download .npmrc
MikhailSuendukov Oct 11, 2024
b17c6ea
revert "try to add repo manually"
MikhailSuendukov Oct 11, 2024
b753587
revert "Download .npmrc"
MikhailSuendukov Oct 11, 2024
be78e0f
Download ExportOptions
MikhailSuendukov Oct 11, 2024
dac4c35
remove AppCenterSDK-Specs-Private source from TestApp
MikhailSuendukov Oct 11, 2024
e471a32
revert "Download ExportOptions"
MikhailSuendukov Oct 14, 2024
ca2715c
fix set-ndk-version
MikhailSuendukov Oct 14, 2024
8edc6c8
refactor update-npm-packages script
MikhailSuendukov Oct 14, 2024
d5fc67b
remove version name from build.gradle file
MikhailSuendukov Oct 14, 2024
3484193
check macos architecture
MikhailSuendukov Oct 14, 2024
8caa2a3
uncoment "source 'https://msmobilecenter.visualstudio.com/SDK/_git/A…
MikhailSuendukov Oct 15, 2024
ef1af7c
improve macos arm64 check
MikhailSuendukov Oct 15, 2024
4ce6329
revert "#include <cstdlib> to TestApp cpp file"
MikhailSuendukov Oct 24, 2024
6cc0b8e
polish install-ndk-version.sh script
MikhailSuendukov Oct 24, 2024
8c82daf
declare ANDROID_NDK_HOME in install-ndk-version.sh script
MikhailSuendukov Oct 24, 2024
050e1f9
polish update-npm-packages.sh script
MikhailSuendukov Oct 24, 2024
c512730
remove "Install watchman" step
MikhailSuendukov Oct 24, 2024
e14547b
improve platform recognition
MikhailSuendukov Oct 25, 2024
957e319
remove cadence
MikhailSuendukov Oct 28, 2024
14a90fc
add versionName to TestApp build.gradle
MikhailSuendukov Oct 28, 2024
7901c76
remove versionName from TestApp build.gradle
MikhailSuendukov Oct 28, 2024
b49ed17
uncoment removing lines
MikhailSuendukov Oct 29, 2024
e12eeee
Remove setting up a specific node version
DmitriyKirakosyan Nov 12, 2024
eddf276
use node 18
DmitriyKirakosyan Nov 12, 2024
1d2cf7e
use node 20
DmitriyKirakosyan Nov 12, 2024
e5f6534
use node 16
DmitriyKirakosyan Nov 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions .azurepipelines/build-test-app-android.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
pr:
- master

pool:
vmImage: macos-latest

jobs:
- job:
displayName: Build and CodeQL TestApp Android
steps:
- checkout: self
submodules: recursive

- task: CodeQL3000Init@0
displayName: CodeQL Initialize

- task: NodeTool@0
displayName: 'Use Node 14.x'
lucen-ms marked this conversation as resolved.
Show resolved Hide resolved
inputs:
versionSpec: 14.x

- task: JavaToolInstaller@0
inputs:
versionSpec: '11'
jdkArchitectureOption: 'x64'
jdkSourceOption: 'PreInstalled'
displayName: 'Use Java 11'

- task: Bash@3
displayName: Run update-npm-packages script
inputs:
filePath: TestApp/update-npm-packages.sh
arguments: "android"
workingDirectory: TestApp

- task: Bash@3
displayName: Run install-ndk-version script
inputs:
filePath: TestApp/install-ndk-version.sh
arguments: "20"
workingDirectory: TestApp

- task: Bash@3
displayName: Run set-ndk-version script
inputs:
filePath: TestApp/set-ndk-version.sh
workingDirectory: TestApp

- task: Gradle@3
displayName: Build TestApp
inputs:
gradleWrapperFile: TestApp/android/gradlew
workingDirectory: TestApp/android
tasks: assembleRelease
publishJUnitResults: false

- task: CodeQL3000Finalize@0
displayName: CodeQL Finalize
38 changes: 38 additions & 0 deletions TestApp/install-ndk-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

# Download and install the specified version of the Android NDK

# Check if the NDK_MAJOR_VERSION argument is provided
if [ -z "$1" ]; then
echo "NDK version is not provided"
return 1
fi

# Check if ANDROID_HOME is defined
if [ -z "$ANDROID_HOME" ]; then
echo "ANDROID_HOME is not defined"
return 1
fi

NDK_MAJOR_VERSION="$1"
ANDROID_NDK_HOME="$ANDROID_HOME/ndk-bundle"

# Download the specified version of the Android NDK
echo "Download Android NDK version $NDK_MAJOR_VERSION"
curl -o android-ndk-r$NDK_MAJOR_VERSION-darwin-x86_64.zip https://dl.google.com/android/repository/android-ndk-r$NDK_MAJOR_VERSION-darwin-x86_64.zip

# Unzip the downloaded NDK zip file into a directory
unzip android-ndk-r$NDK_MAJOR_VERSION-darwin-x86_64.zip -d android-ndk-r$NDK_MAJOR_VERSION

# Remove any existing NDK installation in ANDROID_HOME/ndk-bundle and replace it with the downloaded one
echo "Copy NDK to $ANDROID_NDK_HOME"
rm -rf $ANDROID_NDK_HOME
cp -r ./android-ndk-r$NDK_MAJOR_VERSION/android-ndk-r$NDK_MAJOR_VERSION $ANDROID_NDK_HOME

# Clean up by removing the unzipped files and the downloaded zip file
rm -rf android-ndk-r$NDK_MAJOR_VERSION android-ndk-r$NDK_MAJOR_VERSION-darwin-x86_64.zip

echo "NDK $NDK_MAJOR_VERSION is installed to $ANDROID_NDK_HOME"
23 changes: 23 additions & 0 deletions TestApp/set-ndk-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

# Set the NDK version in the android section of the build.gradle file.

PROPERTY_FILE="$ANDROID_HOME/ndk-bundle/source.properties"
DmitriyKirakosyan marked this conversation as resolved.
Show resolved Hide resolved

echo "Reading ndk version from source.properties file..."
VERSION=$(cat $PROPERTY_FILE | sed 's/ //g' | grep "Pkg.Revision" | cut -d'=' -f2)
echo $VERSION

GRADLE_FILE="./android/app/build.gradle"

if [ -z $VERSION ]; then
echo "No NDK found in the default location. Proceeding..."
else

# Insert ndkVersion = 'x.x.x' in the android section.
NDK_VERSION_LINE="ndkVersion = '$VERSION'"
echo "$(sed "s/android {/android {\\`echo -e '\n\r '`$NDK_VERSION_LINE/g" "$GRADLE_FILE")" > $GRADLE_FILE
fi
58 changes: 40 additions & 18 deletions TestApp/update-npm-packages.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/bin/bash

# Update AppCenter npm packages for the TestApp

set -e

echo 'Removing existing appcenter* packages...'
Expand All @@ -13,32 +16,51 @@ npm pack ../appcenter-link-scripts
echo "Installing appcenter* packages..."
npm install appcenter*.tgz

echo "workaround for macs on arm64"
npm install react-native-fs --save --legacy-peer-deps

echo "Cleanup appcenter*.tgz"
rm appcenter*.tgz

echo "Installing other packages..."
npm install

# Issue: https://github.com/react-native-community/cli/issues/1403
# Fixed in RN 0.65: https://github.com/facebook/react-native/commit/8721ee0a6b10e5bc8a5a95809aaa7b25dd5a6043
echo "Applying patch to react-native package that fixes build on Xcode 12.5..."
npx patch-package
if [ -z "$1" ] || [ "$1" == "ios" ]; then
if [[ "$OSTYPE" == "darwin"* && "$(uname -m)" == "arm64" ]]; then
echo "Workaround for macs on arm64"
npm install react-native-fs --save --legacy-peer-deps
MikhailSuendukov marked this conversation as resolved.
Show resolved Hide resolved
fi

echo "Install shared framework pods..."
(cd ../AppCenterReactNativeShared/ios && pod install --repo-update)

echo "Running pod install and building shared framework..."
(cd ios && pod install --repo-update)
fi


echo "Running jetify to resolve AndroidX compatibility issues..."
npx jetify
if [ -z "$1" ] || [ "$1" == "android" ]; then
echo "Running jetify to resolve AndroidX compatibility issues..."
npx jetify

echo "Updating CocoaPods repos..."
pod repo update
OS_TYPE=$(uname)
if [[ "$OS_TYPE" == "Darwin" ]]; then
# macOS
SED_INPLACE=("sed" "-i" "")
else
# Linux and others
SED_INPLACE=("sed" "-i")
fi

echo "Install shared framework pods..."
(cd ../AppCenterReactNativeShared/ios && pod install)
# Remove versionName from build.gradle for AppCenterReactNativeShared
# to avoid build errors like:
# > Cannot get property 'versionName' on extra properties extension as it does not exist
# echo "Remove versionName from build.gradle for AppCenterReactNativeShared"
"${SED_INPLACE[@]}" "/buildConfigField .*VERSION_NAME/d" "../AppCenterReactNativeShared/android/build.gradle"

# for testing with not released apple and android sdks, you will need to provide the storage access key
echo "Running pod install and building shared framework..."
(cd ios && pod install --repo-update)
# Remove the line "from components.release" to avoid error:
# > Could not get unknown property 'release' for SoftwareComponentInternal set of type org.gradle.api.internal.component.DefaultSoftwareComponentContainer.
"${SED_INPLACE[@]}" "/from components.release/d" "../AppCenterReactNativeShared/android/build.gradle"

# workaround for macs on arm64 (uncomment when running on arm64 mac)
# (cd ios && pod install)
# Move android namespaces for the AppCenter modules from build.gradle to AndroidManifest.xml
# to avoid build errors like:
# > Could not find method namespace() for arguments [com.microsoft.appcenter.reactnative.appcenter] on extension 'android' of type com.android.build.gradle.LibraryExtension.
bash ./use-android-manifest-namespaces.sh
fi
85 changes: 85 additions & 0 deletions TestApp/use-android-manifest-namespaces.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/bin/bash

# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

# Move android namespaces for the AppCenter modules from build.gradle to AndroidManifest.xml

move_namespace() {
# Check if the first argument is provided
if [ -z "$1" ]; then
echo "There is no android project path: move_namespace /path/to/your/android/project"
return 1
fi

PROJECT_PATH="$1"
BUILD_GRADLE="$PROJECT_PATH/android/build.gradle"
MANIFEST_XML="$PROJECT_PATH/android/src/main/AndroidManifest.xml"

# Verify if build.gradle exists
if [ ! -f "$BUILD_GRADLE" ]; then
echo "Error: build.gradle not found: $BUILD_GRADLE"
return 1
fi

# Verify if AndroidManifest.xml exists
if [ ! -f "$MANIFEST_XML" ]; then
echo "Error: AndroidManifest.xml not found: $MANIFEST_XML"
return 1
fi

# Extract namespace from build.gradle
NAMESPACE=$(grep -E '^\s*namespace\s*[= ]\s*["'"'"']([^"'"'"']+)["'"'"']' "$BUILD_GRADLE" | head -n 1 | awk -F'"' '{print $2}')
ESCAPED_NAMESPACE="${NAMESPACE//./\\.}"

if [ -z "$NAMESPACE" ]; then
echo "Error: Can not find namespace in build.gradle"
return 1
fi

echo "Founded namespace: $NAMESPACE"

# Determine the operating system type and configure sed command for inline editing
OS_TYPE=$(uname)
if [[ "$OS_TYPE" == "Darwin" ]]; then
# macOS
SED_INPLACE=("sed" "-i" "")
else
# Linux and others
SED_INPLACE=("sed" "-i")
fi

# Remove the namespace line from build.gradle
"${SED_INPLACE[@]}" "/namespace \"${ESCAPED_NAMESPACE}\"/d" "$BUILD_GRADLE"
# Check if the namespace is successfully deleted
if grep -q "^\s*namespace\s* \s*['\"]${NAMESPACE}['\"]" "$BUILD_GRADLE"; then
echo "Error: namespace is not deleted from build.gradle"
return 1
else
echo "Namespace is deleted from build.gradle"
fi

# Extract the current package name from AndroidManifest.xml
CURRENT_PACKAGE=$(grep -E '<manifest\s+package="([^"]+)"' "$MANIFEST_XML" | head -n1 | sed -E 's/.*package="([^"]+)".*/\1/')

# Update or add the package attribute in AndroidManifest.xml if it differs from the namespace
if [ "$CURRENT_PACKAGE" != "$NAMESPACE" ]; then
if grep -q 'package="' "$MANIFEST_XML"; then
"${SED_INPLACE[@]}" "s/package=\"[^\"]*\"/package=\"$NAMESPACE\"/" "$MANIFEST_XML"
echo "Updated package attribute in AndroidManifest.xml to $NAMESPACE"
else
"${SED_INPLACE[@]}" "1s/<manifest /<manifest package=\"$NAMESPACE\" /" "$MANIFEST_XML"
echo "Added attribute package to AndroidManifest.xml: $NAMESPACE"
fi
else
echo "Package attribute already matches namespace: $NAMESPACE"
fi

echo "Namespace successfully moved from $BUILD_GRADLE to $MANIFEST_XML"
return 0
}

# Move namespaces for the AppCenter modules
move_namespace ./node_modules/appcenter
move_namespace ./node_modules/appcenter-analytics
move_namespace ./node_modules/appcenter-crashes