Skip to content

Commit

Permalink
[0.73] Refactor init-windows CI jobs (#12261)
Browse files Browse the repository at this point in the history
Backport PR #12213 into 0.73

## Description
PR #12183 show-horned a new variable and branching path in our existing `cli-init.yml` CI job to support the new `react-native init-windows` command.

However, this makes the pipeline hard to parse and maintain. This PR factors out the new new project path into a separate set of jobs, so we can leave the "old" pipeline as-is, run both for now, but have and easier time updating the new one (and eventually just delete the old one when it's no longer necessary).

### Type of Change
- New feature (non-breaking change which adds functionality)

### Why
To make the new new project CI easier to maintain and drift from the old new project CI.

### What
Created a new `cli-init-windows.yml` job, which calls a new "template-focused" `react-native-init-windows.yml` template, and also factored out code common to both it and to `react-native-init.yml` (like starting/stopping verdaccio) into reusable templates.

## Screenshots
N/A

## Testing
Ran the new pipelines

## Changelog
Should this change be included in the release notes: _no_
  • Loading branch information
jonthysell committed Oct 20, 2023
1 parent 4fe233d commit ae3ec47
Show file tree
Hide file tree
Showing 8 changed files with 350 additions and 144 deletions.
100 changes: 100 additions & 0 deletions .ado/jobs/cli-init-windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
parameters:
- name: buildEnvironment
type: string
default: PullRequest
values:
- PullRequest
- Continuous
- name: AgentPool
type: object
- name: buildMatrix
type: object
default:
- BuildEnvironment: PullRequest
Matrix:
- Name: FabricX64Debug
template: cpp-app
configuration: Debug
platform: x64
additionalRunArguments: --no-autolink
- Name: FabricX64Release
template: cpp-app
configuration: Release
platform: x64
additionalRunArguments: --no-autolink
- Name: FabricX86Debug
template: cpp-app
configuration: Debug
platform: x86
additionalRunArguments: --no-autolink
- Name: FabricX86Release
template: cpp-app
configuration: Release
platform: x86
additionalRunArguments: --no-autolink
- BuildEnvironment: Continuous
Matrix:
- Name: FabricX64Debug
template: cpp-app
configuration: Debug
platform: x64
additionalRunArguments: --no-autolink
- Name: FabricX64Release
template: cpp-app
configuration: Release
platform: x64
additionalRunArguments: --no-autolink
- Name: FabricX86Debug
template: cpp-app
configuration: Debug
platform: x86
additionalRunArguments: --no-autolink
- Name: FabricX86Release
template: cpp-app
configuration: Release
platform: x86
additionalRunArguments: --no-autolink
jobs:
- ${{ each config in parameters.buildMatrix }}:
- ${{ if eq(config.BuildEnvironment, parameters.buildEnvironment) }}:
- ${{ each matrix in config.Matrix }}:
- job: CliInitWindows${{ matrix.Name }}
displayName: Verify CliInitWindows ${{ matrix.Name }}

variables: [template: ../variables/windows.yml]

${{ if eq(matrix.lowResource, true) }}:
pool: ${{ parameters.AgentPool.Small }}
${{ else }}:
pool: ${{ parameters.AgentPool.Medium }}
timeoutInMinutes: 60
cancelTimeoutInMinutes: 5

steps:
- template: ../templates/checkout-full.yml
parameters:
persistCredentials: false # We don't need git creds in this job

- template: ../templates/prepare-js-env.yml

- template: ../templates/prepare-build-env.yml
parameters:
platform: ${{ parameters.platform }}
configuration: ${{ parameters.configuration }}
buildEnvironment: ${{ parameters.buildEnvironment }}

- task: CmdLine@2
displayName: Create npm directory
name: createNpmDirectory
inputs:
script: mkdir %APPDATA%\npm

- template: ../templates/react-native-init-windows.yml
parameters:
template: ${{ matrix.template }}
configuration: ${{ matrix.configuration }}
platform: ${{ matrix.platform }}
additionalInitArguments: ${{ matrix.additionalInitArguments }}
additionalRunArguments: ${{ matrix.additionalRunArguments }}
runWack: ${{ coalesce(matrix.runWack, false) }}
buildEnvironment: ${{ parameters.buildEnvironment }}
58 changes: 1 addition & 57 deletions .ado/jobs/cli-init.yml
Original file line number Diff line number Diff line change
Expand Up @@ -186,34 +186,6 @@ parameters:
platform: x64
projectType: app
lowResource: true
- Name: FabricX64Debug
language: cpp
configuration: Debug
platform: x64
projectType: app
initPath: InitWindows
additionalRunArguments: --no-autolink
- Name: FabricX64Release
language: cpp
configuration: Release
platform: x64
projectType: app
initPath: InitWindows
additionalRunArguments: --no-autolink
- Name: FabricX86Debug
language: cpp
configuration: Debug
platform: x86
projectType: app
initPath: InitWindows
additionalRunArguments: --no-autolink
- Name: FabricX86Release
language: cpp
configuration: Release
platform: x86
projectType: app
initPath: InitWindows
additionalRunArguments: --no-autolink
- BuildEnvironment: Continuous
Matrix:
- Name: X64ReleaseCpp
Expand Down Expand Up @@ -387,34 +359,7 @@ parameters:
platform: x64
projectType: app
lowResource: true
- Name: FabricX64Debug
language: cpp
configuration: Debug
platform: x64
projectType: app
initPath: InitWindows
additionalRunArguments: --no-autolink
- Name: FabricX64Release
language: cpp
configuration: Release
platform: x64
projectType: app
initPath: InitWindows
additionalRunArguments: --no-autolink
- Name: FabricX86Debug
language: cpp
configuration: Debug
platform: x86
projectType: app
initPath: InitWindows
additionalRunArguments: --no-autolink
- Name: FabricX86Release
language: cpp
configuration: Release
platform: x86
projectType: app
initPath: InitWindows
additionalRunArguments: --no-autolink

jobs:
- ${{ each config in parameters.buildMatrix }}:
- ${{ if eq(config.BuildEnvironment, parameters.buildEnvironment) }}:
Expand Down Expand Up @@ -461,7 +406,6 @@ jobs:
configuration: ${{ matrix.configuration }}
platform: ${{ matrix.platform }}
projectType: ${{ matrix.projectType }}
initPath: ${{ coalesce(matrix.initPath, 'ReactNativeWindowsInit') }}
additionalInitArguments: ${{ matrix.additionalInitArguments }}
additionalRunArguments: ${{ matrix.additionalRunArguments }}
runWack: ${{ coalesce(matrix.runWack, false) }}
Expand Down
5 changes: 5 additions & 0 deletions .ado/stages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,8 @@ stages:
buildEnvironment: ${{ parameters.buildEnvironment }}
AgentPool: ${{ parameters.AgentPool }}
buildNuGetOnly: false

- template: jobs/cli-init-windows.yml
parameters:
buildEnvironment: ${{ parameters.buildEnvironment }}
AgentPool: ${{ parameters.AgentPool }}
28 changes: 28 additions & 0 deletions .ado/templates/react-native-debug-info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#
parameters:
- name: workingDirectory
type: string
- name: doctor
type: boolean
default: true
- name: config
type: boolean
default: true

steps:
# Useful info to have in the log, but also a necessary workaround to make sure the cli is cached by npx
- script: npx react-native info
displayName: React Native Info
workingDirectory: ${{ parameters.workingDirectory }}

- ${{ if eq(parameters.doctor, true) }}:
# Verify react-native doctor command works
- script: npx react-native doctor
displayName: React Native Doctor
workingDirectory: ${{ parameters.workingDirectory }}

- ${{ if eq(parameters.config, true) }}:
# Print the config for debugging react-native CLI commands
- script: npx react-native config
displayName: React Native Config
workingDirectory: ${{ parameters.workingDirectory }}
140 changes: 140 additions & 0 deletions .ado/templates/react-native-init-windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
#
parameters:
- name: template
type: string
- name: platform
type: string
values:
- x86
- x64
- ARM64
- name: configuration
type: string
values:
- Debug
- Release
- name: additionalRunArguments
type: string
default: ''
- name: additionalInitArguments
type: string
default: ''
- name: runWack
type: boolean
default: false
- name: buildEnvironment
type: string
default: PullRequest
values:
- PullRequest
- Continuous

steps:
# Start npm test server
- template: verdaccio-start.yml

- template: set-version-vars.yml
parameters:
buildEnvironment: ${{ parameters.buildEnvironment }}

- ${{ if endsWith(parameters.template, '-app') }}:
- script: |
npx --yes react-native@$(reactNativeDevDependency) init testcli --template react-native@$(reactNativeDevDependency)
displayName: Init new app project
workingDirectory: $(Agent.BuildDirectory)
- ${{ if endsWith(parameters.template, '-lib') }}:
- script: |
npx --yes create-react-native-module@0.20.2 --package-name "testcli" testcli
displayName: Init new lib project
workingDirectory: $(Agent.BuildDirectory)
- script: |
rmdir /s /q android
displayName: Remove broken android folder # See issue https://github.com/microsoft/react-native-windows/issues/12209
workingDirectory: $(Agent.BuildDirectory)\testcli
- script: |
call yarn install
call yarn upgrade react@$(reactDevDependency) --dev
call yarn upgrade react-native@$(reactNativeDevDependency) --dev
displayName: Update project react and react-native dev versions
workingDirectory: $(Agent.BuildDirectory)\testcli
- script: |
call yarn add react-native-windows@$(npmVersion)
displayName: yarn add react-native-windows@$(npmVersion)
workingDirectory: $(Agent.BuildDirectory)\testcli
env:
npm_config_registry: http://localhost:4873
- script: |
call yarn react-native init-windows --template ${{ parameters.template }} --overwrite --logging ${{ parameters.additionalInitArguments }}
displayName: Call react-native init-windows
workingDirectory: $(Agent.BuildDirectory)\testcli
env:
npm_config_registry: http://localhost:4873
- ${{ if endsWith(parameters.template, '-app') }}:
- powershell: |
$path = (Get-ChildItem -Filter "Package.appxmanifest" -File -Recurse).FullName;
[xml] $manifest = Get-Content $path
$manifest.Package.Identity.Name = 'ReactNative.InitTest'
$manifest.Save("$path")
displayName: Set AppX package name to "ReactNative.InitTest"
workingDirectory: $(Agent.BuildDirectory)\testcli\windows
# End npm test server
- template: verdaccio-stop.yml

- task: PowerShell@2
displayName: Start tracing
inputs:
targetType: filePath # filePath | inline
filePath: $(Build.SourcesDirectory)\vnext\Scripts\Tracing\Start-Tracing.ps1

- template: react-native-debug-info.yml
parameters:
workingDirectory: $(Agent.BuildDirectory)\testcli

- template: ../templates/run-windows-with-certificates.yml
parameters:
buildEnvironment: ${{ parameters.BuildEnvironment }}
certificateName: RNWEncodedKey
buildConfiguration: ${{ parameters.configuration }}
buildPlatform: ${{ parameters.platform }}
deployOption: ${{ parameters.additionalRunArguments }}
buildLogDirectory: $(Build.BinariesDirectory)\${{ parameters.platform }}\${{ parameters.configuration }}\BuildLogs
workingDirectory: $(Agent.BuildDirectory)\testcli
restoreLockedMode: false # Allow new lockfile to be created

- template: upload-build-logs.yml
parameters:
buildLogDirectory: '$(Build.BinariesDirectory)\${{ parameters.platform }}\${{ parameters.configuration }}\BuildLogs'

# Only test bundling in debug since we already bundle as part of release builds
- ${{ if and(endsWith(parameters.template, '-app'), eq(parameters.configuration, 'Debug')) }}:
- script: npx react-native bundle --entry-file index.js --platform windows --bundle-output test.bundle
displayName: Create bundle testcli
workingDirectory: $(Agent.BuildDirectory)\testcli

- ${{ if eq(parameters.runWack, true) }}:
- template: ../templates/run-wack.yml
parameters:
packageName: ReactNative.InitTest
reportArtifact: 'Template App WACK Report ${{ parameters.platform }} ${{ parameters.configuration }} ($(System.JobAttempt))'

- task: PowerShell@2
displayName: Stop tracing
inputs:
targetType: filePath # filePath | inline
filePath: $(Build.SourcesDirectory)\vnext\Scripts\Tracing\Stop-Tracing.ps1
arguments: -NoAnalysis -outputFolder $(Build.StagingDirectory)/Tracing
condition: succeededOrFailed()

- task: PublishBuildArtifacts@1
displayName: Upload traces
inputs:
pathtoPublish: '$(Build.StagingDirectory)/Tracing'
artifactName: 'Traces - $(Agent.JobName)-$(System.JobAttempt)'
condition: succeededOrFailed()

0 comments on commit ae3ec47

Please sign in to comment.