Skip to content

Commit

Permalink
rename lazyUpload to asyncUpload
Browse files Browse the repository at this point in the history
  • Loading branch information
michalziolkowski committed Mar 25, 2024
1 parent dfbbbf7 commit e37ec07
Show file tree
Hide file tree
Showing 10 changed files with 2,873 additions and 2,767 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/on_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
# uses: ./.
# with:
# config: examples/expo-example/sherlo.config.json
# lazyUpload: true
# asyncUpload: true
# env:
# SHERLO_TOKEN: ${{ secrets.SHERLO_TOKEN }}

Expand Down
7 changes: 6 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ inputs:
config:
description: 'path to your sherlo.config.ts file'
required: false
lazyUpload:
asyncUpload:
description: 'if 'true' you don't need to provide android and ios builds, they can be uploaded independently with separate action'
required: false
default: false
outputs:
buildIndex:
description: 'The index of the created Sherlo build'
url:
description: 'URL to Sherlo test results'
2 changes: 0 additions & 2 deletions examples/expo-example/.gitattributes

This file was deleted.

4 changes: 2 additions & 2 deletions examples/expo-example/eas-hooks/eas-build-on-success.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ if [[ "$EAS_BUILD_PROFILE" == "preview" ]]; then
android_path="android/app/build/outputs/apk/release/app-release.apk"
fi

yarn sherlo --lazyUploadCommitHash=$EAS_BUILD_GIT_COMMIT_HASH --token=$SHERLO_TOKEN --android=$android_path
yarn sherlo --asyncUploadCommitHash=$EAS_BUILD_GIT_COMMIT_HASH --token=$SHERLO_TOKEN --android=$android_path
fi

if [[ "$EAS_BUILD_PLATFORM" == "ios" ]]; then
Expand All @@ -59,7 +59,7 @@ if [[ "$EAS_BUILD_PROFILE" == "preview" ]]; then
ios_path=$(find ios/build/Build/Products/Release-iphonesimulator -name "*.app" -print -quit)
fi

yarn sherlo --lazyUploadCommitHash=$EAS_BUILD_GIT_COMMIT_HASH --token=$SHERLO_TOKEN --ios=$ios_path
yarn sherlo --asyncUploadCommitHash=$EAS_BUILD_GIT_COMMIT_HASH --token=$SHERLO_TOKEN --ios=$ios_path
fi
fi

Expand Down
5,496 changes: 2,760 additions & 2,736 deletions packages/action/release/index.js

Large diffs are not rendered by default.

