Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(#29, #55) CI: assert Windows dependencies of everything #72

Merged
merged 2 commits into from
May 10, 2022
Merged
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
14 changes: 14 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,20 @@ jobs:
name: tdlib.windows
path: ./artifacts

- name: Cache downloads for Windows
uses: actions/cache@v2
with:
path: build/downloads
key: ${{ hashFiles('windows/install.ps1') }}

- name: Install dependencies
shell: pwsh
run: ./windows/install.ps1

- name: Windows-specific testing
shell: pwsh
run: ./windows/test.ps1

- name: Prepare package for testing
shell: pwsh
run: ./windows/prepare-package.ps1
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/.idea/
/build/

*.temp.txt
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,19 @@ If using .NET, then you'll probably need to also install [tdsharp][], and then u

For other technologies or if you don't want to use tdsharp in .NET, you can just download the binaries and then use them in a manner your technology allows to use dynamically loaded libraries. Consult the [TDLib][tdlib] documentation for further directions.

Library Dependencies
--------------------

On Windows, [Microsoft Visual C++ Redistributable][cpp.redist] of version 2019 or higher is required by TDLib.

Documentation
-------------

- [Changelog][docs.changelog]
- [License][docs.license]
- [Maintainership][docs.maintainership]

[cpp.redist]: https://docs.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-160
[docs.changelog]: ./CHANGELOG.md
[docs.license]: ./LICENSE_1_0.txt
[docs.maintainership]: ./MAINTAINERSHIP.md
Expand Down
49 changes: 49 additions & 0 deletions windows/install.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# NOTE: Only used in tests right now.
param (
$DependenciesLink = 'https://github.com/lucasg/Dependencies/releases/download/v1.11.1/Dependencies_x64_Release_.without.peview.exe.zip',
$DependenciesHash = '7D22DC00F1C09FD4415D48AD74D1CF801893E83B9A39944B0FCE6DEA7CEAEA99',
$DownloadStorage = "$PSScriptRoot/../build/downloads",
$DependenciesInstallPath = "$PSScriptRoot/../build/tools/dependencies"
)

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

if (!(Test-Path $DownloadStorage)) {
New-Item -Type Directory $DownloadStorage | Out-Null
}

$dependenciesFileName = [Uri]::new($DependenciesLink).Segments | Select-Object -Last 1
$dependenciesDownloadPath = "$DownloadStorage/$dependenciesFileName"
if (Test-Path $dependenciesDownloadPath) {
Write-Output "File `"$dependenciesDownloadPath`" already exists; checking its hash…"
$actualHash = Get-FileHash -Algorithm SHA256 $dependenciesDownloadPath
if ($actualHash.Hash -eq $DependenciesHash) {
Write-Output 'Hash check succeeded; reusing the downloaded item.'
} else {
Write-Output "Actual hash: $($actualHash.Hash)."
Write-Output "Expected hash: $DependenciesHash."
Write-Output "Deleting file for re-download…"
Remove-Item $dependenciesDownloadPath
}
}

if (!(Test-Path $dependenciesDownloadPath)) {
Write-Output "Downloading `"$DependenciesLink`"…"
Invoke-WebRequest $DependenciesLink -OutFile $dependenciesDownloadPath
}

$actualHash = Get-FileHash -Algorithm SHA256 $dependenciesDownloadPath
if ($actualHash.Hash -ne $DependenciesHash) {
Write-Output "Actual hash: $($actualHash.Hash)."
Write-Output "Expected hash: $DependenciesHash."
Write-Output "Hashes don't match."
throw 'Cannot download Dependencies tool.'
}

if (Test-Path $DependenciesInstallPath) {
Remove-Item -Recurse $DependenciesInstallPath
}

Expand-Archive $dependenciesDownloadPath $DependenciesInstallPath
Write-Output "Dependencies tool installed to directory `"$DependenciesInstallPath`"."
52 changes: 52 additions & 0 deletions windows/libraries.gold.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
libcrypto-3-x64.dll
ADVAPI32.dll
api-ms-win-crt-convert-l1-1-0.dll
api-ms-win-crt-environment-l1-1-0.dll
api-ms-win-crt-filesystem-l1-1-0.dll
api-ms-win-crt-heap-l1-1-0.dll
api-ms-win-crt-runtime-l1-1-0.dll
api-ms-win-crt-stdio-l1-1-0.dll
api-ms-win-crt-string-l1-1-0.dll
api-ms-win-crt-time-l1-1-0.dll
api-ms-win-crt-utility-l1-1-0.dll
bcrypt.dll
CRYPT32.dll
KERNEL32.dll
USER32.dll
VCRUNTIME140.dll
WS2_32.dll
libssl-3-x64.dll
api-ms-win-crt-convert-l1-1-0.dll
api-ms-win-crt-runtime-l1-1-0.dll
api-ms-win-crt-stdio-l1-1-0.dll
api-ms-win-crt-string-l1-1-0.dll
api-ms-win-crt-time-l1-1-0.dll
api-ms-win-crt-utility-l1-1-0.dll
KERNEL32.dll
libcrypto-3-x64.dll
VCRUNTIME140.dll
tdjson.dll
api-ms-win-crt-convert-l1-1-0.dll
api-ms-win-crt-heap-l1-1-0.dll
api-ms-win-crt-math-l1-1-0.dll
api-ms-win-crt-runtime-l1-1-0.dll
api-ms-win-crt-stdio-l1-1-0.dll
api-ms-win-crt-string-l1-1-0.dll
api-ms-win-crt-time-l1-1-0.dll
CRYPT32.dll
KERNEL32.dll
libcrypto-3-x64.dll
libssl-3-x64.dll
MSVCP140.dll
Normaliz.dll
VCRUNTIME140.dll
VCRUNTIME140_1.dll
WS2_32.dll
zlib1.dll
zlib1.dll
api-ms-win-crt-convert-l1-1-0.dll
api-ms-win-crt-heap-l1-1-0.dll
api-ms-win-crt-runtime-l1-1-0.dll
api-ms-win-crt-stdio-l1-1-0.dll
KERNEL32.dll
VCRUNTIME140.dll
43 changes: 43 additions & 0 deletions windows/test.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
param (
[string] $Dependencies = "$PSScriptRoot/../build/tools/dependencies/Dependencies.exe",

[string] $Artifacts = "$PSScriptRoot/../artifacts",
[string] $GoldFile = "$PSScriptRoot/../windows/libraries.gold.txt",
[string] $ResultFile = "$PSScriptRoot/../windows/libraries.temp.txt",
[switch] $GenerateGold
)

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

Write-Output "Saving library check results to $ResultFile…"

if (Test-Path $ResultFile) {
Remove-Item $ResultFile
}

Get-ChildItem "$Artifacts/*.dll" | Sort-Object -Property Name | ForEach-Object {
$libraryPath = $_.FullName

Write-Output "Checking file `"$libraryPath`"…"
$output = & $Dependencies -json -imports $libraryPath | ConvertFrom-Json
if (!$?) {
throw "Dependencies.exe returned an exit code $LASTEXITCODE."
}

$libraryNames = $output.Imports | Select-Object -ExpandProperty Name | Sort-Object
$_.Name >> $ResultFile
$libraryNames | ForEach-Object { " $_" >> $ResultFile }
}

if ($GenerateGold) {
Move-Item -Force $ResultFile $GoldFile
} else {
$goldContent = Get-Content -Raw $GoldFile
$tempContent = Get-Content -Raw $ResultFile
if ($goldContent -ne $tempContent) {
Write-Output "Current contents are following:`n"
Write-Output $tempContent
throw "File contents are not equal: $GoldFile and $ResultFile"
}
}