Skip to content
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
8d372ef
tweak publish config
mdjastrzebski Dec 18, 2024
41fd9f0
improve
mdjastrzebski Dec 18, 2024
c598e14
simplify script
mdjastrzebski Dec 18, 2024
44f07f3
adapt gh workflows
mdjastrzebski Dec 19, 2024
c6abeff
.
mdjastrzebski Dec 19, 2024
9bcde38
post only when in PR
mdjastrzebski Dec 19, 2024
55b2f57
.
mdjastrzebski Dec 19, 2024
b8adcfe
.
mdjastrzebski Dec 19, 2024
a629730
.
mdjastrzebski Dec 19, 2024
b15a453
detect project root and ci
mdjastrzebski Dec 12, 2024
a4e6a93
fetch artifact (wip)
mdjastrzebski Dec 13, 2024
46298ac
detect GH remote repo details
mdjastrzebski Dec 17, 2024
cd35fb2
cached build workflow
mdjastrzebski Dec 19, 2024
75227b1
query and download artifact
mdjastrzebski Dec 19, 2024
fb53dfc
update actions
mdjastrzebski Dec 19, 2024
e46a9e0
cleanup logs
mdjastrzebski Dec 19, 2024
3295a59
.
mdjastrzebski Dec 19, 2024
d0798dc
unzip downloaded archive to apk
thymikee Dec 19, 2024
e922395
adjust wording
thymikee Dec 20, 2024
c5e3d57
cleanup zip code
mdjastrzebski Dec 20, 2024
e4ec1a2
eslint ignore dist
mdjastrzebski Dec 20, 2024
4303f7a
.
mdjastrzebski Dec 20, 2024
1247f1f
local caching android
mdjastrzebski Dec 20, 2024
f549041
extract fetchCachedBuild fn
thymikee Dec 21, 2024
25f0941
remove unnecessary binaryPath check
thymikee Dec 21, 2024
98b23ca
parametrize fetchCachedBuild with ci provider
thymikee Dec 21, 2024
06ae444
build android action improvements
mdjastrzebski Dec 23, 2024
4146774
fix ios artifact packing
mdjastrzebski Dec 23, 2024
b930a38
ios fetch cached build
mdjastrzebski Dec 23, 2024
fe246a2
Merge branch 'main' into feat/remote-cache-build
mdjastrzebski Dec 24, 2024
db611b3
remote build caching on iOS simu!
mdjastrzebski Dec 24, 2024
2c90119
use nano-spawn
thymikee Dec 23, 2024
bbda187
update expo fingerprint
mdjastrzebski Dec 24, 2024
1e412b5
fix test
mdjastrzebski Dec 24, 2024
02be174
fix e2e
mdjastrzebski Dec 24, 2024
2c4db97
refactor android
mdjastrzebski Dec 27, 2024
cb0c895
refactor ios
mdjastrzebski Dec 27, 2024
fe6e16c
self code review
mdjastrzebski Dec 27, 2024
0471743
fix test
mdjastrzebski Dec 27, 2024
fa9a202
fix tests, add `--no-remote-build-cache` CLI option
mdjastrzebski Dec 27, 2024
dfbf966
Merge branch 'main' into feat/remote-cache-build
mdjastrzebski Dec 31, 2024
ff4c3ea
code review changes
mdjastrzebski Dec 31, 2024
2c8d0cc
.
mdjastrzebski Dec 31, 2024
0be05fb
.
mdjastrzebski Dec 31, 2024
7038dd8
.
mdjastrzebski Dec 31, 2024
e466d10
.
mdjastrzebski Dec 31, 2024
82c6268
.
mdjastrzebski Dec 31, 2024
1c6c4b8
.
mdjastrzebski Dec 31, 2024
e00317a
git ignore
mdjastrzebski Dec 31, 2024
794d2a8
Merge branch 'main' into feat/remote-cache-build
mdjastrzebski Dec 31, 2024
54ed84f
.
mdjastrzebski Dec 31, 2024
0ed7359
tweak cache location
mdjastrzebski Jan 2, 2025
f59febd
.
mdjastrzebski Jan 2, 2025
b35c6b3
Merge branch 'main' into feat/remote-cache-build
mdjastrzebski Jan 2, 2025
91d72e6
fix lockfile
mdjastrzebski Jan 2, 2025
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
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ NPM_CONFIG_REGISTRY=http://localhost:4873 pnpm create @rnef/app --registry http:
# Then use pnpm install with registry
echo "node-linker=hoisted" > .npmrc
NPM_CONFIG_REGISTRY=http://localhost:4873 pnpm install
# Then link packages (see above)
pnpm link --global ...