15 changes: 12 additions & 3 deletions packages/action/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ async function run(): Promise<void> {
const android: string = core.getInput('android', { required: false });
const ios: string = core.getInput('ios', { required: false });
const config: string = core.getInput('config', { required: false });
const lazyUpload: boolean = core.getInput('lazyUpload', { required: false }) === 'true';
const projectRoot: string = core.getInput('projectRoot', { required: false });
const asyncUploadBuildIndex: string = core.getInput('asyncUploadBuildIndex', {
required: false,
});
const asyncUpload: boolean = core.getInput('asyncUpload', { required: false }) === 'true';

const { context } = github;

Expand All @@ -34,14 +38,19 @@ async function run(): Promise<void> {
break;
}

await uploadAndTest({
const { buildIndex, url } = await uploadAndTest({
android,
ios,
config,
lazyUpload,
asyncUpload,
asyncUploadBuildIndex,
projectRoot,
token: process.env.SHERLO_TOKEN || undefined,
gitInfo,
});

core.setOutput('buildIndex', buildIndex);
core.setOutput('url', url);
} catch (error) {
if (error instanceof Error) core.setFailed(error.message);
}
Expand Down
46 changes: 46 additions & 0 deletions packages/cli/eas-hooks/eas-build-on-success.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env bash

# Fail if anything errors
set -eox pipefail

# Build lifecycle hooks: https://docs.expo.dev/build-reference/npm-hooks/
# List of available environment variables: https://docs.expo.dev/build-reference/variables/#built-in-environment-variables
# How to add secrets to environment variables: https://docs.expo.dev/build-reference/variables/#using-secrets-in-environment-variables

# We only execute this command if the build runner is EAS Build
# If user builds the app localy they need to manually choose when to run Sherlo tests
if [[ "$EAS_BUILD_RUNNER" != "eas-build" ]]; then
exit
fi

if [[ "$EAS_BUILD_PROFILE" == "preview" ]]; then

if [[ "$EAS_BUILD_PLATFORM" == "android" ]]; then
# Install jq to parse JSON
sudo apt-get install jq -y

# Details on Android build paths: https://docs.expo.dev/build-reference/android-builds/
android_path=$(jq -r '.builds.android."'"$EAS_BUILD_PROFILE"'"."applicationArchivePath"' eas.json)
if [[ -z "$android_path" || "$android_path" == "null" ]]; then
android_path="android/app/build/outputs/apk/release/app-release.apk"
fi

yarn sherlo --asyncUploadCommitHash=$EAS_BUILD_GIT_COMMIT_HASH --token=$SHERLO_TOKEN --android=$android_path
fi

if [[ "$EAS_BUILD_PLATFORM" == "ios" ]]; then
# Install jq to parse JSON
brew update
brew install jq

# Details on iOS build paths: https://docs.expo.dev/build-reference/ios-builds/
ios_path=$(jq -r '.builds.ios."'"$EAS_BUILD_PROFILE"'"."applicationArchivePath"' eas.json)
if [[ -z "$ios_path" || "$ios_path" == "null" ]]; then
ios_path=$(find ios/build/Build/Products/Release-iphonesimulator -name "*.app" -print -quit)
fi

yarn sherlo --asyncUploadCommitHash=$EAS_BUILD_GIT_COMMIT_HASH --token=$SHERLO_TOKEN --ios=$ios_path
fi
fi


46 changes: 35 additions & 11 deletions packages/cli/src/commands/uploadAndTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,19 @@ import {
uploadMobileBuilds,
} from '../utils';
import { GetConfigParameters } from '../utils/getConfig/getConfig';
import fs from 'fs';
import { Build } from '@sherlo/api-types';
import path from 'path';

const DEFAULT_CONFIG_PATH = 'sherlo.config.json';

async function uploadAndTest(
parameters?: Partial<GetConfigParameters> & { gitInfo?: Build['gitInfo'] }
): Promise<void> {
parameters?: Partial<GetConfigParameters> & {
gitInfo?: Build['gitInfo'];
projectRoot?: string;
asyncUploadBuildIndex?: number;
}
): Promise<{ buildIndex: number; url: string }> {
try {
printHeader();

Expand All @@ -29,12 +35,18 @@ async function uploadAndTest(
description: 'Path to Sherlo config',
type: 'string',
})
.option('lazyUpload', {
.option('asyncUpload', {
default: false,
description:
'Run Sherlo in lazy upload mode, meaning you don’t have to provide builds immidiately. You can send them with the same command later on',
type: 'boolean',
})
.option('projectRoot', {
default: '.',
description:
'use this option to specify the root of the react native project when working with monorepo',
type: 'string',
})
.option('token', {
description: 'Sherlo project token',
type: 'string',
Expand All @@ -48,8 +60,11 @@ async function uploadAndTest(
type: 'string',
}).argv;

const asyncUpload = parameters?.asyncUpload || args.asyncUpload;
const projectRoot = parameters?.projectRoot || args.projectRoot;

const config = await getConfig({
lazyUpload: parameters?.lazyUpload || args.lazyUpload,
asyncUpload,
config: parameters?.config || args.config,
token: parameters?.token || args.token,
ios: parameters?.ios || args.ios,
Expand Down Expand Up @@ -93,13 +108,22 @@ async function uploadAndTest(
throw new Error(getErrorMessage({ type: 'unexpected', message: error.message }));
});

console.log(
`View your test results at: https://app.sherlo.io/build?${getUrlParams({
teamId,
projectIndex,
buildIndex: build.index,
})}\n`
);
const url = `https://app.sherlo.io/build?${getUrlParams({
teamId,
projectIndex,
buildIndex: build.index,
})}`;

const output = { buildIndex: build.index, url };

const expoDir = path.join(projectRoot, '.expo');
if (asyncUpload && fs.existsSync(expoDir)) {
fs.writeFileSync(path.join(expoDir, 'sherlo.json'), JSON.stringify(output));
}

console.log(`View your test results at: ${url}\n`);

return output;
} catch (error) {
console.error((error as Error).message);
} finally {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/utils/getConfig/getConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface GetConfigParameters {
token?: string;
android?: string;
ios?: string;
lazyUpload?: boolean;
asyncUpload?: boolean;
}

async function getConfig(parameters: GetConfigParameters): Promise<Config> {
Expand All @@ -26,7 +26,7 @@ async function getConfig(parameters: GetConfigParameters): Promise<Config> {
config.token = parameters.token;
}

if (validate(config, parameters.lazyUpload)) {
if (validate(config, parameters.asyncUpload)) {
return config;
}

Expand Down
18 changes: 9 additions & 9 deletions packages/cli/src/utils/getConfig/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import getErrorMessage from '../getErrorMessage';
import getProjectTokenParts from '../getProjectTokenParts';
import getConfigErrorMessage from './getConfigErrorMessage';

function validate(config: InvalidatedConfig, lazyUpload?: boolean): config is Config {
function validate(config: InvalidatedConfig, asyncUpload?: boolean): config is Config {
validateProjectToken(config);

validatePlatforms(config, lazyUpload);
validatePlatforms(config, asyncUpload);

validateFilters(config);

Expand Down Expand Up @@ -48,25 +48,25 @@ function validateProjectToken({ token }: InvalidatedConfig): void {
}
}

function validatePlatforms(config: InvalidatedConfig, lazyUpload?: boolean): void {
function validatePlatforms(config: InvalidatedConfig, asyncUpload?: boolean): void {
const { android, ios } = config;

if (!android && !ios) {
throw new Error(getConfigErrorMessage('at least one of the platforms must be defined'));
}

if (android) validatePlatform(config, 'android', lazyUpload);
if (android) validatePlatform(config, 'android', asyncUpload);

if (ios) validatePlatform(config, 'ios', lazyUpload);
if (ios) validatePlatform(config, 'ios', asyncUpload);
}

function validatePlatform(
config: InvalidatedConfig,
platform: Platform,
lazyUpload?: boolean
asyncUpload?: boolean
): void {
validatePlatformSpecificParameters(config, platform);
validatePlatformPath(config, platform, lazyUpload);
validatePlatformPath(config, platform, asyncUpload);
validatePlatformDevices(config, platform);
}

Expand Down Expand Up @@ -129,12 +129,12 @@ function validatePlatformSpecificParameters(config: InvalidatedConfig, platform:
function validatePlatformPath(
config: InvalidatedConfig,
platform: Platform,
lazyUpload?: boolean
asyncUpload?: boolean
): void {
const { path: platformPath } = config[platform] ?? {};

if (!platformPath || typeof platformPath !== 'string') {
if (lazyUpload) return;
if (asyncUpload) return;

throw new Error(
getConfigErrorMessage(`for ${platform}, path must be defined string`, learnMoreLink[platform])
Expand Down

0 comments on commit e37ec07

Please sign in to comment.