diff --git a/.ado/scripts/export-versions.mjs b/.ado/scripts/export-versions.mjs deleted file mode 100644 index 53fb6ae28323..000000000000 --- a/.ado/scripts/export-versions.mjs +++ /dev/null @@ -1,27 +0,0 @@ -// @ts-check -import * as fs from "node:fs"; -import { URL } from "node:url"; - -/** - * @param {string} version - * @returns {string} - */ -function coerce(version) { - const [major, minor = 0] = version.split("-")[0].split("."); - return `${major}.${minor}`; -} - -/** - * @param {string} name - * @param {unknown} value - */ -function exportValue(name, value) { - console.log(`##vso[task.setvariable variable=${name}]${value}`); -} - -const manifestPath = new URL("../../packages/react-native/package.json", import.meta.url); -const json = fs.readFileSync(manifestPath, { encoding: "utf-8" }); -const { dependencies, peerDependencies } = JSON.parse(json); - -exportValue("react_version", peerDependencies["react"]); -exportValue("react_native_version", coerce(dependencies["@react-native/codegen"])); diff --git a/.github/scripts/export-versions.mts b/.github/scripts/export-versions.mts new file mode 100644 index 000000000000..fe9734081b05 --- /dev/null +++ b/.github/scripts/export-versions.mts @@ -0,0 +1,35 @@ +#!/usr/bin/env node +/** + * Export react and react-native version information from packages/react-native/package.json. + * + * Outputs (written to $GITHUB_OUTPUT): + * react_version – the React peer dependency version (e.g. "19.0.0") + * react_native_version – the coerced major.minor React Native version (e.g. "0.79") + */ +import * as fs from "node:fs"; +import { URL } from "node:url"; + +function coerce(version: string): string { + const [major, minor = "0"] = version.split("-")[0].split("."); + return `${major}.${minor}`; +} + +function exportValue(name: string, value: string): void { + const githubOutput = process.env.GITHUB_OUTPUT; + if (githubOutput) { + fs.appendFileSync(githubOutput, `${name}=${value}\n`); + } else { + // Fallback: print to stdout for local debugging + console.log(`${name}=${value}`); + } +} + +const manifestPath = new URL( + "../../packages/react-native/package.json", + import.meta.url +); +const json = fs.readFileSync(manifestPath, { encoding: "utf-8" }); +const { dependencies, peerDependencies } = JSON.parse(json); + +exportValue("react_version", peerDependencies["react"]); +exportValue("react_native_version", coerce(dependencies["@react-native/codegen"])); diff --git a/.github/workflows/microsoft-pr.yml b/.github/workflows/microsoft-pr.yml index 157cd8b05fa2..2566b0ec5f44 100644 --- a/.github/workflows/microsoft-pr.yml +++ b/.github/workflows/microsoft-pr.yml @@ -143,13 +143,11 @@ jobs: if: ${{ endsWith(github.base_ref, '-stable') }} uses: ./.github/workflows/microsoft-test-react-native-macos-init.yml - # https://github.com/microsoft/react-native-macos/issues/2344 - # Disable these tests because verdaccio hangs - # react-native-test-app-integration: - # name: "Test react-native-test-app integration" - # permissions: {} - # if: ${{ endsWith(github.base_ref, '-stable') }} - # uses: ./.github/workflows/microsoft-react-native-test-app-integration.yml + react-native-test-app-integration: + name: "Test react-native-test-app integration" + permissions: {} + if: ${{ endsWith(github.base_ref, '-stable') }} + uses: ./.github/workflows/microsoft-react-native-test-app-integration.yml PR: name: "PR" @@ -164,7 +162,7 @@ jobs: - build-rntester - prebuild-macos-core - test-react-native-macos-init - # - react-native-test-app-integration + - react-native-test-app-integration steps: - name: Check for failures or cancellations if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }} diff --git a/.github/workflows/microsoft-react-native-test-app-integration.yml b/.github/workflows/microsoft-react-native-test-app-integration.yml index 8725a42a9cd0..654dca3a4814 100644 --- a/.github/workflows/microsoft-react-native-test-app-integration.yml +++ b/.github/workflows/microsoft-react-native-test-app-integration.yml @@ -25,64 +25,77 @@ jobs: run: yarn install - name: Build community CLI plugin - run: yarn build + run: | + yarn build + # yarn build rewrites package.json exports; restore them + git checkout -- packages/*/package.json - name: Build react-native-macos-init working-directory: packages/react-native-macos-init run: yarn build - - name: Start Verdaccio server - run: | - set -euo pipefail - nohup npx --yes verdaccio --config .ado/verdaccio/config.yaml >/dev/null 2>&1 & - echo $! > $RUNNER_TEMP/verdaccio.pid - - name: Wait for Verdaccio to be ready - run: node .ado/scripts/waitForVerdaccio.mjs http://localhost:4873 - - - name: Configure npm for Verdaccio - run: .ado/scripts/verdaccio.sh init + - name: Export versions + id: versions + run: node .github/scripts/export-versions.mts - - name: Publish to Verdaccio - run: .ado/scripts/verdaccio.sh publish --branch origin/${{ github.base_ref }} + - name: Pack local react-native-macos + working-directory: packages/react-native + run: | + set -eox pipefail + yarn pack -o ${{ runner.temp }}/react-native-macos.tgz - name: Clone react-native-test-app run: | git clone --filter=blob:none --progress https://github.com/microsoft/react-native-test-app.git - - name: Export versions - run: node .ado/scripts/export-versions.mjs - - name: Configure react-native-test-app dependencies + working-directory: react-native-test-app/packages/app + run: | + node scripts/internal/set-react-version.mts ${{ steps.versions.outputs.react_native_version }} --overrides '{ "react-native-macos": "file:${{ runner.temp }}/react-native-macos.tgz" }' + + - name: Force react-native-macos to local tarball in all workspaces working-directory: react-native-test-app run: | - npm run set-react-version $(cat ${{ github.workspace }}/.react_native_version) -- --overrides '{ "react-native-macos": "1000.0.0" }' + node -e " + const fs = require('fs'); + const tarball = 'file:${{ runner.temp }}/react-native-macos.tgz'; + + // Add root-level resolution + const root = JSON.parse(fs.readFileSync('package.json', 'utf8')); + root.resolutions = root.resolutions || {}; + root.resolutions['react-native-macos'] = tarball; + fs.writeFileSync('package.json', JSON.stringify(root, null, 2) + '\n'); + + // Override direct dependency in example-macos + const exMacosPath = 'packages/example-macos/package.json'; + const exMacos = JSON.parse(fs.readFileSync(exMacosPath, 'utf8')); + if (exMacos.dependencies && exMacos.dependencies['react-native-macos']) { + exMacos.dependencies['react-native-macos'] = tarball; + fs.writeFileSync(exMacosPath, JSON.stringify(exMacos, null, 2) + '\n'); + } + " - name: Install dependencies in test app working-directory: react-native-test-app + env: + YARN_ENABLE_HARDENED_MODE: 0 + YARN_NPM_MINIMAL_AGE_GATE: 0 run: | set -eo pipefail - ${{ github.workspace }}/.ado/scripts/verdaccio.sh configure yarn --no-immutable - name: Bundle JavaScript - working-directory: react-native-test-app/example + working-directory: react-native-test-app/packages/example-macos run: | yarn build:macos || yarn build:macos - name: Install Pods - working-directory: react-native-test-app/example + working-directory: react-native-test-app/packages/example-macos run: | rm -f macos/Podfile.lock pod install --project-directory=macos - name: Build test app - working-directory: react-native-test-app/example - run: | - ../scripts/build/xcodebuild.sh macos/Example.xcworkspace build - - - name: Stop Verdaccio - if: always() + working-directory: react-native-test-app/packages/example-macos run: | - if [ -f "$RUNNER_TEMP/verdaccio.pid" ]; then - kill "$(cat $RUNNER_TEMP/verdaccio.pid)" || true - fi + ../../scripts/xcodebuild.sh macos/Example.xcworkspace build