# Clean up
pnpm verdaccio-reset
Expand Down
6 changes: 6 additions & 0 deletions nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
"outDir": "packages/{projectRoot}/dist"
}
}
},
"publish:npm": {
"dependsOn": ["build"]
},
"verdaccio:publish": {
"dependsOn": ["build"]
}
},
"release": {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"typecheck": "nx run-many --target typecheck",
"watch": "nx watch --all -- nx run \\$NX_PROJECT_NAME:build",
"link-packages": "node ./scripts/linkPackages.mjs",
"publish:npm": "./scripts/npm-publish.sh",
"verdaccio:init": "node ./scripts/verdaccio-init.mjs",
"verdaccio:publish": "node ./scripts/verdaccio-publish.mjs",
"verdaccio:reset": "./scripts/verdaccio-reset.sh"
Expand Down
4 changes: 4 additions & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
},
"scripts": {
"clean-dist": "rm -f dist/package.json",
"publish:npm": "npm publish --access restricted",
"publish:verdaccio": "npm publish --registry http://localhost:4873 --userconfig ../../.npmrc"
},
"dependencies": {
Expand All @@ -23,5 +24,8 @@
},
"devDependencies": {
"@react-native-community/cli-types": "^16.0.2"
},
"publishConfig": {
"access": "restricted"
}
}
2 changes: 1 addition & 1 deletion packages/cli/src/lib/commands/fingerprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export async function nativeFingerprintCommand(
path = path ?? '.';
const platform = options?.platform ?? 'ios';
const loader = spinner();
logger.debug(`Fingerprinting "${resolveAbsolutePath(path)}"...`);
logger.debug(`Fingerprinting "${resolveAbsolutePath(path)}".`);

let start = 0;
if (logger.isVerbose()) {
Expand Down
4 changes: 4 additions & 0 deletions packages/config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@
},
"scripts": {
"clean-dist": "rm -f dist/package.json",
"publish:npm": "npm publish --access restricted",
"publish:verdaccio": "npm publish --registry http://localhost:4873 --userconfig ../../.npmrc"
},
"dependencies": {
"tslib": "^2.3.0"
},
"publishConfig": {
"access": "restricted"
}
}
4 changes: 4 additions & 0 deletions packages/create-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
],
"scripts": {
"clean-dist": "rm -f dist/package.json",
"publish:npm": "npm publish --access restricted",
"publish:verdaccio": "npm publish --registry http://localhost:4873 --userconfig ../../.npmrc",
"e2e": "vitest --config vite.e2e.config.js"
},
Expand All @@ -30,5 +31,8 @@
"@rnef/test-helpers": "^0.0.1",
"@types/gradient-string": "^1.1.6",
"@types/minimist": "^1.2.5"
},
"publishConfig": {
"access": "restricted"
}
}
2 changes: 2 additions & 0 deletions packages/create-app/src/lib/utils/package-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export function rewritePackageJson(projectPath: string, packageName: string) {
packageJson.version = '1.0.0';
packageJson.private = true;

delete packageJson.publishConfig;

if (packageJson.dependencies) {
packageJson.dependencies = Object.fromEntries(
Object.entries(packageJson.dependencies).sort()
Expand Down
4 changes: 4 additions & 0 deletions packages/plugin-metro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
],
"scripts": {
"clean-dist": "rm -f dist/package.json",
"publish:npm": "npm publish --access restricted",
"publish:verdaccio": "npm publish --registry http://localhost:4873 --userconfig ../../.npmrc"
},
"dependencies": {
Expand All @@ -23,5 +24,8 @@
},
"devDependencies": {
"@rnef/config": "^0.0.1"
},
"publishConfig": {
"access": "restricted"
}
}
4 changes: 4 additions & 0 deletions packages/plugin-platform-android/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
],
"scripts": {
"clean-dist": "rm -f dist/package.json",
"publish:npm": "npm publish --access restricted",
"publish:verdaccio": "npm publish --registry http://localhost:4873 --userconfig ../../.npmrc"
},
"dependencies": {
Expand All @@ -28,5 +29,8 @@
"devDependencies": {
"@react-native-community/cli-types": "^16.0.2",
"@rnef/config": "^0.0.1"
},
"publishConfig": {
"access": "restricted"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const promptForTaskSelection = async (
): Promise<string> => {
const tasks = await getGradleTasks(taskType, sourceDir);
if (!tasks.length) {
throw new Error(`No actionable ${taskType} tasks were found...`);
throw new Error(`No actionable ${taskType} tasks were found.`);
}
const task = checkCancelPrompt<string>(
await select({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,18 @@ import {
AndroidProjectConfig,
Config,
} from '@react-native-community/cli-types';
import { checkCancelPrompt, logger } from '@rnef/tools';
import {
checkCancelPrompt,
downloadGitHubArtifact,
fetchGitHubArtifactsByName,
getProjectRoot,
hasGitHubToken,
logger,
nativeFingerprint,
} from '@rnef/tools';
import { log, outro, select, spinner } from '@clack/prompts';
import color from 'picocolors';
import isInteractive from 'is-interactive';
import { getDevices } from './adb.js';
import { toPascalCase } from '../toPascalCase.js';
import { tryLaunchAppOnDevice } from './tryLaunchAppOnDevice.js';
Expand All @@ -14,8 +25,6 @@ import path from 'path';
import { BuildFlags, options } from '../buildAndroid/buildAndroid.js';
import { promptForTaskSelection } from '../listAndroidTasks.js';
import { runGradle } from '../runGradle.js';
import { outro, select } from '@clack/prompts';
import isInteractive from 'is-interactive';

export interface Flags extends BuildFlags {
appId: string;
Expand Down Expand Up @@ -48,6 +57,17 @@ export async function runAndroid(
? [await promptForTaskSelection(mainTaskType, androidProject.sourceDir)]
: [...(args.tasks ?? []), `${mainTaskType}${toPascalCase(args.mode)}`];

if (!args.binaryPath) {
const cachedBuild = await fetchCachedBuild(
androidProject.sourceDir,
args.mode
);
if (cachedBuild) {
// @todo replace with a more generic way to pass binary path
args.binaryPath = cachedBuild.artifactPath;
}
}

if (deviceId) {
await runGradle({ tasks, androidProject, args });
if (!(await getDevices()).find((d) => d === deviceId)) {
Expand All @@ -64,21 +84,72 @@ export async function runAndroid(
await selectAndLaunchDevice();
} else {
logger.debug(
'No booted devices or emulators found. Launching first available mulator...'
'No booted devices or emulators found. Launching first available mulator.'
);
await tryLaunchEmulator();
}
}

await runGradle({ tasks, androidProject, args });
if (!args.binaryPath) {
await runGradle({ tasks, androidProject, args });
}

for (const device of await getDevices()) {
if (args.binaryPath) {
await tryInstallAppOnDevice(device, androidProject, args, tasks);
}
await tryLaunchAppOnDevice(device, androidProject, args);
}
}
outro('Success 🎉.');
}

export type CachedBuild = {
fingerprint: string;
artifactName: string;
artifactPath: string;
};

// TODO: pass relevant build variables
async function fetchCachedBuild(
sourceDir: string,
mode: string
): Promise<CachedBuild | null> {
const loader = spinner();
loader.start('Checking for cached build');

if (!hasGitHubToken()) {
loader.stop('No GitHub token found, skipping cached build.');
log.warn(
'Please set GITHUB_TOKEN environment variable to use cached builds.'
);
return null;
}

const root = getProjectRoot();
loader.message('Calculating fingerprint');
const fingerprint = await nativeFingerprint(root, { platform: 'android' });

loader.message('Querying cached build');
const artifactName = `app-${mode}-${fingerprint.hash}.apk`;
const artifacts = await fetchGitHubArtifactsByName(artifactName);
if (artifacts.length === 0) {
loader.stop(`No cached build found for hash ${fingerprint.hash}.`);
return null;
}

loader.message('Downloading cached build');
const cachePath = path.join(sourceDir, 'build/cache');
const artifactPath = await downloadGitHubArtifact(artifacts[0], cachePath);
loader.stop(`Downloaded cached build to: ${color.cyan(artifactPath)}`);

return {
fingerprint: fingerprint.hash,
artifactName,
artifactPath,
};
}

async function selectAndLaunchDevice() {
const allDevices = await listAndroidDevices();
const device = await promptForDeviceSelection(allDevices);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export async function tryInstallAppOnDevice(

const adbPath = getAdbPath();
const loader = spinner();
loader.start(`Installing the app on "${device}"...`);
loader.start(`Installing the app on "${device}"`);
const { stderr } = await spawn(adbPath, adbArgs, {
stdio: ['ignore', 'ignore', 'pipe'],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export async function tryLaunchAppOnDevice(
const adbPath = getAdbPath();
logger.debug(`Running ${adbPath} ${adbArgs.join(' ')}.`);
const loader = spinner();
loader.start(`Installing the app on "${device}"...`);
loader.start(`Installing the app on "${device}"`);
const { stderr } = await spawn(adbPath, adbArgs, {
stdio: ['ignore', 'ignore', 'pipe'],
});
Expand Down
12 changes: 7 additions & 5 deletions packages/plugin-platform-android/src/lib/commands/runGradle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ import spawn from 'nano-spawn';
import type { BuildFlags } from './buildAndroid/buildAndroid.js';
import { spinner } from '@clack/prompts';

export type RunGradleArgs = {
tasks: string[];
androidProject: AndroidProject;
args: BuildFlags | Flags;
};

export async function runGradle({
tasks,
androidProject,
args,
}: {
tasks: string[];
androidProject: AndroidProject;
args: BuildFlags | Flags;
}) {
}: RunGradleArgs) {
if ('binaryPath' in args) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ runs:
id: fingerprint
uses: ./.github/actions/rnef-native-fingerprint
with:
platforms: android
platform: android

- name: Find artifact URL
id: cached-url
Expand All @@ -43,7 +43,7 @@ runs:
name: ${{inputs.artifact-name-prefix}}-${{ steps.fingerprint.outputs.hash}}.${{inputs.artifact-name-extension}}

- name: Post Cached Build (if found)
if: steps.cached-url.outputs.artifact-url
if: ${{ steps.cached-url.outputs.artifact-url && github.event_name == 'pull_request' }}
uses: ./.github/actions/rnef-post-build
with:
platform: Android
Expand All @@ -65,10 +65,10 @@ runs:
if: ${{ !steps.cached-url.outputs.artifact-url }}
run: |
cd android
pnpm rnef build:android --tasks assembleDebug
npx rnef build:android --tasks assembleDebug
shell: bash

- name: Upload APK
- name: Upload Artifact
id: upload-artifact
if: ${{ !steps.cached-url.outputs.artifact-url }}
uses: actions/upload-artifact@v4
Expand All @@ -78,7 +78,7 @@ runs:
if-no-files-found: error

- name: Post Build
if: ${{ !steps.cached-url.outputs.artifact-url }}
if: ${{ !steps.cached-url.outputs.artifact-url && github.event_name == 'pull_request' }}
uses: ./.github/actions/rnef-post-build
with:
platform: Android
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ jobs:
cache: 'npm'

- name: Install dependencies
run: npm install
run: |
# Remove next line after public release
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > .npmrc
npm install

- name: RNEF Remote Build - Android
uses: ./.github/actions/rnef-remote-build-android

4 changes: 4 additions & 0 deletions packages/plugin-platform-apple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
],
"scripts": {
"clean-dist": "rm -f dist/package.json",
"publish:npm": "npm publish --access restricted",
"publish:verdaccio": "npm publish --registry http://localhost:4873 --userconfig ../../.npmrc"
},
"dependencies": {
Expand All @@ -27,5 +28,8 @@
},
"devDependencies": {
"@rnef/config": "^0.0.1"
},
"publishConfig": {
"access": "restricted"
}
}
4 changes: 4 additions & 0 deletions packages/plugin-platform-ios/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
],
"scripts": {
"clean-dist": "rm -f dist/package.json",
"publish:npm": "npm publish --access restricted",
"publish:verdaccio": "npm publish --registry http://localhost:4873 --userconfig ../../.npmrc"
},
"dependencies": {
Expand All @@ -23,5 +24,8 @@
},
"devDependencies": {
"@rnef/config": "^0.0.1"
},
"publishConfig": {
"access": "restricted"
}
}
Loading
Loading