Skip to content

Commit d7dccdc

Browse files
committed
detect version
1 parent 9f11c4b commit d7dccdc

5 files changed

Lines changed: 68 additions & 98 deletions

File tree

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
name: Create React Native Test App
22
description: Initializes a new test app
33
inputs:
4-
platform:
5-
description: The platform to create a test app for
4+
arguments:
65
required: true
76
runs:
87
using: composite
@@ -13,14 +12,10 @@ runs:
1312
shell: bash
1413
- name: Install
1514
run: |
16-
scripts/install-test-template.sh ${{ inputs.platform }}
15+
scripts/install-test-template.sh --version highest ${{ inputs.arguments }}
1716
shell: bash
1817
- name: Initialize a new app
1918
run: |
20-
if [[ ${{ inputs.platform }} == "all" ]]; then
21-
yarn init-test-app --destination test-app --name TestApp -p android -p ios -p macos -p visionos -p windows
22-
else
23-
yarn init-test-app --destination test-app --name TestApp --platform ${{ inputs.platform }}
24-
fi
19+
yarn init-test-app --destination test-app --name TestApp ${{ inputs.arguments }}
2520
shell: bash
2621
working-directory: template-example

.github/actions/setup-toolchain/action.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,16 @@ runs:
6868
jdks
6969
- name: Set up MSBuild
7070
if: ${{ inputs.platform == 'windows' }}
71-
uses: microsoft/setup-msbuild@v2
71+
uses: microsoft/setup-msbuild@v3
7272
- name: Set up Ruby
7373
if: ${{ runner.os != 'Windows' }}
7474
uses: ruby/setup-ruby@v1
7575
with:
76-
ruby-version: "3.2.3"
76+
ruby-version: "3.3.11"
7777
bundler: Gemfile.lock
7878
bundler-cache: true
7979
- name: Set up Node.js
80-
uses: actions/setup-node@v6.3.0
80+
uses: actions/setup-node@v6
8181
with:
8282
node-version: ${{ inputs.node-version }}
8383
cache: ${{ inputs.cache-npm-dependencies }}

.github/workflows/build.yml

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,6 @@ jobs:
212212
ios-template:
213213
name: "iOS [template]"
214214
permissions: {}
215-
strategy:
216-
matrix:
217-
template: [all, ios]
218215
runs-on: macos-15
219216
if: ${{ github.event_name != 'schedule' }}
220217
steps:
@@ -233,7 +230,7 @@ jobs:
233230
- name: Initialize test app
234231
uses: ./.github/actions/init-test-app
235232
with:
236-
platform: ${{ matrix.template }}
233+
arguments: -p android -p ios
237234
- name: Bundle JavaScript
238235
run: |
239236
yarn build:ios
@@ -310,7 +307,6 @@ jobs:
310307
permissions: {}
311308
strategy:
312309
matrix:
313-
template: [all, android]
314310
runner: [ubuntu-24.04, windows-2025]
315311
runs-on: ${{ matrix.runner }}
316312
if: ${{ github.event_name != 'schedule' }}
@@ -326,7 +322,7 @@ jobs:
326322
- name: Initialize test app
327323
uses: ./.github/actions/init-test-app
328324
with:
329-
platform: ${{ matrix.template }}
325+
arguments: -p android -p ios
330326
- name: Bundle JavaScript
331327
run: |
332328
yarn build:android
@@ -405,9 +401,6 @@ jobs:
405401
macos-template:
406402
name: "macOS [template]"
407403
permissions: {}
408-
strategy:
409-
matrix:
410-
template: [all, macos]
411404
runs-on: macos-15
412405
if: ${{ github.event_name != 'schedule' }}
413406
steps:
@@ -426,7 +419,7 @@ jobs:
426419
- name: Initialize test app
427420
uses: ./.github/actions/init-test-app
428421
with:
429-
platform: ${{ matrix.template }}
422+
arguments: -p macos
430423
- name: Bundle JavaScript
431424
run: |
432425
yarn build:macos
@@ -502,9 +495,6 @@ jobs:
502495
visionos-template:
503496
name: "visionOS [template]"
504497
permissions: {}
505-
strategy:
506-
matrix:
507-
template: [all, visionos]
508498
runs-on: macos-15
509499
if: false # visionOS temporarily disabled until releases are resumed
510500
steps:
@@ -523,7 +513,7 @@ jobs:
523513
- name: Initialize test app
524514
uses: ./.github/actions/init-test-app
525515
with:
526-
platform: ${{ matrix.template }}
516+
arguments: -p visionos
527517
- name: Bundle JavaScript
528518
run: |
529519
yarn build:visionos
@@ -636,9 +626,6 @@ jobs:
636626
permissions: {}
637627
runs-on: windows-2025
638628
if: ${{ github.event_name != 'schedule' }}
639-
strategy:
640-
matrix:
641-
template: [all, windows]
642629
steps:
643630
- name: Checkout
644631
uses: actions/checkout@v6
@@ -653,7 +640,7 @@ jobs:
653640
- name: Initialize test app
654641
uses: ./.github/actions/init-test-app
655642
with:
656-
platform: ${{ matrix.template }}
643+
arguments: -p windows --version 0.82.3
657644
- name: Bundle JavaScript
658645
run: |
659646
yarn build:windows
@@ -775,7 +762,7 @@ jobs:
775762
runs-on: ubuntu-24.04
776763
steps:
777764
- name: Label
778-
uses: actions/labeler@v6.0.1
765+
uses: actions/labeler@v6
779766
with:
780767
repo-token: ${{ secrets.GITHUB_TOKEN }}
781768
sync-labels: true

