Skip to content
Open
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
216 changes: 216 additions & 0 deletions .github/workflows/build-local-libraries.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
name: Build local library
on:
workflow_dispatch:
schedule:
- cron: "0 0 * * *"
push:
branches:
- main
- next
pull_request:
branches:
- main
- next
merge_group:
types:
- checks_requested

permissions:
contents: read

jobs:
build:
env:
XCODE_VERSION: 26
RCT_REMOVE_LEGACY_ARCH: 1
RCT_USE_RN_DEP: 1
RCT_USE_PREBUILT_RNCORE: 1
REACT_NATIVE_VERSION: 0.85.0
EXPO_SDK_VERSION: 55
APP_NAME: LocalLibraryApp
LIBRARY_NAME: TestLibrary
LIBRARY_DIR: modules/TestLibrary

strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macos-15
app:
- community-cli
- expo
type:
- name: turbo-module
language: kotlin-objc
- name: nitro-module
language: kotlin-swift

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.os }}-${{ matrix.app }}-${{ matrix.type.name }}-${{ matrix.type.language }}
cancel-in-progress: true

runs-on: ${{ matrix.os }}

steps:
- name: Checkout
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0

- name: Setup
uses: ./.github/actions/setup

- name: Build package
run: |
yarn workspace create-react-native-library prepare

- name: Create app
shell: bash
run: |
if [[ "${{ matrix.app }}" == "community-cli" ]]; then
npx @react-native-community/cli init "$APP_NAME" \
--directory "$APP_NAME" \
--version "$REACT_NATIVE_VERSION" \
--skip-install \
--skip-git-init \
--pm npm \
--package-name com.locallibraryapp
else
npx create-expo-app@latest "$APP_NAME" \
--no-install \
--template "blank@sdk-$EXPO_SDK_VERSION"
fi

- name: Create local library
working-directory: ${{ env.APP_NAME }}
shell: bash
run: |
../packages/create-react-native-library/bin/create-react-native-library "$LIBRARY_NAME" \
--local \
--directory "$LIBRARY_DIR" \
--slug @bob/react-native-test \
--description test \
--type ${{ matrix.type.name }} \
--languages ${{ matrix.type.language }}

- name: Restore dependencies of app
id: app-npm-cache
uses: actions/cache/restore@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
with:
path: |
${{ env.APP_NAME }}/node_modules
${{ env.APP_NAME }}/package-lock.json
key: ${{ runner.os }}-local-library-npm-${{ matrix.app }}-${{ matrix.type.name }}-${{ matrix.type.language }}-${{ hashFiles(format('{0}/package.json', env.APP_NAME), format('{0}/modules/**/package.json', env.APP_NAME)) }}
restore-keys: |
${{ runner.os }}-local-library-npm-${{ matrix.app }}-${{ matrix.type.name }}-${{ matrix.type.language }}-
${{ runner.os }}-local-library-npm-${{ matrix.app }}-

- name: Install dependencies of app
if: steps.app-npm-cache.outputs.cache-hit != 'true'
working-directory: ${{ env.APP_NAME }}
run: |
npm install --no-audit --no-fund

- name: Cache dependencies of app
if: steps.app-npm-cache.outputs.cache-hit != 'true'
uses: actions/cache/save@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
with:
path: |
${{ env.APP_NAME }}/node_modules
${{ env.APP_NAME }}/package-lock.json
key: ${{ steps.app-npm-cache.outputs.cache-primary-key }}

- name: Generate nitrogen code
if: matrix.type.name == 'nitro-module'
working-directory: ${{ env.APP_NAME }}/${{ env.LIBRARY_DIR }}
shell: bash
run: |
nitro_version=$(node -p "require('../../package.json').dependencies['react-native-nitro-modules']")
npm exec --yes --package "nitrogen@$nitro_version" -- nitrogen

- name: Install JDK
if: runner.os == 'Linux'
uses: actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 # v4.7.1
with:
distribution: 'zulu'
java-version: '17'

- name: Finalize Android SDK
if: runner.os == 'Linux'
run: |
/bin/bash -c "yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --licenses > /dev/null"

