Skip to content

Commit bfd9b43

Browse files
authored
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
1 parent 9a7079c commit bfd9b43

File tree

8 files changed

+233
-9
lines changed

8 files changed

+233
-9
lines changed

.ado/ado-start-verdaccio.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
set -ex
3+
4+
# Script used by the Azure DevOps build agent to start the verdaccio npm proxy server
5+
6+
THIS_DIR=$PWD
7+
8+
COMMAND="$TMPDIR/launchVerdaccio.command"
9+
echo "cd ${THIS_DIR}; sudo n 10 ; verdaccio --config ./.ado/verdaccio/config.yaml &> ./.ado/verdaccio/console.log" > "$COMMAND"
10+
chmod +x "$COMMAND"
11+
open "$COMMAND"

.ado/apple-pr.yml

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# This file defines the Apple PR build steps used during the CI loop
22
name: $(Date:yyyyMMdd).$(Rev:.r)
33

4+
variables:
5+
- template: variables/mac.yml
6+
47
trigger: none # will disable CI builds entirely
58

69
pr:
@@ -17,7 +20,7 @@ jobs:
1720
public:
1821
apply_office_patches: 'false'
1922
pool:
20-
vmImage: macOS-10.14
23+
vmImage: $(VmImage)
2124
demands: ['xcode', 'sh', 'npm']
2225
steps:
2326
- template: templates/apple-job-javascript.yml
@@ -36,12 +39,6 @@ jobs:
3639
xcode_actions_debug: 'build test'
3740
xcode_actions_release: 'build'
3841
apply_office_patches: 'false'
39-
# Microsoft- We don't use tvOS, so don't bother maintaining the infra
40-
# tvos:
41-
# packager_platform: 'ios'
42-
# xcode_sdk: appletvsimulator
43-
# xcode_scheme: 'RNTester-tvOS'
44-
# xcode_destination: 'platform=tvOS Simulator,OS=latest,name=Apple TV'
4542
macos:
4643
packager_platform: 'macos'
4744
xcode_sdk: macosx
@@ -67,7 +64,7 @@ jobs:
6764
xcode_actions_release: 'build'
6865
apply_office_patches: 'true'
6966
pool:
70-
vmImage: macOS-10.14
67+
vmImage: $(VmImage)
7168
demands: ['xcode', 'sh', 'npm']
7269
timeoutInMinutes: 60 # how long to run the job before automatically cancelling
7370
cancelTimeoutInMinutes: 5 # how much time to give 'run always even if cancelled tasks' before killing them
@@ -82,3 +79,21 @@ jobs:
8279
xcode_actions_release: $(xcode_actions_release)
8380
xcode_destination: $(xcode_destination)
8481
apply_office_patches: $(apply_office_patches)
82+
83+
- job: CliInit
84+
displayName: Verify react-native-macos-init
85+
strategy:
86+
matrix:
87+
MacDebug:
88+
configuration: Debug
89+
pool:
90+
vmImage: $(VmImage)
91+
demands: ['xcode', 'sh', 'npm']
92+
steps:
93+
- task: UseNode@1
94+
inputs:
95+
version: '10.x'
96+
97+
- template: templates/react-native-macos-init.yml
98+
parameters:
99+
configuration: $(configuration)

