-
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
Changes from 16 commits
1f1fd7e
f619f4a
ca1ca13
912ec74
b22b560
1795157
d95347a
d41e809
d4f041d
c0e4f9a
324e14e
b038cb2
3ff6a41
5fd42d7
1f47d19
803d789
1a637d1
300f55e
9b70011
eb3b79e
75cf095
c1e7bab
e4aa8c2
bccfc34
d3327c1
fb60fc2
eb8333b
c24eee8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
import path from 'path'; | ||
|
||
import fs from 'fs-extra'; | ||
import { AndroidConfig } from '@expo/config-plugins'; | ||
|
||
import { | ||
AndroidMetadataName, | ||
getAndroidManifestDirectory, | ||
androidGetNativelyDefinedReleaseChannelAsync, | ||
androidSetChannelNativelyAsync, | ||
androidSetReleaseChannelNativelyAsync, | ||
} 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(androidSetReleaseChannelNativelyAsync, () => { | ||
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: () => {} }, | ||
}; | ||
|
||
const manifestDirectory = getAndroidManifestDirectory(reactNativeProjectDirectory); | ||
const manifestPath = path.join(manifestDirectory, 'AndroidManifest.xml'); | ||
|
||
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 androidSetReleaseChannelNativelyAsync(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: () => {} }, | ||
}; | ||
|
||
const manifestDirectory = getAndroidManifestDirectory(reactNativeProjectDirectory); | ||
const manifestPath = path.join(manifestDirectory, 'AndroidManifest.xml'); | ||
|
||
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(androidGetNativelyDefinedReleaseChannelAsync, () => { | ||
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>`; | ||
const manifestDirectory = getAndroidManifestDirectory(reactNativeProjectDirectory); | ||
const manifestPath = path.join(manifestDirectory, 'AndroidManifest.xml'); | ||
|
||
fs.ensureDirSync(manifestDirectory); | ||
fs.writeFileSync(manifestPath, releaseChannelInAndroidManifest); | ||
|
||
const nativelyDefinedReleaseChannel = await androidGetNativelyDefinedReleaseChannelAsync( | ||
ctx as any | ||
); | ||
expect(nativelyDefinedReleaseChannel).toBe(releaseChannel); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,89 @@ | ||||||
import path from 'path'; | ||||||
import assert from 'assert'; | ||||||
|
||||||
import fs from 'fs-extra'; | ||||||
import { AndroidConfig } from '@expo/config-plugins'; | ||||||
|
||||||
import { ManagedBuildContext, ManagedJob } from '../managed/context'; | ||||||
import { BuildContext } from '../context'; | ||||||
import { GenericJob } from '../utils/expoUpdates'; | ||||||
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 function getAndroidManifestDirectory(reactNativeProjectDirectory: string): string { | ||||||
jkhales marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
return path.join(reactNativeProjectDirectory, 'android', 'app', 'src', 'main'); | ||||||
} | ||||||
|
||||||
export async function androidSetChannelNativelyAsync( | ||||||
ctx: ManagedBuildContext<ManagedJob> | BuildContext<GenericJob> | ||||||
): Promise<void> { | ||||||
assert(ctx.job.updates?.channel, 'updates.channel must be defined'); | ||||||
|
||||||
const manifestPath = path.join( | ||||||
getAndroidManifestDirectory(ctx.reactNativeProjectDirectory), | ||||||
'AndroidManifest.xml' | ||||||
); | ||||||
jkhales marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
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 const androidSetReleaseChannelNativelyAsync = async ( | ||||||
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.
When we switch to eas updates old key in eas.json will also have to be renamed this way to 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.
Suggested change
|
||||||
ctx: ManagedBuildContext<ManagedJob> | BuildContext<GenericJob> | ||||||
): Promise<void> => { | ||||||
assert(ctx.job.releaseChannel, 'releaseChannel must be defined'); | ||||||
|
||||||
const manifestPath = path.join( | ||||||
getAndroidManifestDirectory(ctx.reactNativeProjectDirectory), | ||||||
'AndroidManifest.xml' | ||||||
); | ||||||
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 const androidGetNativelyDefinedReleaseChannelAsync = async ( | ||||||
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.
Suggested change
|
||||||
ctx: ManagedBuildContext<ManagedJob> | BuildContext<GenericJob> | ||||||
jkhales marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
): Promise<string | undefined | null> => { | ||||||
const manifestPath = path.join( | ||||||
getAndroidManifestDirectory(ctx.reactNativeProjectDirectory), | ||||||
'AndroidManifest.xml' | ||||||
); | ||||||
if (!(await fs.pathExists(manifestPath))) { | ||||||
return; | ||||||
} | ||||||
|
||||||
const androidManifest = await AndroidConfig.Manifest.readAndroidManifestAsync(manifestPath); | ||||||
return AndroidConfig.Manifest.getMainApplicationMetaDataValue( | ||||||
androidManifest, | ||||||
AndroidMetadataName.RELEASE_CHANNEL | ||||||
); | ||||||
}; |
This file was deleted.
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.