diff --git a/.circleci/config.yml b/.circleci/config.yml index 910da903e2..36eef246d8 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -154,6 +154,10 @@ commands: - custom_attach_workspace # Install Bazel pre-requisites that aren't in the preconfigured CircleCI Windows VM. - run: ./.circleci/windows-env.ps1 + - run: + # Overwrite the yarn installed in the docker container with our own version. + name: Overwrite yarn with our own version + command: ./.circleci/windows-yarn-setup.ps1 - run: node --version - run: yarn --version - restore_cache: diff --git a/.circleci/windows-yarn-setup.ps1 b/.circleci/windows-yarn-setup.ps1 new file mode 100644 index 0000000000..b53c0b0007 --- /dev/null +++ b/.circleci/windows-yarn-setup.ps1 @@ -0,0 +1,14 @@ +# Use our local, vendored yarn in the global `yarn` command. +$globalYarnDir = "$HOME\AppData\Roaming\yarn" +$localYarnPath = & ${Env:ProgramFiles}\nodejs\node.exe ".\.circleci\get-vendored-yarn-path.js" + +# Create a directory to put the yarn PowerShell script. +New-Item -Path "$globalYarnDir" -ItemType "directory" >$null + +# Create the yarn PowerShell script (using the inferred path to the local yarn script). +Get-Content -Path ".\.circleci\windows-yarn.ps1.template" | + %{$_ -replace "{{ LOCAL_YARN_PATH_PLACEHOLDER }}", "$localYarnPath"} | + Add-Content -Path "$globalYarnDir\yarn.ps1" + +# Add the directory containing the yarn PowerShell script to `PATH`. +Add-Content -Path $profile -Value ('$Env:path = "{0};" + $Env:path' -f $globalYarnDir) diff --git a/.circleci/windows-yarn.ps1.template b/.circleci/windows-yarn.ps1.template new file mode 100644 index 0000000000..1d200352d7 --- /dev/null +++ b/.circleci/windows-yarn.ps1.template @@ -0,0 +1,15 @@ +$exe="" +if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { + # Fix case when both the Windows and Linux builds of Node + # are installed in the same directory + $exe=".exe" +} +$ret=0 +if (Test-Path "$basedir/node$exe") { + & "$basedir/node$exe" "{{ LOCAL_YARN_PATH_PLACEHOLDER }}" $args + $ret=$LASTEXITCODE +} else { + & "node$exe" "{{ LOCAL_YARN_PATH_PLACEHOLDER }}" $args + $ret=$LASTEXITCODE +} +exit $ret