Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
5 changes: 5 additions & 0 deletions .changeset/fix-expo-ios-symbol-upload.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'posthog-react-native': patch
---

Use EAS-managed iOS versions from the source Info.plist when uploading Hermes source maps.
Comment thread
marandaneto marked this conversation as resolved.
Outdated
62 changes: 62 additions & 0 deletions packages/react-native/test/posthog-xcode-parse.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,68 @@ describe('posthog-xcode.sh bundle command composition', () => {
})
})

describe('posthog-xcode.sh release version resolution', () => {
const scriptContents = fs.readFileSync(SCRIPT_PATH, 'utf8')

const extractReleaseInfoBlock = (): string => {
const match = scriptContents.match(
/resolve_posthog_ios_release_info\(\) \{[\s\S]+?\n\}\n\nresolve_posthog_ios_release_info/
)
if (!match) throw new Error('Could not locate iOS release info resolution in posthog-xcode.sh')
return match[0]
}

const resolveReleaseInfo = (
tempDir: string,
plistVersion: string,
plistBuild: string,
marketingVersion = '1.0',
projectVersion = '1'
): string => {
const plistBuddy = path.join(tempDir, 'plist-buddy')
const infoPlist = path.join(tempDir, 'ExampleApp', 'Info.plist')
fs.mkdirSync(path.dirname(infoPlist), { recursive: true })
fs.writeFileSync(infoPlist, '')
fs.writeFileSync(
plistBuddy,
'#!/bin/sh\ncase "$2" in\n *CFBundleShortVersionString*) printf %s "$TEST_PLIST_VERSION" ;;\n *CFBundleVersion*) printf %s "$TEST_PLIST_BUILD" ;;\nesac\n',
{ mode: 0o755 }
)

const script = `${extractReleaseInfoBlock()}\nprintf '%s|%s' "$POSTHOG_RELEASE_VERSION" "$POSTHOG_BUILD_VERSION"`
return execFileSync('/bin/bash', ['-c', script], {
env: {
...process.env,
SRCROOT: tempDir,
INFOPLIST_FILE: 'ExampleApp/Info.plist',
POSTHOG_PLIST_BUDDY: plistBuddy,
MARKETING_VERSION: marketingVersion,
CURRENT_PROJECT_VERSION: projectVersion,
TEST_PLIST_VERSION: plistVersion,
TEST_PLIST_BUILD: plistBuild,
},
}).toString()
}

it('prefers Expo source Info.plist versions over generated Xcode defaults', () => {
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'posthog-xcode-version-'))
try {
expect(resolveReleaseInfo(tempDir, '2.10.0', '154')).toBe('2.10.0|154')
} finally {
fs.rmSync(tempDir, { recursive: true, force: true })
}
})

it('keeps Xcode versions when source Info.plist values are unresolved', () => {
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'posthog-xcode-version-'))
try {
expect(resolveReleaseInfo(tempDir, '$(MARKETING_VERSION)', '$(CURRENT_PROJECT_VERSION)')).toBe('1.0|1')
} finally {
fs.rmSync(tempDir, { recursive: true, force: true })
}
})
})

describe('posthog-xcode.sh skipOnConflict upload flag', () => {
it('passes --skip-on-conflict only to hermes upload', () => {
const contents = fs.readFileSync(SCRIPT_PATH, 'utf8')
Expand Down
45 changes: 40 additions & 5 deletions packages/react-native/tooling/posthog-xcode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,51 @@ fi
# mimics how the file is defined in node_modules/react-native/scripts/react-native-xcode.sh (PACKAGER_SOURCEMAP_FILE)
SOURCEMAP_PACKAGER_FILE="$CONFIGURATION_BUILD_DIR/$SOURCEMAP_NAME"

# Pass release info from Xcode build settings when available
# Expo EAS remote versioning writes the release version to the source Info.plist
Comment thread
marandaneto marked this conversation as resolved.
Outdated
# without necessarily updating MARKETING_VERSION or CURRENT_PROJECT_VERSION.
resolve_posthog_ios_release_info() {
Comment thread
marandaneto marked this conversation as resolved.
POSTHOG_RELEASE_VERSION="${MARKETING_VERSION:-}"
POSTHOG_BUILD_VERSION="${CURRENT_PROJECT_VERSION:-}"
POSTHOG_PLIST_BUDDY="${POSTHOG_PLIST_BUDDY:-/usr/libexec/PlistBuddy}"

if [ -z "${INFOPLIST_FILE:-}" ] || [ ! -x "$POSTHOG_PLIST_BUDDY" ]; then
return
fi

POSTHOG_INFO_PLIST="$INFOPLIST_FILE"
case "$POSTHOG_INFO_PLIST" in
/*) ;;
*) POSTHOG_INFO_PLIST="${SRCROOT}/${POSTHOG_INFO_PLIST}" ;;
esac

if [ ! -f "$POSTHOG_INFO_PLIST" ]; then
return
fi

POSTHOG_PLIST_RELEASE_VERSION=$("$POSTHOG_PLIST_BUDDY" -c "Print :CFBundleShortVersionString" "$POSTHOG_INFO_PLIST" 2>/dev/null || true)
POSTHOG_PLIST_BUILD_VERSION=$("$POSTHOG_PLIST_BUDDY" -c "Print :CFBundleVersion" "$POSTHOG_INFO_PLIST" 2>/dev/null || true)

case "$POSTHOG_PLIST_RELEASE_VERSION" in
""|*'$('*|*'${'*) ;;
*) POSTHOG_RELEASE_VERSION="$POSTHOG_PLIST_RELEASE_VERSION" ;;
esac
case "$POSTHOG_PLIST_BUILD_VERSION" in
""|*'$('*|*'${'*) ;;
*) POSTHOG_BUILD_VERSION="$POSTHOG_PLIST_BUILD_VERSION" ;;
esac
}

resolve_posthog_ios_release_info

CLI_RELEASE_ARGS=""
if [ -n "${PRODUCT_BUNDLE_IDENTIFIER}" ]; then
CLI_RELEASE_ARGS="$CLI_RELEASE_ARGS --release-name $PRODUCT_BUNDLE_IDENTIFIER"
fi
if [ -n "${MARKETING_VERSION}" ]; then
CLI_RELEASE_ARGS="$CLI_RELEASE_ARGS --release-version $MARKETING_VERSION"
if [ -n "${POSTHOG_RELEASE_VERSION}" ]; then
CLI_RELEASE_ARGS="$CLI_RELEASE_ARGS --release-version $POSTHOG_RELEASE_VERSION"
Comment thread
marandaneto marked this conversation as resolved.
Outdated
fi
if [ -n "${CURRENT_PROJECT_VERSION}" ]; then
CLI_RELEASE_ARGS="$CLI_RELEASE_ARGS --build $CURRENT_PROJECT_VERSION"
if [ -n "${POSTHOG_BUILD_VERSION}" ]; then
CLI_RELEASE_ARGS="$CLI_RELEASE_ARGS --build $POSTHOG_BUILD_VERSION"
fi

# RN deletes the PACKAGER_SOURCEMAP_FILE file after execution but we need it
Expand Down