.ado/npmAddUser.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env node
2+
// @ts-check
3+
4+
const child_process = require("child_process");
5+
6+
const username = process.argv[2];
7+
const password = process.argv[3];
8+
const email = process.argv[4];
9+
const registry = process.argv[5];
10+
11+
if (!username) {
12+
console.error("Please specify username");
13+
process.exit(1);
14+
}
15+
16+
if (!password) {
17+
console.error("Please specify password");
18+
process.exit(1);
19+
}
20+
21+
if (!email) {
22+
console.error("Please specify email");
23+
process.exit(1);
24+
}
25+
26+
const child = child_process.exec(`npm adduser${registry? (' --registry ' + registry) :''}` );
27+
28+
child.stdout.on("data", d => {
29+
const data = d.toString();
30+
process.stdout.write(d + "\n");
31+
if (data.match(/username/i)) {
32+
child.stdin.write(username + "\n");
33+
} else if (data.match(/password/i)) {
34+
child.stdin.write(password + "\n");
35+
} else if (data.match(/email/i)) {
36+
child.stdin.write(email + "\n");
37+
} else if (data.match(/logged in as/i)) {
38+
child.stdin.end();
39+
}
40+
});
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
parameters:
2+
configuration:
3+
4+
steps:
5+
- checkout: self # self represents the repo where the initial Pipelines YAML file was found
6+
clean: true # whether to fetch clean each time
7+
# fetchDepth: 2 # the depth of commits to ask Git to fetch
8+
lfs: false # whether to download Git-LFS files
9+
submodules: false # set to 'true' for a single level of submodules or 'recursive' to get submodules of submodules
10+
persistCredentials: false # set to 'true' to leave the OAuth token in the Git config after the initial fetch
11+
12+
# First do a build of the local package, since we point the cli at the local files, it needs to be pre-built
13+
- task: CmdLine@2
14+
displayName: yarn install (local react-native-macos)
15+
inputs:
16+
script: yarn install --frozen-lockfile
17+
18+
- task: CmdLine@2
19+
displayName: yarn install (local react-native-macos-init)
20+
inputs:
21+
script: |
22+
cd packages/react-native-macos-init
23+
yarn install
24+
25+
- task: CmdLine@2
26+
displayName: yarn build (local react-native-macos-init)
27+
inputs:
28+
script: |
29+
cd packages/react-native-macos-init
30+
yarn build
31+
32+
- task: CmdLine@2
33+
displayName: Install Verdaccio
34+
inputs:
35+
script: |
36+
npm install --global verdaccio
37+
38+
- task: CmdLine@2
39+
displayName: Install n used by ado-start-verdaccio.sh
40+
inputs:
41+
script: |
42+
npm install --global n
43+
44+
- task: ShellScript@2
45+
displayName: Launch test npm server (verdaccio)
46+
inputs:
47+
scriptPath: '.ado/ado-start-verdaccio.sh'
48+
disableAutoCwd: true
49+
cwd: ''
50+
51+
- script: |
52+
npm set registry http://localhost:4873
53+
displayName: Modify default npm config to point to local verdaccio server
54+
55+
- script: |
56+
node .ado/waitForVerdaccio.js
57+
displayName: Wait for verdaccio server to boot
58+
59+
- script: |
60+
node .ado/npmAddUser.js user pass [email protected] http://localhost:4873
61+
displayName: Add npm user to verdaccio
62+
63+
- task: CmdLine@2
64+
displayName: Bump package version
65+
inputs:
66+
script: node .ado/bumpFileVersions.js
67+
68+
- task: CmdLine@2
69+
displayName: "Prepare package.json for npm publishing as react-native-macos"
70+
inputs:
71+
script: node .ado/renamePackageToMac.js
72+
73+
- script: |
74+
npm publish --registry http://localhost:4873
75+
displayName: Publish react-native-macos to verdaccio
76+
77+
- script: |
78+
cd packages/react-native-macos-init
79+
npx --no-install beachball publish --branch origin/$(System.PullRequest.TargetBranch) --no-push --registry http://localhost:4873 --yes --access public
80+
displayName: Publish react-native-macos-init to verdaccio
81+
82+
- task: CmdLine@2
83+
displayName: Install react-native cli
84+
inputs:
85+
script: npm install -g react-native-cli
86+
87+
- task: CmdLine@2
88+
displayName: Init new project
89+
inputs:
90+
script: react-native init testcli
91+
workingDirectory: $(Agent.BuildDirectory)
92+
93+
- task: CmdLine@2
94+
displayName: Apply macos template
95+
inputs:
96+
script: npx react-native-macos-init --version latest --overwrite --prerelease
97+
workingDirectory: $(Agent.BuildDirectory)/testcli
98+
99+
# TODO: react-native run-macos and test when implemented

.ado/variables/mac.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
variables:
2+
VmImage: macOS-10.14

.ado/verdaccio/config.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
storage: ./storage
2+
auth:
3+
htpasswd:
4+
file: ./htpasswd
5+
uplinks:
6+
npmjs:
7+
url: https://registry.npmjs.org/
8+
max_fails: 40
9+
maxage: 30m
10+
timeout: 60s
11+
agent_options:
12+
keepAlive: true
13+
maxSockets: 40
14+
maxFreeSockets: 10
15+
packages:
16+
'@*/*':
17+
access: $all
18+
publish: $all
19+
proxy: npmjs
20+
'**':
21+
access: $all
22+
publish: $all
23+
proxy: npmjs
24+
logs:
25+
- {type: file, path: verdaccio.log, format: pretty, level: debug}

.ado/versionUtils.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ const fs = require("fs");
33
const path = require("path");
44

55
const pkgJsonPath = path.resolve(__dirname, "../package.json");
6-
const publishBranchName = process.env.BUILD_SOURCEBRANCH.match(/refs\/heads\/(.*)/)[1];
6+
let publishBranchName = '';
7+
try {
8+
publishBranchName = process.env.BUILD_SOURCEBRANCH.match(/refs\/heads\/(.*)/)[1];
9+
} catch (error) {}
710

811
function gatherVersionInfo() {
912
let pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, "utf8"));

.ado/waitForVerdaccio.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env node
2+
// @ts-check
3+
4+
const http = require('http');
5+
const fs = require('fs');
6+
const path = require('path');
7+
8+
function queryForServerStatus() {
9+
10+
http.get('http://localhost:4873', res => {
11+
console.log(`Server status: ${res.statusCode}`);
12+
if (res.statusCode != 200) {
13+
setTimeout(queryForServerStatus, 2000);
14+
}
15+
}).on('error', err => {
16+
console.log(err.message);
17+
try {
18+
const logFile = fs.readFileSync(path.resolve(__dirname, 'verdaccio/console.log')).toString('utf8');
19+
console.log('verdaccio console output: ' + logFile);
20+
} catch (error) {
21+
console.log('no verdaccio console output yet.');
22+
}
23+
setTimeout(queryForServerStatus, 2000);
24+
});
25+
}
26+
27+
console.log('Waiting for verdaccio instance to respond...');
28+
29+
queryForServerStatus();

0 commit comments

Comments
 (0)