- name: Prebuild Expo app (Android)
if: runner.os == 'Linux' && matrix.app == 'expo'
working-directory: ${{ env.APP_NAME }}
run: |
npx expo prebuild --platform android --non-interactive

- name: Cache Gradle
if: runner.os == 'Linux'
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
with:
path: |
~/.gradle/wrapper
~/.gradle/caches
key: ${{ runner.os }}-local-library-gradle-${{ matrix.app }}-${{ hashFiles(format('{0}/android/gradle/wrapper/gradle-wrapper.properties', env.APP_NAME)) }}
restore-keys: |
${{ runner.os }}-local-library-gradle-${{ matrix.app }}-
${{ runner.os }}-local-library-gradle-

- name: Build app (Android)
if: runner.os == 'Linux'
working-directory: ${{ env.APP_NAME }}
shell: bash
env:
JAVA_OPTS: "-XX:MaxHeapSize=6g"
run: |
if [[ "${{ matrix.app }}" == "community-cli" ]]; then
npx react-native build-android --extra-params "--no-daemon --console=plain -PreactNativeArchitectures=arm64-v8a"
else
cd android
./gradlew assembleDebug -DtestBuildType=debug -Dorg.gradle.jvmargs=-Xmx4g -PreactNativeArchitectures=arm64-v8a --no-daemon --console=plain
fi

- name: Use appropriate Xcode version
if: runner.os == 'macOS'
uses: maxim-lobanov/setup-xcode@60606e260d2fc5762a71e64e74b2174e8ea3c8bd # v1.6.0
with:
xcode-version: ${{ env.XCODE_VERSION }}

- name: Prebuild Expo app (iOS)
if: runner.os == 'macOS' && matrix.app == 'expo'
working-directory: ${{ env.APP_NAME }}
run: |
npx expo prebuild --platform ios --non-interactive

- name: Install cocoapods
if: runner.os == 'macOS'
working-directory: ${{ env.APP_NAME }}
shell: bash
run: |
if [[ -f Gemfile ]]; then
bundle install
bundle exec pod repo update --verbose
bundle exec pod install --project-directory=ios
else
pod repo update --verbose
pod install --project-directory=ios
fi

- name: Build app (iOS)
if: runner.os == 'macOS'
working-directory: ${{ env.APP_NAME }}
shell: bash
run: |
if [[ "${{ matrix.app }}" == "community-cli" ]]; then
npx react-native build-ios --mode Debug
else
xcodebuild ONLY_ACTIVE_ARCH=YES \
-workspace "ios/$APP_NAME.xcworkspace" \
-UseNewBuildSystem=YES \
-scheme "$APP_NAME" \
-configuration Debug \
-sdk iphonesimulator \
-derivedDataPath ios/build \
-quiet
fi
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
3 changes: 3 additions & 0 deletions .github/workflows/build-templates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ on:
types:
- checks_requested

permissions:
contents: read

