Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions .circleci/chocolatey.config

This file was deleted.

181 changes: 115 additions & 66 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,21 +168,59 @@ commands:
- when:
condition: << parameters.static >>
steps:
- run:
name: Build static << parameters.go_target_os >>/<< parameters.go_arch >>
environment:
CC: << parameters.c_compiler >>
MACOSX_DEPLOYMENT_TARGET: 13.0
command: make << parameters.make_target >> GOOS=<< parameters.go_target_os >> GOARCH=<< parameters.go_arch >> STATIC_NODE_BINARY=true CGO_ENABLED=0
# Windows static build (use PowerShell and ensure GNU make is on PATH)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: This block adds quite some duplication which is difficult to maintain just to load environment variables, is there a way to avoid this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: maybe re-use this approach.

- when:
condition:
equal: ['windows', << parameters.go_target_os >>]
steps:
- run:
shell: powershell
name: Build static << parameters.go_target_os >>/<< parameters.go_arch >> (windows)
environment:
CC: << parameters.c_compiler >>
MACOSX_DEPLOYMENT_TARGET: 13.0
command: |
if (Test-Path 'C:\tools-cache\snyk-env.ps1') { . 'C:\tools-cache\snyk-env.ps1' }
make << parameters.make_target >> GOOS=<< parameters.go_target_os >> GOARCH=<< parameters.go_arch >> STATIC_NODE_BINARY=true CGO_ENABLED=0
# Non-windows static build (bash)
- unless:
condition:
equal: ['windows', << parameters.go_target_os >>]
steps:
- run:
name: Build static << parameters.go_target_os >>/<< parameters.go_arch >>
environment:
CC: << parameters.c_compiler >>
MACOSX_DEPLOYMENT_TARGET: 13.0
command: make << parameters.make_target >> GOOS=<< parameters.go_target_os >> GOARCH=<< parameters.go_arch >> STATIC_NODE_BINARY=true CGO_ENABLED=0
- unless:
condition: << parameters.static >>
steps:
- run:
name: Build << parameters.go_target_os >>/<< parameters.go_arch >>
environment:
CC: << parameters.c_compiler >>
MACOSX_DEPLOYMENT_TARGET: 13.0
command: make << parameters.make_target >> GOOS=<< parameters.go_target_os >> GOARCH=<< parameters.go_arch >> STATIC_NODE_BINARY=false CGO_ENABLED=1
# Windows non-static build
- when:
condition:
equal: ['windows', << parameters.go_target_os >>]
steps:
- run:
shell: powershell
name: Build << parameters.go_target_os >>/<< parameters.go_arch >> (windows)
environment:
CC: << parameters.c_compiler >>
MACOSX_DEPLOYMENT_TARGET: 13.0
command: |
if (Test-Path 'C:\tools-cache\snyk-env.ps1') { . 'C:\tools-cache\snyk-env.ps1' }
make << parameters.make_target >> GOOS=<< parameters.go_target_os >> GOARCH=<< parameters.go_arch >> STATIC_NODE_BINARY=false CGO_ENABLED=1
# Non-windows non-static build
- unless:
condition:
equal: ['windows', << parameters.go_target_os >>]
steps:
- run:
name: Build << parameters.go_target_os >>/<< parameters.go_arch >>
environment:
CC: << parameters.c_compiler >>
MACOSX_DEPLOYMENT_TARGET: 13.0
command: make << parameters.make_target >> GOOS=<< parameters.go_target_os >> GOARCH=<< parameters.go_arch >> STATIC_NODE_BINARY=false CGO_ENABLED=1
install-go:
parameters:
go_os:
Expand Down Expand Up @@ -228,40 +266,76 @@ commands:
equal: ['windows', << parameters.go_os >>]
steps:
- run:
name: Add go binary to PATH
name: Add go binary to PATH (via snyk-env)
shell: powershell
command: |
New-Item -Path $profile -ItemType File -Force
'$Env:Path = "<< parameters.extraction_path >>\go\bin;" + $Env:Path' >> $profile

install-deps-windows-full:
$goBin = '<< parameters.extraction_path >>\go\bin'
$envScript = 'C:\tools-cache\snyk-env.ps1'
if (-not (Test-Path $envScript)) {
New-Item -Path $envScript -ItemType File -Force | Out-Null
}
'$Env:Path = "' + $goBin + ';" + $Env:Path' | Out-File -FilePath $envScript -Append -Encoding UTF8

