Skip to content

Commit

Permalink
ci: fix the react-native-macos-init pipeline (#2228)
Browse files Browse the repository at this point in the history
* ci: fix the `react-native-macos-init` pipeline

The pipeline wasn't actually publishing anything and we've been testing
against latest on npm all this time.

* fix(react-native): `xcodeProject.path` may not always be present
  • Loading branch information
tido64 authored and Saadnajmi committed Nov 14, 2024
1 parent 670f23e commit d0fa160
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 58 deletions.
101 changes: 55 additions & 46 deletions .ado/jobs/test-react-native-macos-init.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
jobs:
- job: CliInit
displayName: Verify react-native-macos-init
displayName: Verify react-native-macos in a new project
pool:
vmImage: $(VmImageApple)
steps:
Expand All @@ -13,50 +13,59 @@ jobs:

- template: /.ado/templates/apple-tools-setup.yml@self

- script: |
set -eox pipefail
yarn install
displayName: Install npm dependencies
- script: |
set -eox pipefail
yarn build
displayName: Build @react-native/community-cli-plugin
- script: |
set -eox pipefail
yarn build
workingDirectory: packages/react-native-macos-init
displayName: Build react-native-macos-init
- template: /.ado/templates/verdaccio-init.yml@self

- template: /.ado/templates/verdaccio-publish.yml@self

# First do a build of the local package, since we point the cli at the local files, it needs to be pre-built
- task: CmdLine@2
displayName: yarn install (local react-native-macos)
inputs:
script: yarn install --immutable

- task: CmdLine@2
displayName: yarn install (local react-native-macos-init)
inputs:
script: |
cd packages/react-native-macos-init
yarn install --immutable
- task: CmdLine@2
displayName: yarn build (local react-native-macos-init)
inputs:
script: |
cd packages/react-native-macos-init
yarn build
- task: CmdLine@2
displayName: Init new project
inputs:
script: npx --yes react-native@0.71.5 init testcli --template react-native@0.71.5 --skip-install
workingDirectory: $(Agent.BuildDirectory)

- task: CmdLine@2
displayName: yarn install (local react-native-macos-init)
inputs:
script: yarn install --immutable
workingDirectory: $(Agent.BuildDirectory)/testcli

- task: CmdLine@2
displayName: Apply macos template
inputs:
script: npx react-native-macos-init --version latest --overwrite --prerelease
workingDirectory: $(Agent.BuildDirectory)/testcli

- task: CmdLine@2
displayName: Run macos [test]
inputs:
script: npx react-native run-macos
workingDirectory: $(Agent.BuildDirectory)/testcli
- script: |
.ado/scripts/verdaccio.sh publish --branch origin/$(System.PullRequest.TargetBranch)
displayName: Publish react-native-macos to Verdaccio
- script: |
set -eox pipefail
npx --yes @react-native-community/cli init testcli --version 0.75 --skip-install
workingDirectory: $(Agent.BuildDirectory)
displayName: Initialize a new project
- script: |
set -eox pipefail
yarn install --mode=update-lockfile
# `update-lockfile` skips the linking step, so we need to run `yarn install` again
yarn install
workingDirectory: $(Agent.BuildDirectory)/testcli
displayName: Install npm dependencies (new project)
- script: |
set -eox pipefail
# We need to set the npm registry here otherwise it won't stick
$(Build.Repository.LocalPath)/.ado/scripts/verdaccio.sh configure
node $(Build.Repository.LocalPath)/packages/react-native-macos-init/bin.js --verbose --version latest --overwrite --prerelease
yarn why react-native-macos
workingDirectory: $(Agent.BuildDirectory)/testcli
displayName: Apply macOS template (new project)
- script: |
set -eox pipefail
npx react-native build-macos
workingDirectory: $(Agent.BuildDirectory)/testcli
displayName: Build macOS app (new project)
- script: |
set -eox pipefail
npx react-native run-macos
workingDirectory: $(Agent.BuildDirectory)/testcli
displayName: Run macOS app (new project)
34 changes: 34 additions & 0 deletions .ado/scripts/verdaccio.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/sh

NPM_REGISTRY=http://localhost:4873

project_root=$(cd -P "$(dirname $0)" && pwd)

set -eox pipefail

case ${1-} in
"configure")
yarn config set npmRegistryServer $NPM_REGISTRY
yarn config set unsafeHttpWhitelist --json '["localhost"]'
;;

"init")
npm set registry $NPM_REGISTRY
npx verdaccio --config $project_root/.ado/verdaccio/config.yaml &
node $project_root/.ado/waitForVerdaccio.js
node $project_root/.ado/npmAddUser.js user pass mail@nomail.com $NPM_REGISTRY
;;

"publish")
checkpoint=$(git rev-parse HEAD)
yarn set-version 1000.0.0-pr
git commit --all --message 'bump' --no-verify
packages=()
for json in $(yarn workspaces list --no-private --json); do
packages+=(--package $(node --print "JSON.parse('$json').name"))
done
npx beachball change --no-fetch --type patch --message 'bump for testing purposes' ${packages[@]}
npx beachball $* --no-push --registry $NPM_REGISTRY --yes --access public --no-generate-changelog
git reset --hard $checkpoint
;;
esac
6 changes: 0 additions & 6 deletions .ado/templates/verdaccio-publish.yml

This file was deleted.

6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,8 @@ vendor/
# Ccache
.ccache

# macOS]
# ADO
.ado/Brewfile.lock.json
.ado/verdaccio/htpasswd
.ado/verdaccio/storage/.verdaccio-db.json
# macOS]
7 changes: 2 additions & 5 deletions packages/react-native-macos-init/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ You can either downgrade your version of ${chalk.yellow(RNPKG)} to ${chalk.cyan(
const pkgmgr = isProjectUsingYarn(process.cwd())
? `yarn add${verbose ? '' : ' --silent'}`
: `npm install --save${verbose ? '' : ' --silent'}`;
const execOptions = verbose ? {stdio: 'inherit' as 'inherit'} : {};
const execOptions = verbose ? {stdio: 'inherit' as const} : {};
execSync(`${pkgmgr} "${MACOSPKG}@${version}"`, execOptions);

console.log(`${pkgLatest} ${chalk.green('successfully installed!')}`);
Expand All @@ -302,10 +302,7 @@ You can either downgrade your version of ${chalk.yellow(RNPKG)} to ${chalk.cyan(
}

const generateMacOS = require(reactNativeMacOSGeneratePath());
generateMacOS(process.cwd(), name, {
overwrite,
verbose,
});
generateMacOS(process.cwd(), name, {overwrite, verbose});
} catch (error) {
printError(error.message, error);
process.exit(EXITCODE_UNKNOWN_ERROR);
Expand Down

0 comments on commit d0fa160

Please sign in to comment.