Skip to content

Commit

Permalink
CI: enable built artifacts cache
Browse files Browse the repository at this point in the history
  • Loading branch information
ForNeVeR committed May 12, 2024
1 parent 8fc3c7e commit 35954d8
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 104 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ jobs:
shell: pwsh
run: ./common/verify-encoding.ps1

- name: Cache artifacts
uses: actions/cache@v4
with:
path: artifacts
key: linux.x86-64

# Build:
- name: Install
shell: pwsh
Expand Down Expand Up @@ -55,6 +61,12 @@ jobs:
shell: pwsh
run: ./common/verify-encoding.ps1

- name: Cache artifacts
uses: actions/cache@v4
with:
path: artifacts
key: macos.x86-64

# Build:
- name: Install
shell: pwsh
Expand Down Expand Up @@ -85,6 +97,12 @@ jobs:
shell: pwsh
run: ./common/verify-encoding.ps1

- name: Cache artifacts
uses: actions/cache@v4
with:
path: artifacts
key: windows.x86-64

# Build:
- name: Build
shell: pwsh
Expand Down
27 changes: 27 additions & 0 deletions common/Test-UpToDate.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
param (
[string] $RepoDirectory = "$PSScriptRoot/../td",
[string] $ArtifactsDirectory = "$PSScriptRoot/../artifacts",
[switch] $GenerateCheckResult
)

$ErrorActionPreference = 'Stop'
Set-StrictMode -Version Latest

$resultFile = "$ArtifactsDirectory/artifact.json"
$inputs = [pscustomobject] @{
$InputCommitHash = (git --git-dir=$RepoDirectory/.git rev-parse HEAD)
}

if ($GenerateCheckResult) {
$inputs | ConvertTo-Json | Set-Content $resultFile
Write-Host "Result cache file generated: `"$resultFile`"."
return $true
} elseif (Test-Path $resultFile) {
$result = Get-Content $resultFile | ConvertFrom-Json
$upToDate = $result.InputCommitHash -eq $inputs.InputCommitHash
Write-Host "Cache found: cached commit hash is $($result.InputCommitHash), current commit hash is $($inputs.InputCommitHash). Up to date: $upToDate."
return $upToDate
} else {
Write-Host "Last result cache file not found: `"$resultFile`"."
return $false
}
90 changes: 49 additions & 41 deletions linux/build.ps1
Original file line number Diff line number Diff line change
@@ -1,54 +1,62 @@
param (
[string] $td = "$PSScriptRoot/../td",
[string] $InstallPrefix = "$PSScriptRoot/../build/install"
[string] $InstallPrefix = "$PSScriptRoot/../build/install",
[string] $CheckUpToDateScript = "$PSScriptRoot/../common/Test-UpToDate.ps1",
[switch] $SkipUpToDateCheck
)

$ErrorActionPreference = 'Stop'
Set-StrictMode -Version Latest

if (-not (Test-Path $td/build)) {
New-Item -Type Directory $td/build
}

