Skip to content

Commit daad150

Browse files
committed
feat: Chocolatey and Homebrew caching
1 parent 886f7cb commit daad150

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

.gitlab-ci.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ cache:
3636
- ./tmp/ts-node-cache/
3737
# Homebrew cache is only used by the macos runner
3838
- ./tmp/Homebrew
39+
# Chocolatey cache is only used by the windows runner
40+
- ./tmp/chocolatey/
3941
# `jest` cache is configured in jest.config.js
4042
- ./tmp/jest/
4143
# `node-gyp` cache used by windows and macos
@@ -163,10 +165,9 @@ build:windows:
163165
npm_config_arch: "x64"
164166
before_script:
165167
- mkdir -Force "$CI_PROJECT_DIR/tmp"
166-
- choco install nodejs --version="16.15.1" -y
167-
- choco install python --version=3.9.12 -y
168-
- refreshenv
169168
script:
169+
- .\scripts\choco-install.ps1
170+
- refreshenv
170171
- npm install --ignore-scripts
171172
- $env:Path = "$(npm bin);" + $env:Path
172173
- npm run build --verbose
@@ -193,6 +194,8 @@ build:macos:
193194
variables:
194195
HOMEBREW_NO_INSTALL_UPGRADE: "true"
195196
HOMEBREW_NO_INSTALL_CLEANUP: "true"
197+
HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK: "true"
198+
HOMEBREW_NO_AUTO_UPDATE: "true"
196199
# Location node-gyp installed headers and static libraries
197200
npm_config_devdir: "${CI_PROJECT_DIR}/tmp/node-gyp"
198201
# Produce universal binary

scripts/choco-install.ps1

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
function Save-ChocoPackage {
2+
param (
3+
$PackageName
4+
)
5+
Rename-Item -Path "$env:ChocolateyInstall\lib\$PackageName\$PackageName.nupkg" -NewName "$PackageName.nupkg.zip" -ErrorAction:SilentlyContinue
6+
Expand-Archive -LiteralPath "$env:ChocolateyInstall\lib\$PackageName\$PackageName.nupkg.zip" -DestinationPath "$env:ChocolateyInstall\lib\$PackageName" -Force
7+
Remove-Item "$env:ChocolateyInstall\lib\$PackageName\_rels" -Recurse
8+
Remove-Item "$env:ChocolateyInstall\lib\$PackageName\package" -Recurse
9+
Remove-Item "$env:ChocolateyInstall\lib\$PackageName\[Content_Types].xml"
10+
New-Item -Path "${PSScriptRoot}\..\tmp\chocolatey\$PackageName" -ItemType "directory" -ErrorAction:SilentlyContinue
11+
choco pack "$env:ChocolateyInstall\lib\$PackageName\$PackageName.nuspec" --outdir "${PSScriptRoot}\..\tmp\chocolatey\$PackageName"
12+
}
13+
14+
# Check for existence of required environment variables
15+
if ( $null -eq $env:ChocolateyInstall ) {
16+
[Console]::Error.WriteLine('Missing $env:ChocolateyInstall environment variable')
17+
exit 1
18+
}
19+
20+
# Add the cached packages with source priority 1 (Chocolatey community is 0)
21+
New-Item -Path "${PSScriptRoot}\..\tmp\chocolatey" -ItemType "directory" -ErrorAction:SilentlyContinue
22+
choco source add --name="cache" --source="${PSScriptRoot}\..\tmp\chocolatey" --priority=1
23+
24+
# Install nodejs v16.15.1 (will use cache if exists)
25+
$nodejs = "nodejs.install"
26+
choco install "$nodejs" --version="16.15.1" --require-checksums -y
27+
# Internalise nodejs to cache if doesn't exist
28+
if ( -not (Test-Path -Path "${PSScriptRoot}\..\tmp\chocolatey\$nodejs\$nodejs.16.15.1.nupkg" -PathType Leaf) ) {
29+
Save-ChocoPackage -PackageName $nodejs
30+
}
31+
32+
# Install python v3.9.12 (will use cache if exists)
33+
$python = "python3"
34+
choco install $python --version="3.9.12" --require-checksums -y
35+
# Internalise python to cache if doesn't exist
36+
if ( -not (Test-Path -Path "${PSScriptRoot}\..\tmp\chocolatey\$python\$python.3.9.12.nupkg" -PathType Leaf) ) {
37+
Save-ChocoPackage -PackageName $python
38+
}

0 commit comments

Comments
 (0)