From c049cf22067d6b49cb923761d19a4b4ec6528736 Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Sat, 14 Dec 2019 16:38:03 +0200 Subject: [PATCH] ci: use local, vendored yarn in Windows CI jobs (#34384) We keep a version of yarn in the repo, at `third_party/github.com/yarnpkg/`. All CI jobs should use that version for consistency (and easier updates). Previously, the Windows jobs did not use the local version. They used the version that came pre-installed on the docker image that we used. This made it more difficult to update the yarn version (something that we might want to do independently of updating other dependencies, such as Node.js). This commit fixes this by setting up the Windows CI jobs to also use the local, vendored version of yarn. PR Close #34384 --- .circleci/config.yml | 4 ++++ .circleci/windows-yarn-setup.ps1 | 14 ++++++++++++++ .circleci/windows-yarn.ps1.template | 15 +++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 .circleci/windows-yarn-setup.ps1 create mode 100644 .circleci/windows-yarn.ps1.template 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