From bfd9b433e5e178404a5ca66122c09d3f638c306b Mon Sep 17 00:00:00 2001 From: Tom Underhill Date: Tue, 7 Apr 2020 11:08:40 -0700 Subject: [PATCH 1/2] Add CI for react-native-macos-init (#297) * Update scripts to publish react-native-macos-init * Clean up merge markers * Added CI test for react-native-macos-init * Rename command * Apparently ADO variables cannot be yml arrays. Remove the Demands variable. * Ensure node 10.x * Try npm install -g verdaccio * Try without npx * Log verdaccio console output. * Try NodeTool instead of UseNode * Fix argument * Try using `n` to enforce node version when running ado-start-verdaccio.sh * No bump * Set env var * Lets try setting the correct env var this time. * Make versionUtils.js more robust. * Restore package.json * Run beachball from react-native-macos-init * Fix \ to /. * Change version to latest --- .ado/ado-start-verdaccio.sh | 11 +++ .ado/apple-pr.yml | 31 +++++-- .ado/npmAddUser.js | 40 +++++++++ .ado/templates/react-native-macos-init.yml | 99 ++++++++++++++++++++++ .ado/variables/mac.yml | 2 + .ado/verdaccio/config.yaml | 25 ++++++ .ado/versionUtils.js | 5 +- .ado/waitForVerdaccio.js | 29 +++++++ 8 files changed, 233 insertions(+), 9 deletions(-) create mode 100755 .ado/ado-start-verdaccio.sh create mode 100644 .ado/npmAddUser.js create mode 100644 .ado/templates/react-native-macos-init.yml create mode 100644 .ado/variables/mac.yml create mode 100644 .ado/verdaccio/config.yaml create mode 100644 .ado/waitForVerdaccio.js diff --git a/.ado/ado-start-verdaccio.sh b/.ado/ado-start-verdaccio.sh new file mode 100755 index 00000000000000..34f01b4cc3a5dc --- /dev/null +++ b/.ado/ado-start-verdaccio.sh @@ -0,0 +1,11 @@ +#!/bin/bash +set -ex + +# Script used by the Azure DevOps build agent to start the verdaccio npm proxy server + +THIS_DIR=$PWD + +COMMAND="$TMPDIR/launchVerdaccio.command" +echo "cd ${THIS_DIR}; sudo n 10 ; verdaccio --config ./.ado/verdaccio/config.yaml &> ./.ado/verdaccio/console.log" > "$COMMAND" +chmod +x "$COMMAND" +open "$COMMAND" diff --git a/.ado/apple-pr.yml b/.ado/apple-pr.yml index 33ba7a6cf266bc..ab9b3e69886a4e 100644 --- a/.ado/apple-pr.yml +++ b/.ado/apple-pr.yml @@ -1,6 +1,9 @@ # This file defines the Apple PR build steps used during the CI loop name: $(Date:yyyyMMdd).$(Rev:.r) +variables: + - template: variables/mac.yml + trigger: none # will disable CI builds entirely pr: @@ -17,7 +20,7 @@ jobs: public: apply_office_patches: 'false' pool: - vmImage: macOS-10.14 + vmImage: $(VmImage) demands: ['xcode', 'sh', 'npm'] steps: - template: templates/apple-job-javascript.yml @@ -36,12 +39,6 @@ jobs: xcode_actions_debug: 'build test' xcode_actions_release: 'build' apply_office_patches: 'false' - # Microsoft- We don't use tvOS, so don't bother maintaining the infra - # tvos: - # packager_platform: 'ios' - # xcode_sdk: appletvsimulator - # xcode_scheme: 'RNTester-tvOS' - # xcode_destination: 'platform=tvOS Simulator,OS=latest,name=Apple TV' macos: packager_platform: 'macos' xcode_sdk: macosx @@ -67,7 +64,7 @@ jobs: xcode_actions_release: 'build' apply_office_patches: 'true' pool: - vmImage: macOS-10.14 + vmImage: $(VmImage) demands: ['xcode', 'sh', 'npm'] timeoutInMinutes: 60 # how long to run the job before automatically cancelling cancelTimeoutInMinutes: 5 # how much time to give 'run always even if cancelled tasks' before killing them @@ -82,3 +79,21 @@ jobs: xcode_actions_release: $(xcode_actions_release) xcode_destination: $(xcode_destination) apply_office_patches: $(apply_office_patches) + + - job: CliInit + displayName: Verify react-native-macos-init + strategy: + matrix: + MacDebug: + configuration: Debug + pool: + vmImage: $(VmImage) + demands: ['xcode', 'sh', 'npm'] + steps: + - task: UseNode@1 + inputs: + version: '10.x' + + - template: templates/react-native-macos-init.yml + parameters: + configuration: $(configuration) diff --git a/.ado/npmAddUser.js b/.ado/npmAddUser.js new file mode 100644 index 00000000000000..d8e77ee409921a --- /dev/null +++ b/.ado/npmAddUser.js @@ -0,0 +1,40 @@ +#!/usr/bin/env node +// @ts-check + +const child_process = require("child_process"); + +const username = process.argv[2]; +const password = process.argv[3]; +const email = process.argv[4]; +const registry = process.argv[5]; + +if (!username) { + console.error("Please specify username"); + process.exit(1); +} + +if (!password) { + console.error("Please specify password"); + process.exit(1); +} + +if (!email) { + console.error("Please specify email"); + process.exit(1); +} + +const child = child_process.exec(`npm adduser${registry? (' --registry ' + registry) :''}` ); + +child.stdout.on("data", d => { + const data = d.toString(); + process.stdout.write(d + "\n"); + if (data.match(/username/i)) { + child.stdin.write(username + "\n"); + } else if (data.match(/password/i)) { + child.stdin.write(password + "\n"); + } else if (data.match(/email/i)) { + child.stdin.write(email + "\n"); + } else if (data.match(/logged in as/i)) { + child.stdin.end(); + } +}); diff --git a/.ado/templates/react-native-macos-init.yml b/.ado/templates/react-native-macos-init.yml new file mode 100644 index 00000000000000..a880a34ac60942 --- /dev/null +++ b/.ado/templates/react-native-macos-init.yml @@ -0,0 +1,99 @@ +parameters: + configuration: + +steps: + - checkout: self # self represents the repo where the initial Pipelines YAML file was found + clean: true # whether to fetch clean each time + # fetchDepth: 2 # the depth of commits to ask Git to fetch + lfs: false # whether to download Git-LFS files + submodules: false # set to 'true' for a single level of submodules or 'recursive' to get submodules of submodules + persistCredentials: false # set to 'true' to leave the OAuth token in the Git config after the initial fetch + + # 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 --frozen-lockfile + + - task: CmdLine@2 + displayName: yarn install (local react-native-macos-init) + inputs: + script: | + cd packages/react-native-macos-init + yarn install + + - 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: Install Verdaccio + inputs: + script: | + npm install --global verdaccio + + - task: CmdLine@2 + displayName: Install n used by ado-start-verdaccio.sh + inputs: + script: | + npm install --global n + + - task: ShellScript@2 + displayName: Launch test npm server (verdaccio) + inputs: + scriptPath: '.ado/ado-start-verdaccio.sh' + disableAutoCwd: true + cwd: '' + + - script: | + npm set registry http://localhost:4873 + displayName: Modify default npm config to point to local verdaccio server + + - script: | + node .ado/waitForVerdaccio.js + displayName: Wait for verdaccio server to boot + + - script: | + node .ado/npmAddUser.js user pass mail@nomail.com http://localhost:4873 + displayName: Add npm user to verdaccio + + - task: CmdLine@2 + displayName: Bump package version + inputs: + script: node .ado/bumpFileVersions.js + + - task: CmdLine@2 + displayName: "Prepare package.json for npm publishing as react-native-macos" + inputs: + script: node .ado/renamePackageToMac.js + + - script: | + npm publish --registry http://localhost:4873 + displayName: Publish react-native-macos to verdaccio + + - script: | + cd packages/react-native-macos-init + npx --no-install beachball publish --branch origin/$(System.PullRequest.TargetBranch) --no-push --registry http://localhost:4873 --yes --access public + displayName: Publish react-native-macos-init to verdaccio + + - task: CmdLine@2 + displayName: Install react-native cli + inputs: + script: npm install -g react-native-cli + + - task: CmdLine@2 + displayName: Init new project + inputs: + script: react-native init testcli + workingDirectory: $(Agent.BuildDirectory) + + - task: CmdLine@2 + displayName: Apply macos template + inputs: + script: npx react-native-macos-init --version latest --overwrite --prerelease + workingDirectory: $(Agent.BuildDirectory)/testcli + + # TODO: react-native run-macos and test when implemented \ No newline at end of file diff --git a/.ado/variables/mac.yml b/.ado/variables/mac.yml new file mode 100644 index 00000000000000..f81f780ec1b166 --- /dev/null +++ b/.ado/variables/mac.yml @@ -0,0 +1,2 @@ +variables: + VmImage: macOS-10.14 diff --git a/.ado/verdaccio/config.yaml b/.ado/verdaccio/config.yaml new file mode 100644 index 00000000000000..7728446b671986 --- /dev/null +++ b/.ado/verdaccio/config.yaml @@ -0,0 +1,25 @@ +storage: ./storage +auth: + htpasswd: + file: ./htpasswd +uplinks: + npmjs: + url: https://registry.npmjs.org/ + max_fails: 40 + maxage: 30m + timeout: 60s + agent_options: + keepAlive: true + maxSockets: 40 + maxFreeSockets: 10 +packages: + '@*/*': + access: $all + publish: $all + proxy: npmjs + '**': + access: $all + publish: $all + proxy: npmjs +logs: + - {type: file, path: verdaccio.log, format: pretty, level: debug} \ No newline at end of file diff --git a/.ado/versionUtils.js b/.ado/versionUtils.js index 8abed9b6c41882..40e0db278f14f1 100644 --- a/.ado/versionUtils.js +++ b/.ado/versionUtils.js @@ -3,7 +3,10 @@ const fs = require("fs"); const path = require("path"); const pkgJsonPath = path.resolve(__dirname, "../package.json"); -const publishBranchName = process.env.BUILD_SOURCEBRANCH.match(/refs\/heads\/(.*)/)[1]; +let publishBranchName = ''; +try { + publishBranchName = process.env.BUILD_SOURCEBRANCH.match(/refs\/heads\/(.*)/)[1]; +} catch (error) {} function gatherVersionInfo() { let pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, "utf8")); diff --git a/.ado/waitForVerdaccio.js b/.ado/waitForVerdaccio.js new file mode 100644 index 00000000000000..62c4e2888a8d28 --- /dev/null +++ b/.ado/waitForVerdaccio.js @@ -0,0 +1,29 @@ +#!/usr/bin/env node +// @ts-check + +const http = require('http'); +const fs = require('fs'); +const path = require('path'); + +function queryForServerStatus() { + + http.get('http://localhost:4873', res => { + console.log(`Server status: ${res.statusCode}`); + if (res.statusCode != 200) { + setTimeout(queryForServerStatus, 2000); + } + }).on('error', err => { + console.log(err.message); + try { + const logFile = fs.readFileSync(path.resolve(__dirname, 'verdaccio/console.log')).toString('utf8'); + console.log('verdaccio console output: ' + logFile); + } catch (error) { + console.log('no verdaccio console output yet.'); + } + setTimeout(queryForServerStatus, 2000); + }); +} + +console.log('Waiting for verdaccio instance to respond...'); + +queryForServerStatus(); \ No newline at end of file From f9df0ae07461de48eefaffbf354b202be08da681 Mon Sep 17 00:00:00 2001 From: React-Native Bot <53619745+rnbot@users.noreply.github.com> Date: Tue, 7 Apr 2020 18:21:39 +0000 Subject: [PATCH 2/2] Applying package update to 0.60.0-microsoft.69 ***NO_CI*** --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 72027fec42c492..d1de78c7700b42 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native", - "version": "0.60.0-microsoft.68", + "version": "0.60.0-microsoft.69", "description": "[Microsoft Fork] A framework for building native apps using React", "license": "MIT", "repository": {