packages/app/scripts/init.mjs

Lines changed: 53 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -45,46 +45,10 @@ const getInstalledVersion = memo(() => {
4545
});
4646

4747
/**
48-
* Returns the desired `react-native` version.
49-
*
50-
* Checks the following in order:
51-
*
52-
* - Command line flag, e.g. `--version 0.81`
53-
* - Currently installed `react-native` version
54-
* - Latest version from npm
55-
*
5648
* @param {import("./types.js").Platform[]} platforms
5749
* @returns {Promise<string>}
5850
*/
59-
async function getVersion(platforms) {
60-
const index = process.argv.lastIndexOf("--version");
61-
if (index >= 0) {
62-
const m = process.argv[index + 1].match(/(\d+\.\d+[-.0-9a-z]*)/);
63-
if (!m) {
64-
throw new Error(
65-
"Expected version number of the form <major>.<minor>.<patch>-<prerelease> (where patch and prerelease are optional)"
66-
);
67-
}
68-
return m[1];
69-
}
70-
71-
/** @type {(version: string, reason: string) => void} */
72-
const logVersion = (version, reason) => {
73-
const bVersionFlag = colors.bold("--version");
74-
const bTarget = colors.bold(version);
75-
console.log(
76-
`Using ${bTarget} because ${reason} (use ${bVersionFlag} to specify another version)`
77-
);
78-
};
79-
80-
const version = getInstalledVersion();
81-
if (version) {
82-
logVersion(version, "the current project uses it");
83-
return version;
84-
}
85-
86-
console.log("No version was specified; fetching available versions...");
87-
51+
async function getLatestCommonVersion(platforms) {
8852
let maxSupportedVersion = Number.MAX_VALUE;
8953
for (const p of platforms) {
9054
const pkgName = getDefaultPlatformPackageName(p);
@@ -103,7 +67,58 @@ async function getVersion(platforms) {
10367
const major = Math.trunc(maxSupportedVersion / 1000);
10468
const minor = maxSupportedVersion % 1000;
10569

106-
const target = major + "." + minor;
70+
return major + "." + minor;
71+
}
72+
73+
/**
74+
* @param {string} version
75+
* @param {string} reason
76+
* @returns {void}
77+
*/
78+
function logVersion(version, reason) {
79+
const bVersionFlag = colors.bold("--version");
80+
const bTarget = colors.bold(version);
81+
console.log(
82+
`Using ${bTarget} because ${reason} (use ${bVersionFlag} to specify another version)`
83+
);
84+
}
85+
86+
/**
87+
* Returns the desired `react-native` version.
88+
*
89+
* Checks the following in order:
90+
*
91+
* - Command line flag, e.g. `--version 0.81`
92+
* - Currently installed `react-native` version
93+
* - Latest version from npm
94+
*
95+
* @param {import("./types.js").Platform[]} platforms
96+
* @returns {Promise<string>}
97+
*/
98+
async function getVersion(platforms) {
99+
const index = process.argv.lastIndexOf("--version");
100+
const input = index >= 0 && process.argv[index + 1];
101+
if (input !== "highest") {
102+
if (input) {
103+
const m = input.match(/(\d+\.\d+[-.0-9a-z]*)/);
104+
if (!m) {
105+
throw new Error(
106+
"Expected version number of the form <major>.<minor>.<patch>-<prerelease> (where patch and prerelease are optional)"
107+
);
108+
}
109+
return m[1];
110+
} else {
111+
const installedVersion = getInstalledVersion();
112+
if (installedVersion) {
113+
logVersion(installedVersion, "the current project uses it");
114+
return installedVersion;
115+
}
116+
}
117+
118+
console.log("No version was specified; fetching available versions...");
119+
}
120+
121+
const target = await getLatestCommonVersion(platforms);
107122
logVersion(target, "it supports all specified platforms");
108123

109124
return target;

scripts/install-test-template.sh

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22
set -eo pipefail
33

44
install=true
5-
platforms=(all android ios macos visionos windows)
65
version=$(node --print 'require("./package.json").version')
76
tarball=react-native-test-app-$version.$(git rev-parse --short HEAD).tgz
87

98
current_dir="$(pwd)"
109
script_dir="$(cd -P "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" >/dev/null 2>&1 && pwd)"
1110

1211
function print_usage {
13-
echo "usage: $(basename "$0") [-u] <$(IFS=\|; echo "${platforms[*]}")>"
12+
echo "usage: $(basename "$0") [-u] ..."
1413
}
1514

1615
while true; do
@@ -24,12 +23,6 @@ while true; do
2423
shift
2524
;;
2625
*)
27-
if [[ ! " ${platforms[*]} " =~ " $1 " ]]; then
28-
[[ -n "$1" ]] && echo "invalid platform: $1"
29-
print_usage
30-
exit 1
31-
fi
32-
platform=$1
3326
break
3427
;;
3528
esac
@@ -44,33 +37,13 @@ popd 1> /dev/null
4437
yarn
4538

4639
v=$(cat packages/app/example/package.json | jq '.dependencies["react-native"]' | grep -o -E '[0-9]+\.[0-9]+')
47-
if [[ "$platform" == "all" ]]; then
48-
node packages/app/scripts/init.mjs \
49-
--destination template-example \
50-
--name TemplateExample \
51-
--platform android \
52-
--platform ios \
53-
--platform macos \
54-
--platform visionos \
55-
--platform windows \
56-
--version $v
57-
else
58-
node packages/app/scripts/init.mjs \
59-
--destination template-example \
60-
--name TemplateExample \
61-
--platform "$platform" \
62-
--version $v
63-
fi
40+
node packages/app/scripts/init.mjs --destination template-example --name TemplateExample --version $v $@
6441

6542
pushd template-example 1> /dev/null
6643
node "$script_dir/copy-yarnrc.mjs" ../.yarnrc.yml
6744

6845
# Workaround for NuGet publishing failures
69-
if [[ "$platform" == "all" ]] || [[ "$platform" == "windows" ]]; then
70-
cp ../yarn.lock .
71-
else
72-
touch yarn.lock
73-
fi
46+
cp ../yarn.lock .
7447

7548
script="s/\"react-native-test-app\": \".*\"/\"react-native-test-app\": \"..\/packages\/app\/$tarball\"/"
7649
if sed --version &> /dev/null; then

0 commit comments

Comments
 (0)