Push-Location $td/build
try {
$cmakeArguments = @(
'-DCMAKE_BUILD_TYPE=Release'
"-DCMAKE_INSTALL_PREFIX:PATH=$InstallPrefix"
'..'
)
$cmakePrepareCrossCompilingArguments = @(
'--build'
'.'
'--target', 'prepare_cross_compiling'
)
$cmakeBuildArguments = @(
'--build'
'.'
'--target', 'install'
)

cmake @cmakeArguments
if (!$?) {
throw 'Cannot execute cmake'
if ($SkipUpToDateCheck -or !$(& $CheckUpToDateScript)) {
if (-not (Test-Path $td/build)) {
New-Item -Type Directory $td/build
}

cmake @cmakePrepareCrossCompilingArguments
if (!$?) {
throw 'Cannot execute cmake --build --target prepare_cross_compiling'
}
Push-Location $td/build
try {
$cmakeArguments = @(
'-DCMAKE_BUILD_TYPE=Release'
"-DCMAKE_INSTALL_PREFIX:PATH=$InstallPrefix"
'..'
)
$cmakePrepareCrossCompilingArguments = @(
'--build'
'.'
'--target', 'prepare_cross_compiling'
)
$cmakeBuildArguments = @(
'--build'
'.'
'--target', 'install'
)

Set-Location ..
php SplitSource.php
if (!$?) {
throw 'Cannot execute php SplitSource.php'
}
cmake @cmakeArguments
if (!$?) {
throw 'Cannot execute cmake'
}

cmake @cmakePrepareCrossCompilingArguments
if (!$?) {
throw 'Cannot execute cmake --build --target prepare_cross_compiling'
}

Set-Location ..
php SplitSource.php
if (!$?) {
throw 'Cannot execute php SplitSource.php'
}

Set-Location build
cmake @cmakeBuildArguments
if (!$?) {
throw 'Cannot execute cmake --build --target install'
}

Set-Location build
cmake @cmakeBuildArguments
if (!$?) {
throw 'Cannot execute cmake --build --target install'
& $CheckUpToDateScript -GenerateCheckResult
} finally {
Pop-Location
}
} finally {
Pop-Location
} else {
Write-Host 'The build result is up to date.'
}
54 changes: 30 additions & 24 deletions macos/build.ps1
Original file line number Diff line number Diff line change
@@ -1,35 +1,41 @@
param (
[string] $td = "$PSScriptRoot/../td"
[string] $td = "$PSScriptRoot/../td",
[string] $CheckUpToDateScript = "$PSScriptRoot/../common/Test-UpToDate.ps1",
[switch] $SkipUpToDateCheck
)

$ErrorActionPreference = 'Stop'
Set-StrictMode -Version Latest

if (-not (Test-Path $td/build)) {
New-Item -Type Directory $td/build
}
if ($SkipUpToDateCheck -or !$(& $CheckUpToDateScript)) {
if (-not (Test-Path $td/build)) {
New-Item -Type Directory $td/build
}

Push-Location $td/build
try {
$cmakeArguments = @(
'-DCMAKE_BUILD_TYPE=Release'
'-DOPENSSL_ROOT_DIR=/usr/local/opt/openssl/'
'..'
)
$cmakeBuildArguments = @(
'--build'
'.'
)
Push-Location $td/build
try {
$cmakeArguments = @(
'-DCMAKE_BUILD_TYPE=Release'
'-DOPENSSL_ROOT_DIR=/usr/local/opt/openssl/'
'..'
)
$cmakeBuildArguments = @(
'--build'
'.'
)

cmake @cmakeArguments
if (!$?) {
throw 'Cannot execute cmake'
}
cmake @cmakeArguments
if (!$?) {
throw 'Cannot execute cmake'
}

cmake @cmakeBuildArguments
if (!$?) {
throw 'Cannot execute cmake --build'
cmake @cmakeBuildArguments
if (!$?) {
throw 'Cannot execute cmake --build'
}
} finally {
Pop-Location
}
} finally {
Pop-Location
} else {
Write-Host 'The build result is up to date.'
}
84 changes: 45 additions & 39 deletions windows/build.ps1
Original file line number Diff line number Diff line change
@@ -1,54 +1,60 @@
param (
[string] $td = "$PSScriptRoot/../td",
[string] $Platform = 'x64-windows',
[Parameter(Mandatory = $true)] [string] $VcpkgToolchain
[Parameter(Mandatory = $true)] [string] $VcpkgToolchain,
[string] $CheckUpToDateScript = "$PSScriptRoot/../common/Test-UpToDate.ps1",
[switch] $SkipUpToDateCheck
)

$ErrorActionPreference = 'Stop'
Set-StrictMode -Version Latest

if (-not (Test-Path $td/build)) {
New-Item -Type Directory $td/build
}
if ($SkipUpToDateCheck -or !$(& $CheckUpToDateScript)) {
if (-not (Test-Path $td/build)) {
New-Item -Type Directory $td/build
}

Push-Location $td/build
try {
$vcpkgArguments = @(
'install'
"gperf:$platform"
"openssl:$platform"
"zlib:$platform"
)
$cmakeArguments = @(
"-DCMAKE_TOOLCHAIN_FILE=$VcpkgToolchain"
'-DCMAKE_DISABLE_FIND_PACKAGE_Readline=TRUE' # workaround for #76
'..'
)
$cmakeBuildArguments = @(
'--build'
'.'
'--config'
'Release'
)
Push-Location $td/build
try {
$vcpkgArguments = @(
'install'
"gperf:$platform"
"openssl:$platform"
"zlib:$platform"
)
$cmakeArguments = @(
"-DCMAKE_TOOLCHAIN_FILE=$VcpkgToolchain"
'-DCMAKE_DISABLE_FIND_PACKAGE_Readline=TRUE' # workaround for #76
'..'
)
$cmakeBuildArguments = @(
'--build'
'.'
'--config'
'Release'
)

if ($Platform -eq 'x64-windows') {
$cmakeArguments += @('-A', 'X64')
}
if ($Platform -eq 'x64-windows') {
$cmakeArguments += @('-A', 'X64')
}

vcpkg @vcpkgArguments
if (!$?) {
throw 'Cannot execute vcpkg'
}
vcpkg @vcpkgArguments
if (!$?) {
throw 'Cannot execute vcpkg'
}

cmake @cmakeArguments
if (!$?) {
throw 'Cannot execute cmake'
}
cmake @cmakeArguments
if (!$?) {
throw 'Cannot execute cmake'
}

cmake @cmakeBuildArguments
if (!$?) {
throw 'Cannot execute cmake --build'
cmake @cmakeBuildArguments
if (!$?) {
throw 'Cannot execute cmake --build'
}
} finally {
Pop-Location
}
} finally {
Pop-Location
} else {
Write-Host 'The build result is up to date.'
}

0 comments on commit 35954d8

Please sign in to comment.