From 6a2ebae0586fa9351247be00c1eda3171e525d2e Mon Sep 17 00:00:00 2001 From: Siddarth Kumar Date: Wed, 18 Sep 2024 08:03:25 +0530 Subject: [PATCH] ci: generate autolink in prep stage --- Makefile | 4 ++++ ci/Jenkinsfile.android | 1 + scripts/build-android.sh | 2 +- scripts/generate_autolink_android.sh | 31 ++++++++++++++++++++++++++++ 4 files changed, 37 insertions(+), 1 deletion(-) create mode 100755 scripts/generate_autolink_android.sh diff --git a/Makefile b/Makefile index b9bfb722ee54..01538170672b 100644 --- a/Makefile +++ b/Makefile @@ -476,6 +476,10 @@ android-install: export BUILD_TYPE ?= release android-install: ##@other Install APK on device using adb adb install result/app-$(BUILD_TYPE).apk +generate-autolink-android: export TARGET := default +generate-autolink-android: ##@other Generate autolinking.json + @scripts/generate_autolink_android.sh + _list: SHELL := /bin/sh _list: @$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' diff --git a/ci/Jenkinsfile.android b/ci/Jenkinsfile.android index bb1e85aaea8a..699883012a35 100644 --- a/ci/Jenkinsfile.android +++ b/ci/Jenkinsfile.android @@ -49,6 +49,7 @@ pipeline { script { utils.symlinkEnv() println("Build Number: ${utils.genBuildNumber()}") + sh 'make generate-autolink-android' } } } diff --git a/scripts/build-android.sh b/scripts/build-android.sh index d032d9cc1b99..0b105a6af362 100755 --- a/scripts/build-android.sh +++ b/scripts/build-android.sh @@ -101,6 +101,6 @@ else fi # needed since react-native v0.75 -generate_android_autolink +source "${GIT_ROOT}/scripts/generate_autolink_android.sh" "${GIT_ROOT}/nix/scripts/build.sh" targets.mobile.android.build "${nixOpts[@]}" diff --git a/scripts/generate_autolink_android.sh b/scripts/generate_autolink_android.sh new file mode 100755 index 000000000000..c15eede599dc --- /dev/null +++ b/scripts/generate_autolink_android.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash + +function generate_android_autolink() { + AUTOLINKING_DIR="android/build/generated/autolinking" + + if [ ! -d "$AUTOLINKING_DIR" ]; then + mkdir -p "$AUTOLINKING_DIR" + echo "Created directory: $AUTOLINKING_DIR" + fi + + rm "$AUTOLINKING_DIR/autolinking.json" || true + react-native config > "$AUTOLINKING_DIR/autolinking.json" + echo "Generated autolinking.json" + + ROOT_VALUE=$(jq -r '.root' "$AUTOLINKING_DIR/autolinking.json") + + if [ -z "$ROOT_VALUE" ]; then + echo "Error: 'root' key not found in autolinking.json" + exit 1 + fi + + echo "Current 'root' value: $ROOT_VALUE" + + sed -i.bak "s|$ROOT_VALUE|..|g" "$AUTOLINKING_DIR/autolinking.json" + + echo "Updated autolinking.json: replaced all occurrences of '$ROOT_VALUE' with '..'" + + rm "$AUTOLINKING_DIR/autolinking.json.bak" +} + +generate_android_autolink