Skip to content
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

add appBuildVersion to build metadata #413

Merged
merged 6 commits into from
May 20, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ This is the log of notable changes to EAS CLI and related packages.
- Allow for installing custom `expo-cli` version on EAS Build. ([#409](https://github.com/expo/eas-cli/pull/409) by [@randomhajile](https://github.com/randomhajile))
- Support PKCS kesytores for Android. ([#398](https://github.com/expo/eas-cli/pull/398) by [@wkozyra95](https://github.com/wkozyra95))
- Support empty passwords in Android and iOS keystores. ([#398](https://github.com/expo/eas-cli/pull/398) by [@wkozyra95](https://github.com/wkozyra95))
- Add more build metadata - `appBuildVersion`. ([#413](https://github.com/expo/eas-cli/pull/413) by [@dsokal](https://github.com/dsokal))

### 🐛 Bug fixes

Expand Down
2 changes: 1 addition & 1 deletion packages/eas-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@expo/apple-utils": "0.0.0-alpha.20",
"@expo/config": "3.3.19",
"@expo/config-plugins": "1.0.31",
"@expo/eas-build-job": "0.2.33",
"@expo/eas-build-job": "0.2.35",
"@expo/eas-json": "0.14.0",
"@expo/json-file": "8.2.25",
"@expo/pkcs12": "0.0.4",
Expand Down
114 changes: 114 additions & 0 deletions packages/eas-cli/src/build/android/__tests__/version-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import { ExpoConfig } from '@expo/config';
import fs from 'fs-extra';
import { vol } from 'memfs';
import os from 'os';

import { readVersionCode, readVersionName } from '../version';

jest.mock('fs');

afterAll(() => {
// do not remove the following line
// this fixes a weird error with tempy in @expo/image-utils
fs.removeSync(os.tmpdir());
});

beforeEach(() => {
vol.reset();
// do not remove the following line
// this fixes a weird error with tempy in @expo/image-utils
fs.mkdirpSync(os.tmpdir());
});

describe(readVersionCode, () => {
describe('generic project', () => {
it('reads the version code from native code', () => {
const exp = initGenericProject();
const versionCode = readVersionCode('/repo', exp);
expect(versionCode).toBe(123);
});
});
describe('managed project', () => {
it('reads the version code from expo config', () => {
const exp = initManagedProject();
const versionCode = readVersionCode('/repo', exp);
expect(versionCode).toBe(123);
});
});
});

describe(readVersionName, () => {
describe('generic project', () => {
it('reads the version name from native code', () => {
const exp = initGenericProject();
const versionName = readVersionName('/repo', exp);
expect(versionName).toBe('1.0');
});
});
describe('managed project', () => {
it('reads the version from expo config', () => {
const exp = initManagedProject();
const versionName = readVersionName('/repo', exp);
expect(versionName).toBe('1.0.0');
});
});
});

function initGenericProject(): ExpoConfig {
vol.fromJSON(
{
'./app.json': JSON.stringify({
expo: {
version: '1.0.0',
android: {
versionCode: 1,
},
},
}),
'./android/app/build.gradle': `android {
defaultConfig {
applicationId "com.expo.testapp"
versionCode 123
versionName "1.0"
}
}`,
},
'/repo'
);

const fakeExp: ExpoConfig = {
name: 'myproject',
slug: 'myproject',
version: '1.0.0',
android: {
versionCode: 123,
},
};
return fakeExp;
}

function initManagedProject(): ExpoConfig {
vol.fromJSON(
{
'./app.json': JSON.stringify({
expo: {
version: '1.0.0',
android: {
versionCode: 123,
},
},
}),
},
'/repo'
);

const fakeExp: ExpoConfig = {
name: 'myproject',
slug: 'myproject',
version: '1.0.0',
android: {
versionCode: 123,
},
};
return fakeExp;
}
44 changes: 44 additions & 0 deletions packages/eas-cli/src/build/android/version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { ExpoConfig } from '@expo/config';
import { AndroidConfig } from '@expo/config-plugins';
import { Platform, Workflow } from '@expo/eas-build-job';
import fs from 'fs-extra';

import { resolveWorkflow } from '../../project/workflow';

export function readVersionCode(projectDir: string, exp: ExpoConfig): number | undefined {
const workflow = resolveWorkflow(projectDir, Platform.ANDROID);
if (workflow === Workflow.GENERIC) {
const buildGradle = readBuildGradle(projectDir);
const matchResult = buildGradle?.match(/versionCode (.*)/);
if (matchResult) {
return Number(matchResult[1]);
} else {
return undefined;
}
} else {
return AndroidConfig.Version.getVersionCode(exp) ?? undefined;
}
}

export function readVersionName(projectDir: string, exp: ExpoConfig): string | undefined {
const workflow = resolveWorkflow(projectDir, Platform.ANDROID);
if (workflow === Workflow.GENERIC) {
const buildGradle = readBuildGradle(projectDir);
const matchResult = buildGradle?.match(/versionName ["'](.*)["']/);
if (matchResult) {
return matchResult[1];
} else {
return undefined;
}
} else {
return exp.version;
}
}

function readBuildGradle(projectDir: string): string | undefined {
const buildGradlePath = AndroidConfig.Paths.getAppBuildGradle(projectDir);
if (!fs.pathExistsSync(buildGradlePath)) {
return undefined;
}
return fs.readFileSync(buildGradlePath, 'utf8');
}
44 changes: 43 additions & 1 deletion packages/eas-cli/src/build/ios/__tests__/version-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ import { vol } from 'memfs';
import os from 'os';

import { readPlistAsync } from '../plist';
import { BumpStrategy, bumpVersionAsync, bumpVersionInAppJsonAsync } from '../version';
import {
BumpStrategy,
bumpVersionAsync,
bumpVersionInAppJsonAsync,
readBuildNumberAsync,
readShortVersionAsync,
} from '../version';

jest.mock('fs');

Expand Down Expand Up @@ -144,6 +150,42 @@ describe(bumpVersionInAppJsonAsync, () => {
});
});

describe(readBuildNumberAsync, () => {
describe('generic project', () => {
it('reads the build number from native code', async () => {
const exp = initGenericProject();
const buildNumber = await readBuildNumberAsync('/repo', exp);
expect(buildNumber).toBe('1');
});
});

describe('managed project', () => {
it('reads the build number from expo config', async () => {
const exp = initManagedProject();
const buildNumber = await readBuildNumberAsync('/repo', exp);
expect(buildNumber).toBe('1');
});
});
});

describe(readShortVersionAsync, () => {
describe('generic project', () => {
it('reads the short version from native code', async () => {
const exp = initGenericProject();
const shortVersion = await readShortVersionAsync('/repo', exp);
expect(shortVersion).toBe('1.0.0');
});
});

describe('managed project', () => {
it('reads the version from app config', async () => {
const exp = initGenericProject();
const shortVersion = await readShortVersionAsync('/repo', exp);
expect(shortVersion).toBe('1.0.0');
});
});
});

function initGenericProject(): ExpoConfig {
vol.fromJSON(
{
Expand Down
34 changes: 31 additions & 3 deletions packages/eas-cli/src/build/ios/version.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { ExpoConfig, getConfigFilePaths } from '@expo/config';
import { IOSConfig } from '@expo/config-plugins';
import { Platform, Workflow } from '@expo/eas-build-job';
import chalk from 'chalk';
import nullthrows from 'nullthrows';
import semver from 'semver';

import Log from '../../log';
import { resolveWorkflow } from '../../project/workflow';
import { promptAsync } from '../../prompts';
import { updateAppJsonConfigAsync } from '../utils/appJson';
import { readPlistAsync, writePlistAsync } from './plist';
Expand Down Expand Up @@ -100,9 +102,30 @@ export async function bumpVersionInAppJsonAsync({
}
}

async function readInfoPlistAsync(projectDir: string): Promise<IOSConfig.InfoPlist> {
const infoPlistPath = IOSConfig.Paths.getInfoPlistPath(projectDir);
return (await readPlistAsync(infoPlistPath)) as IOSConfig.InfoPlist;
export async function readShortVersionAsync(
projectDir: string,
exp: ExpoConfig
): Promise<string | undefined> {
const workflow = resolveWorkflow(projectDir, Platform.IOS);
if (workflow === Workflow.GENERIC) {
const infoPlist = await readInfoPlistAsync(projectDir);
return infoPlist.CFBundleShortVersionString;
} else {
return exp.version;
}
}

export async function readBuildNumberAsync(
projectDir: string,
exp: ExpoConfig
): Promise<string | undefined> {
const workflow = resolveWorkflow(projectDir, Platform.IOS);
if (workflow === Workflow.GENERIC) {
const infoPlist = await readInfoPlistAsync(projectDir);
return infoPlist.CFBundleVersion;
} else {
return IOSConfig.Version.getBuildNumber(exp);
}
}

async function writeVersionsToInfoPlistAsync({
Expand All @@ -120,6 +143,11 @@ async function writeVersionsToInfoPlistAsync({
return updatedInfoPlist;
}

async function readInfoPlistAsync(projectDir: string): Promise<IOSConfig.InfoPlist> {
const infoPlistPath = IOSConfig.Paths.getInfoPlistPath(projectDir);
return (await readPlistAsync(infoPlistPath)) as IOSConfig.InfoPlist;
}

async function writeInfoPlistAsync({
projectDir,
infoPlist,
Expand Down
40 changes: 34 additions & 6 deletions packages/eas-cli/src/build/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import { getUsername } from '../project/projectUtils';
import { ensureLoggedInAsync } from '../user/actions';
import { gitCommitHashAsync } from '../utils/git';
import { readReleaseChannelSafelyAsync as readAndroidReleaseChannelSafelyAsync } from './android/UpdatesModule';
import { readVersionCode, readVersionName } from './android/version';
import { BuildContext } from './context';
import { readReleaseChannelSafelyAsync as readIosReleaseChannelSafelyAsync } from './ios/UpdatesModule';
import { readBuildNumberAsync, readShortVersionAsync } from './ios/version';
import { Platform } from './types';
import { isExpoUpdatesInstalled } from './utils/updates';

Expand All @@ -27,27 +29,53 @@ export async function collectMetadata<T extends Platform>(
credentialsSource?: CredentialsSource.LOCAL | CredentialsSource.REMOTE;
}
): Promise<Metadata> {
const appIdentifier =
ctx.platform === Platform.IOS
? getBundleIdentifier(ctx.commandCtx.projectDir, ctx.commandCtx.exp)
: getApplicationId(ctx.commandCtx.projectDir, ctx.commandCtx.exp);
return {
trackingContext: ctx.trackingCtx,
appVersion: ctx.commandCtx.exp.version!,
appVersion: await resolveAppVersionAsync(ctx),
appBuildVersion: await resolveAppBuildVersionAsync(ctx),
cliVersion: packageJSON.version,
workflow: ctx.buildProfile.workflow,
credentialsSource,
sdkVersion: ctx.commandCtx.exp.sdkVersion,
releaseChannel: await resolveReleaseChannel(ctx),
distribution: ctx.buildProfile.distribution ?? 'store',
appName: ctx.commandCtx.exp.name,
appIdentifier,
appIdentifier: resolveAppIdentifier(ctx),
buildProfile: ctx.commandCtx.profile,
gitCommitHash: await gitCommitHashAsync(),
username: getUsername(ctx.commandCtx.exp, await ensureLoggedInAsync()),
};
}

async function resolveAppVersionAsync<T extends Platform>(
ctx: BuildContext<T>
): Promise<string | undefined> {
if (ctx.platform === Platform.IOS) {
return await readShortVersionAsync(ctx.commandCtx.projectDir, ctx.commandCtx.exp);
} else {
return readVersionName(ctx.commandCtx.projectDir, ctx.commandCtx.exp);
}
}

async function resolveAppBuildVersionAsync<T extends Platform>(
ctx: BuildContext<T>
): Promise<string | undefined> {
if (ctx.platform === Platform.IOS) {
return await readBuildNumberAsync(ctx.commandCtx.projectDir, ctx.commandCtx.exp);
} else {
const versionCode = readVersionCode(ctx.commandCtx.projectDir, ctx.commandCtx.exp);
return versionCode !== undefined ? String(versionCode) : undefined;
}
}

function resolveAppIdentifier<T extends Platform>(ctx: BuildContext<T>): string {
if (ctx.platform === Platform.IOS) {
return getBundleIdentifier(ctx.commandCtx.projectDir, ctx.commandCtx.exp);
} else {
return getApplicationId(ctx.commandCtx.projectDir, ctx.commandCtx.exp);
}
}

async function resolveReleaseChannel<T extends Platform>(
ctx: BuildContext<T>
): Promise<string | undefined> {
Expand Down
1 change: 0 additions & 1 deletion packages/eas-cli/src/build/utils/appJson.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// import { ExpoConfig, getConfigFilePaths } from '@expo/config';
import * as ExpoConfig from '@expo/config';
import assert from 'assert';
import fs from 'fs-extra';
Expand Down
2 changes: 1 addition & 1 deletion packages/eas-json/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"author": "Expo <[email protected]>",
"bugs": "https://github.com/expo/eas-cli/issues",
"dependencies": {
"@expo/eas-build-job": "0.2.33",
"@expo/eas-build-job": "0.2.35",
"@hapi/joi": "17.1.1",
"fs-extra": "9.0.1",
"tslib": "1.14.1"
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1181,10 +1181,10 @@
xcode "^3.0.0"
xml-js "^1.6.11"

"@expo/[email protected].33":
version "0.2.33"
resolved "https://registry.yarnpkg.com/@expo/eas-build-job/-/eas-build-job-0.2.33.tgz#fef76ad0acce6cdd828ddc22945184024df05fad"
integrity sha512-OB/ytNkNHI9wydOrhVTrP2XjT0AUzn038eEG4U0QYif2fs1nXUBd6gHM3YNiQjdJtTSXjGpvgBDfNPLIgJHlOQ==
"@expo/[email protected].35":
version "0.2.35"
resolved "https://registry.yarnpkg.com/@expo/eas-build-job/-/eas-build-job-0.2.35.tgz#4e64ebe1314d0af0f33d3922b15d9e3fe415378e"
integrity sha512-+R24ZbZSgC1rLm83pOIUJ8pk2e9e/V6nJBrdl/jLWaCE1YPp1N/Elh8R6x1QuqYyXGOm2AG6r++MGItg9KmggA==
dependencies:
"@hapi/joi" "^17.1.1"

Expand Down