jobs:
build:
env:
Expand Down
2 changes: 1 addition & 1 deletion packages/create-react-native-library/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"github-username": "^9.0.0",
"kleur": "^4.1.5",
"ora": "^9.3.0",
"pigment": "^0.4.4",
"pigment": "^0.4.5",
"typescript": "^6.0.3",
"validate-npm-package-name": "^7.0.2"
},
Expand Down
6 changes: 5 additions & 1 deletion packages/create-react-native-library/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ async function create() {

console.log(''); // Empty new line after prompts

if (answers.directory == null) {
throw new Error('Missing required option: --directory');
}

const bobVersion = await bobVersionPromise;
const nitroModulesVersion =
answers.type === 'nitro-module' || answers.type === 'nitro-view'
Expand Down Expand Up @@ -101,7 +105,7 @@ async function create() {
spinner.text = 'Configuring tools';

await configureTools({
tools: answers.tools,
tools: config.tools,
config,
root: folder,
packageJson: rootPackageJson,
Expand Down
5 changes: 5 additions & 0 deletions packages/create-react-native-library/src/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ export const prompt = create(['[name]'], {
return answers.name;
},
validate: validateDirectory,
required: true,
skip: () => {
const answers = prompt.read();

Expand Down Expand Up @@ -261,6 +262,7 @@ export const prompt = create(['[name]'], {
message: 'What is the name of the package author?',
default: async () => getGitConfig('user.name'),
validate: (input) => Boolean(input) || 'Cannot be empty',
required: true,
skip: (): boolean => prompt.read().local === true,
},
authorEmail: {
Expand All @@ -270,6 +272,7 @@ export const prompt = create(['[name]'], {
default: async () => getGitConfig('user.email'),
validate: (input) =>
/^\S+@\S+$/.test(input) || 'Must be a valid email address',
required: true,
skip: (): boolean => prompt.read().local === true,
},
authorUrl: {
Expand All @@ -296,6 +299,7 @@ export const prompt = create(['[name]'], {
return undefined;
},
validate: (input) => /^https?:\/\//.test(input) || 'Must be a valid URL',
required: true,
skip: (): boolean => prompt.read().local === true,
},
repoUrl: {
Expand All @@ -318,6 +322,7 @@ export const prompt = create(['[name]'], {
return undefined;
},
validate: (input) => /^https?:\/\//.test(input) || 'Must be a valid URL',
required: true,
skip: (): boolean => prompt.read().local === true,
},
type: {
Expand Down
35 changes: 30 additions & 5 deletions packages/create-react-native-library/src/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,31 @@ export function generateTemplateConfiguration({
}): TemplateConfiguration {
const { slug, languages, type } = answers;

let { authorName, authorEmail, authorUrl, repoUrl } = answers;

if (answers.local) {
authorName = '';
authorEmail = '';
authorUrl = '';
repoUrl = '';
} else {
if (authorName == null) {
throw new Error('Missing required option: --author-name');
}

if (authorEmail == null) {
throw new Error('Missing required option: --author-email');
}

if (authorUrl == null) {
throw new Error('Missing required option: --author-url');
}

if (repoUrl == null) {
throw new Error('Missing required option: --repo-url');
}
}

const project = slug.replace(/^(react-native-|@[^/]+\/)/, '');
let namespace: string | undefined;

Expand Down Expand Up @@ -190,13 +215,13 @@ export function generateTemplateConfiguration({
moduleConfig: getModuleConfig(type),
},
author: {
name: answers.authorName,
email: answers.authorEmail,
url: answers.authorUrl,
name: authorName,
email: authorEmail,
url: authorUrl,
},
repo: answers.repoUrl,
repo: repoUrl,
example: answers.example,
tools: answers.tools,
tools: answers.tools ?? [],
year: new Date().getFullYear(),
};
}
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5347,7 +5347,7 @@ __metadata:
github-username: "npm:^9.0.0"
kleur: "npm:^4.1.5"
ora: "npm:^9.3.0"
pigment: "npm:^0.4.4"
pigment: "npm:^0.4.5"
typescript: "npm:^6.0.3"
validate-npm-package-name: "npm:^7.0.2"
bin:
Expand Down Expand Up @@ -10105,13 +10105,13 @@ __metadata:
languageName: node
linkType: hard

"pigment@npm:^0.4.4":
version: 0.4.4
resolution: "pigment@npm:0.4.4"
"pigment@npm:^0.4.5":
version: 0.4.5
resolution: "pigment@npm:0.4.5"
dependencies:
ansi-escapes: "npm:^7.2.0"
wrap-ansi: "npm:^9.0.2"
checksum: 10c0/d2663d4e44603ed4bdab7b1c7c73c0c8a42390599c7f7f880dc91b2cb00f252667e9e22606ca7c56db6bd36e4a6067e68141afd17d1e7d03867da8866bde5bb0
checksum: 10c0/696ba9feee6f22d59de62a37e31ced40845dc061c78175b18805eb9550215685e5fd6612e355025742152d8bc093b56ef258044e5dae7265d781cd2b353b3aac
languageName: node
linkType: hard

Expand Down
Loading