install-deps-windows-native-build:
steps:
- run:
name: Configure Chocolatey cache location
shell: bash.exe
name: Ensure tools cache directory
shell: powershell
command: |
choco config set cacheLocation "C:\choco-cache"
$cacheDir = 'C:\tools-cache'
if (-not (Test-Path $cacheDir)) {
New-Item -ItemType Directory -Path $cacheDir | Out-Null
}
- restore_cache:
name: Restoring Chocolatey cache
name: Restoring Windows tools cache
keys:
- chocolatey-cache-full-v5-{{ arch }}-{{ checksum ".circleci/chocolatey.config" }}
- windows-tools-cache-v1-{{ arch }}
- run:
name: Install Node.js (native)
shell: powershell
command: |
.\.circleci\windows\install-node.ps1
- run:
name: Install Apache Maven 3.8.2 (native)
shell: powershell
command: |
.\.circleci\windows\install-maven.ps1
- run:
name: Install Gradle 8.1.1 (native)
shell: powershell
command: |
.\.circleci\windows\install-gradle.ps1
- run:
name: Install .NET SDK 8.0.100 (native)
shell: powershell
command: |
.\.circleci\windows\install-dotnet-sdk.ps1
- run:
name: Install Python 3.12.8 (native)
shell: powershell
command: |
.\.circleci\windows\install-python3.ps1
- run:
name: Install Windows dependencies
shell: bash.exe
name: Install GNU Make 4.4.1 (native)
shell: powershell
command: |
.\.circleci\windows\install-make.ps1
- run:
name: Ensure Python and uv
shell: powershell
command: |
choco uninstall nodejs -y
choco uninstall nodejs.install -y
choco install .circleci/chocolatey.config --no-progress -y
choco install nodejs --version=$(head .nvmrc) --no-progress -y
if (Test-Path 'C:\tools-cache\snyk-env.ps1') { . 'C:\tools-cache\snyk-env.ps1' }
.\.circleci\windows\ensure-python-uv.ps1
- save_cache:
name: Saving Chocolatey cache
key: chocolatey-cache-full-v5-{{ arch }}-{{ checksum ".circleci/chocolatey.config" }}
name: Saving Windows tools cache
key: windows-tools-cache-v1-{{ arch }}
paths:
- C:\choco-cache
- install-deps-python:
os: win
- run:
name: Install uv
command: pip install uv
- C:\tools-cache

install-deps-windows-native-full-signing:
steps:
- install-deps-windows-signing
- install-deps-windows-native-build

install-deps-windows-signing:
steps:
Expand Down Expand Up @@ -310,32 +384,6 @@ commands:
install-deps-windows-full-signing:
steps:
- install-deps-windows-signing
- install-deps-windows-make

install-deps-windows-make:
steps:
- run:
name: Configure Chocolatey cache location
shell: bash.exe
command: |
choco config set cacheLocation "C:\choco-cache"
- restore_cache:
name: Restoring Chocolatey cache
keys:
- chocolatey-cache-v5-{{ arch }}-{{ checksum ".circleci/chocolatey.config" }}
- run:
name: Install Windows dependencies
shell: bash.exe
command: |
choco install make --no-progress -y
- save_cache:
name: Saving Chocolatey cache
key: chocolatey-cache-v5-{{ arch }}-{{ checksum ".circleci/chocolatey.config" }}
paths:
- C:\choco-cache
- install-deps-python:
os: win
- install-deps-windows-signing

install-deps-noop:
steps:
Expand Down Expand Up @@ -717,7 +765,7 @@ workflows:
go_arch: amd64
go_download_base_url: << pipeline.parameters.fips_go_download_base_url >>
make_target: build clean-golang build-fips
install_deps_extension: windows-full-signing
install_deps_extension: windows-native-full-signing
install_path: 'C:\'
executor: win-server2022-amd64
context:
Expand Down Expand Up @@ -903,11 +951,12 @@ workflows:
- build windows amd64
executor: win-server2022-amd64
test_snyk_command: binary-releases\\snyk-win.exe
install_deps_extension: windows-full
install_deps_extension: windows-native-build
dont_skip_tests: 0
shards: 8
shard_calc_cmd: '$([int]$env:CIRCLE_NODE_INDEX + 1)'
pre_test_cmds: Import-Module $env:ChocolateyInstall\helpers\chocolateyProfile.psm1; RefreshEnv
pre_test_cmds: |
if (Test-Path 'C:\tools-cache\snyk-env.ps1') { . 'C:\tools-cache\snyk-env.ps1' }

