Skip to content

Commit

Permalink
ci: generate autolink in prep stage
Browse files Browse the repository at this point in the history
  • Loading branch information
siddarthkay committed Sep 18, 2024
1 parent 0f31894 commit 6a2ebae
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 '^$@$$'
Expand Down
1 change: 1 addition & 0 deletions ci/Jenkinsfile.android
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pipeline {
script {
utils.symlinkEnv()
println("Build Number: ${utils.genBuildNumber()}")
sh 'make generate-autolink-android'
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/build-android.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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[@]}"
31 changes: 31 additions & 0 deletions scripts/generate_autolink_android.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 6a2ebae

Please sign in to comment.