-
Notifications
You must be signed in to change notification settings - Fork 10
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
[eas-build-job] add channel to Job #24
Merged
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
1f1fd7e
[eas-build-job] add channel to Job
f619f4a
testse
ca1ca13
add oxor
912ec74
refactor to umbrella 'updates' object
b22b560
fix lint
1795157
metadata schema
d95347a
metadata test
d41e809
remove nesting and validation from metadata
d4f041d
add native mutations
c0e4f9a
refactore to platform tests
324e14e
remove stray logging
b038cb2
fix ios plist names
3ff6a41
add assert
5fd42d7
clean up
1f47d19
fix lint
803d789
remove uuid
1a637d1
Apply suggestions from code review
300f55e
use getAndroidManifestAsync
9b70011
rename to ...classic...
eb3b79e
simplify typing
75cf095
remove redundant platform parameter
c1e7bab
use IOSConfig
e4aa8c2
remove switch
bccfc34
remove undefined
d3327c1
remove assertion
fb60fc2
rename more classic
eb8333b
fix tests
c24eee8
fix tests
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,9 +34,7 @@ | |
"fs-extra": "^9.0.0", | ||
"node-forge": "^0.9.1", | ||
"nullthrows": "^1.1.1", | ||
"plist": "^3.0.1", | ||
"uuid": "^3.3.3", | ||
"xml2js": "^0.4.23" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I replaced the manual xml2js usage in |
||
"plist": "^3.0.1" | ||
}, | ||
"devDependencies": { | ||
"@types/fs-extra": "^9.0.1", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
156 changes: 156 additions & 0 deletions
156
packages/build-tools/src/android/__tests__/expoUpdates.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
import path from 'path'; | ||
|
||
import fs from 'fs-extra'; | ||
import { AndroidConfig } from '@expo/config-plugins'; | ||
|
||
import { | ||
AndroidMetadataName, | ||
androidGetNativelyDefinedClassicReleaseChannelAsync, | ||
androidSetChannelNativelyAsync, | ||
androidSetClassicReleaseChannelNativelyAsync, | ||
} from '../expoUpdates'; | ||
|
||
jest.mock('fs'); | ||
|
||
const channel = 'main'; | ||
const noMetadataAndroidManifest = ` | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.expo.mycoolapp"> | ||
|
||
<uses-permission android:name="android.permission.INTERNET" /> | ||
|
||
<application | ||
android:name=".MainApplication" | ||
android:label="@string/app_name" | ||
android:icon="@mipmap/ic_launcher" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:allowBackup="true" | ||
android:theme="@style/AppTheme"> | ||
<activity | ||
android:name=".MainActivity" | ||
android:launchMode="singleTask" | ||
android:label="@string/app_name" | ||
android:configChanges="keyboard|keyboardHidden|orientation|screenSize" | ||
android:windowSoftInputMode="adjustResize"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" /> | ||
</application> | ||
|
||
</manifest> | ||
`; | ||
describe(androidSetClassicReleaseChannelNativelyAsync, () => { | ||
test('sets the release channel', async () => { | ||
const reactNativeProjectDirectory = fs.mkdtempSync('/expo-project-'); | ||
fs.ensureDirSync(reactNativeProjectDirectory); | ||
const releaseChannel = 'default'; | ||
const ctx = { | ||
reactNativeProjectDirectory, | ||
job: { releaseChannel }, | ||
logger: { info: () => {} }, | ||
}; | ||
|
||
fs.ensureDirSync(path.join(reactNativeProjectDirectory, 'android')); | ||
const manifestPath = await AndroidConfig.Paths.getAndroidManifestAsync( | ||
reactNativeProjectDirectory | ||
); | ||
const manifestDirectory = path.dirname(manifestPath); | ||
|
||
fs.ensureDirSync(manifestDirectory); | ||
fs.writeFileSync(manifestPath, Buffer.from(noMetadataAndroidManifest)); | ||
const androidManifest = await AndroidConfig.Manifest.readAndroidManifestAsync(manifestPath); | ||
expect( | ||
AndroidConfig.Manifest.getMainApplicationMetaDataValue(androidManifest, 'releaseChannel') | ||
).toBe(null); | ||
|
||
await androidSetClassicReleaseChannelNativelyAsync(ctx as any); | ||
|
||
const newAndroidManifest = await AndroidConfig.Manifest.readAndroidManifestAsync(manifestPath); | ||
expect( | ||
AndroidConfig.Manifest.getMainApplicationMetaDataValue( | ||
newAndroidManifest, | ||
AndroidMetadataName.RELEASE_CHANNEL | ||
) | ||
).toBe(releaseChannel); | ||
}); | ||
}); | ||
describe(androidSetChannelNativelyAsync, () => { | ||
it('sets the channel', async () => { | ||
const reactNativeProjectDirectory = fs.mkdtempSync('/expo-project-'); | ||
fs.ensureDirSync(reactNativeProjectDirectory); | ||
const ctx = { | ||
reactNativeProjectDirectory, | ||
job: { updates: { channel } }, | ||
logger: { info: () => {} }, | ||
}; | ||
|
||
fs.ensureDirSync(path.join(reactNativeProjectDirectory, 'android')); | ||
const manifestPath = await AndroidConfig.Paths.getAndroidManifestAsync( | ||
reactNativeProjectDirectory | ||
); | ||
const manifestDirectory = path.dirname(manifestPath); | ||
|
||
fs.ensureDirSync(manifestDirectory); | ||
fs.writeFileSync(manifestPath, noMetadataAndroidManifest); | ||
|
||
const androidManifest = await AndroidConfig.Manifest.readAndroidManifestAsync(manifestPath); | ||
expect( | ||
AndroidConfig.Manifest.getMainApplicationMetaDataValue( | ||
androidManifest, | ||
AndroidMetadataName.UPDATES_CONFIGURATION_REQUEST_HEADERS_KEY | ||
) | ||
).toBe(null); | ||
|
||
await androidSetChannelNativelyAsync(ctx as any); | ||
|
||
const newAndroidManifest = await AndroidConfig.Manifest.readAndroidManifestAsync(manifestPath); | ||
const newValue = AndroidConfig.Manifest.getMainApplicationMetaDataValue( | ||
newAndroidManifest, | ||
AndroidMetadataName.UPDATES_CONFIGURATION_REQUEST_HEADERS_KEY | ||
); | ||
expect(newValue).toBeDefined(); | ||
expect(JSON.parse(newValue!)).toEqual({ 'expo-channel-name': channel }); | ||
}); | ||
}); | ||
describe(androidGetNativelyDefinedClassicReleaseChannelAsync, () => { | ||
it('gets the natively defined release channel', async () => { | ||
const reactNativeProjectDirectory = fs.mkdtempSync('/expo-project-'); | ||
fs.ensureDirSync(reactNativeProjectDirectory); | ||
const releaseChannel = 'default'; | ||
const ctx = { | ||
reactNativeProjectDirectory, | ||
logger: { info: () => {} }, | ||
}; | ||
|
||
const releaseChannelInAndroidManifest = ` | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.expo.mycoolapp"> | ||
<uses-permission android:name="android.permission.INTERNET"/> | ||
<application android:name=".MainApplication" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round" android:allowBackup="true" android:theme="@style/AppTheme"> | ||
<activity android:name=".MainActivity" android:launchMode="singleTask" android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden|orientation|screenSize" android:windowSoftInputMode="adjustResize"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN"/> | ||
<category android:name="android.intent.category.LAUNCHER"/> | ||
</intent-filter> | ||
</activity> | ||
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity"/> | ||
<meta-data android:name="expo.modules.updates.EXPO_RELEASE_CHANNEL" android:value="default"/> | ||
</application> | ||
</manifest>`; | ||
fs.ensureDirSync(path.join(reactNativeProjectDirectory, 'android')); | ||
const manifestPath = await AndroidConfig.Paths.getAndroidManifestAsync( | ||
reactNativeProjectDirectory | ||
); | ||
const manifestDirectory = path.dirname(manifestPath); | ||
|
||
fs.ensureDirSync(manifestDirectory); | ||
fs.writeFileSync(manifestPath, releaseChannelInAndroidManifest); | ||
|
||
const nativelyDefinedReleaseChannel = await androidGetNativelyDefinedClassicReleaseChannelAsync( | ||
ctx as any | ||
); | ||
expect(nativelyDefinedReleaseChannel).toBe(releaseChannel); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import assert from 'assert'; | ||
|
||
import fs from 'fs-extra'; | ||
import { AndroidConfig } from '@expo/config-plugins'; | ||
import { Job } from '@expo/eas-build-job'; | ||
|
||
import { BuildContext } from '../context'; | ||
|
||
export enum AndroidMetadataName { | ||
jkhales marked this conversation as resolved.
Show resolved
Hide resolved
|
||
UPDATES_CONFIGURATION_REQUEST_HEADERS_KEY = 'expo.modules.updates.UPDATES_CONFIGURATION_REQUEST_HEADERS_KEY', | ||
RELEASE_CHANNEL = 'expo.modules.updates.EXPO_RELEASE_CHANNEL', | ||
} | ||
|
||
export async function androidSetChannelNativelyAsync(ctx: BuildContext<Job>): Promise<void> { | ||
assert(ctx.job.updates?.channel, 'updates.channel must be defined'); | ||
|
||
const manifestPath = await AndroidConfig.Paths.getAndroidManifestAsync( | ||
ctx.reactNativeProjectDirectory | ||
); | ||
|
||
if (!(await fs.pathExists(manifestPath))) { | ||
throw new Error(`Couldn't find Android manifest at ${manifestPath}`); | ||
} | ||
|
||
const androidManifest = await AndroidConfig.Manifest.readAndroidManifestAsync(manifestPath); | ||
const mainApp = AndroidConfig.Manifest.getMainApplicationOrThrow(androidManifest); | ||
const stringifiedUpdatesRequestHeaders = AndroidConfig.Manifest.getMainApplicationMetaDataValue( | ||
androidManifest, | ||
AndroidMetadataName.UPDATES_CONFIGURATION_REQUEST_HEADERS_KEY | ||
); | ||
AndroidConfig.Manifest.addMetaDataItemToMainApplication( | ||
mainApp, | ||
AndroidMetadataName.UPDATES_CONFIGURATION_REQUEST_HEADERS_KEY, | ||
JSON.stringify({ | ||
...JSON.parse(stringifiedUpdatesRequestHeaders ?? '{}'), | ||
'expo-channel-name': ctx.job.updates.channel, | ||
}), | ||
'value' | ||
); | ||
await AndroidConfig.Manifest.writeAndroidManifestAsync(manifestPath, androidManifest); | ||
} | ||
|
||
export async function androidSetClassicReleaseChannelNativelyAsync( | ||
ctx: BuildContext<Job> | ||
): Promise<void> { | ||
assert(ctx.job.releaseChannel, 'releaseChannel must be defined'); | ||
|
||
const manifestPath = await AndroidConfig.Paths.getAndroidManifestAsync( | ||
ctx.reactNativeProjectDirectory | ||
); | ||
if (!(await fs.pathExists(manifestPath))) { | ||
throw new Error(`Couldn't find Android manifest at ${manifestPath}`); | ||
} | ||
|
||
const androidManifest = await AndroidConfig.Manifest.readAndroidManifestAsync(manifestPath); | ||
const mainApp = AndroidConfig.Manifest.getMainApplicationOrThrow(androidManifest); | ||
AndroidConfig.Manifest.addMetaDataItemToMainApplication( | ||
mainApp, | ||
AndroidMetadataName.RELEASE_CHANNEL, | ||
ctx.job.releaseChannel, | ||
'value' | ||
); | ||
await AndroidConfig.Manifest.writeAndroidManifestAsync(manifestPath, androidManifest); | ||
} | ||
|
||
export async function androidGetNativelyDefinedClassicReleaseChannelAsync( | ||
ctx: BuildContext<Job> | ||
): Promise<string | null> { | ||
const manifestPath = await AndroidConfig.Paths.getAndroidManifestAsync( | ||
ctx.reactNativeProjectDirectory | ||
); | ||
if (!(await fs.pathExists(manifestPath))) { | ||
return null; | ||
} | ||
|
||
const androidManifest = await AndroidConfig.Manifest.readAndroidManifestAsync(manifestPath); | ||
return AndroidConfig.Manifest.getMainApplicationMetaDataValue( | ||
androidManifest, | ||
AndroidMetadataName.RELEASE_CHANNEL | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uuid wasn't being used.