- sign:
name: sign windows amd64
Expand All @@ -918,7 +967,7 @@ workflows:
go_arch: amd64
make_target: sign sign-fips
executor: win-server2022-amd64
install_deps_extension: windows-make
install_deps_extension: windows-native-full-signing
filters:
branches:
only:
Expand Down
30 changes: 30 additions & 0 deletions .circleci/windows/ensure-python-uv.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Param()

$ErrorActionPreference = 'Stop'

try {
$python = Get-Command python -ErrorAction SilentlyContinue
if (-not $python) {
$python = Get-Command python3 -ErrorAction SilentlyContinue
}

if (-not $python) {
throw "Python is expected to be preinstalled on the CircleCI Windows image, but was not found."
}

Write-Host "Using Python at $($python.Path)"

try {
& $python.Path -m pip install --upgrade pip
}
catch {
Write-Host "Failed to upgrade pip, continuing: $($_.Exception.Message)"
}

& $python.Path -m pip install uv
}
catch {
Write-Error "Failed to ensure Python/uv: $($_.Exception.Message)"
exit 1
}

81 changes: 81 additions & 0 deletions .circleci/windows/install-dotnet-sdk.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
Param()

$ErrorActionPreference = 'Stop'

# Load previously persisted tool PATH entries if present
$envScript = 'C:\tools-cache\snyk-env.ps1'
if (Test-Path $envScript) {
. $envScript
}

try {
$dotnetVersion = '8.0.100'
$cacheDir = 'C:\tools-cache'
$installerPath = Join-Path $cacheDir "dotnet-sdk-$dotnetVersion-win-x64.exe"
$expectedSha256 = 'd77a87a78264fcfb1703a7064795ccb10938cdfaea64a03cb0f36b1cda379f82'

if (-not (Test-Path $cacheDir)) {
New-Item -ItemType Directory -Path $cacheDir | Out-Null
}

if (-not (Test-Path $installerPath)) {
Write-Host "Downloading .NET SDK $dotnetVersion installer..."
$url = "https://builds.dotnet.microsoft.com/dotnet/Sdk/$dotnetVersion/dotnet-sdk-$dotnetVersion-win-x64.exe"
curl.exe -L $url -o $installerPath
}

Write-Host 'Verifying .NET SDK installer checksum...'
$hash = Get-FileHash -Path $installerPath -Algorithm SHA256
if ($hash.Hash.ToLower() -ne $expectedSha256.ToLower()) {
throw "Checksum verification failed for $installerPath. Expected $expectedSha256 but got $($hash.Hash.ToLower())."
}

Write-Host "Installing .NET SDK $dotnetVersion..."
& $installerPath /install /quiet /norestart /log "$cacheDir\dotnet-sdk-install.log"

# Locate installed dotnet.exe using the known default installation path (%ProgramFiles%\dotnet)
$dotnetExe = "C:\Program Files\dotnet\dotnet.exe"
if (-not (Test-Path $dotnetExe)) {
throw ".NET SDK $dotnetVersion did not install correctly; expected $dotnetExe to exist."
}

$dotnetPath = Split-Path $dotnetExe -Parent

Write-Host "Adding $dotnetPath to PATH for current session..."
$Env:Path = "$dotnetPath;" + $Env:Path

try {
if (-not (Test-Path $profile)) {
New-Item -Path $profile -ItemType File -Force | Out-Null
}
$pathUpdateLine = '$Env:Path = "' + $dotnetPath + ';" + $Env:Path'
$profileContent = Get-Content -Path $profile -ErrorAction SilentlyContinue
if (-not $profileContent -or -not ($profileContent -contains $pathUpdateLine)) {
$pathUpdateLine | Out-File -FilePath $profile -Append -Encoding UTF8
}
}
catch {
Write-Host "Warning: failed to persist .NET PATH update to profile: $($_.Exception.Message)"
}

# Append PATH update to shared environment script for CircleCI steps
try {
$envScript = 'C:\tools-cache\snyk-env.ps1'
if (-not (Test-Path $envScript)) {
New-Item -Path $envScript -ItemType File -Force | Out-Null
}
$pathUpdateLine = '$Env:Path = "' + $dotnetPath + ';" + $Env:Path'
$existing = Get-Content -Path $envScript -ErrorAction SilentlyContinue
if (-not $existing -or -not ($existing -contains $pathUpdateLine)) {
$pathUpdateLine | Out-File -FilePath $envScript -Append -Encoding UTF8
}
}
catch {
Write-Host "Warning: failed to persist .NET PATH update to env script: $($_.Exception.Message)"
}
}
catch {
Write-Error "Failed to install .NET SDK: $($_.Exception.Message)"
exit 1
}

Loading
Loading