Skip to content
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
40 changes: 39 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ on:
- pull_request

env:
GOPROXY: off
GOFLAGS: -mod=vendor
GOPROXY: off

jobs:
lint:
Expand All @@ -22,6 +22,44 @@ jobs:
version: v1.42.0 # Has fixes for stylecheck configuration https://github.com/golangci/golangci-lint/pull/2017/files
args: --timeout=5m -v

verify-main-vendor:
runs-on: 'windows-2019'
env:
GOPROXY: "https://proxy.golang.org,direct"
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: '^1.15.0'
- name: Validate main modules
shell: powershell
run: |
$currentPath = (Get-Location).Path
$process = Start-Process powershell.exe -PassThru -Verb runAs -Wait -ArgumentList $currentPath/scripts/Verify-GoModules.ps1, $currentPath
if ($process.ExitCode -ne 0) {
Write-Error "Main modules are not up to date. Please run `go mod vendor` followed by `go mod tidy` in the repo root path."
}
exit $process.ExitCode

verify-test-vendor:
runs-on: 'windows-2019'
env:
GOPROXY: "https://proxy.golang.org,direct"
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: '^1.15.0'
- name: Validate test modules
shell: powershell
run: |
$currentPath = (Get-Location).Path
$process = Start-Process powershell.exe -PassThru -Verb runAs -Wait -ArgumentList $currentPath/scripts/Verify-GoModules.ps1, $currentPath, "test"
if ($process.ExitCode -ne 0) {
Write-Error "Test package modules are not up to date. Please run `go mod vendor` followed by `go mod tidy` in hcsshim/test directory."
}
exit $process.ExitCode

test:
runs-on: 'windows-2019'
steps:
Expand Down
63 changes: 63 additions & 0 deletions scripts/Verify-GoModules.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
function newTemporaryDirectory {
$parent = [System.IO.Path]::GetTempPath()
[string] $name = [System.Guid]::NewGuid()
New-Item -ItemType Directory -Path (Join-Path $parent $name)
}

function updateVendor {
param (
[string]$path
)
$currentPath = (Get-Location).Path
Set-Location $path
go mod vendor
go mod tidy
Set-Location $currentPath
}

function matchingHashes {
param (
[string]$rootPath,
[string]$tempPath
)
$rootHashes = Get-ChildItem -Recurse -Path $rootPath | foreach {Get-FileHash -Path $_.FullName -Algorithm SHA256}
if (-not $?) {
return $false
}
$tempHashes = Get-ChildItem -Recurse -Path $tempPath | foreach {Get-FileHash -Path $_.FullName -Algorithm SHA256}
if (-not $?) {
return $false
}
$diff = Compare-Object -ReferenceObject $rootHashes.Hash -DifferenceObject $tempHashes.Hash
if ($diff.Count -eq 0) {
return $true
}
return $false
}

$rootPath = $args[0]
$subdir = $args[1]

$tempDir = newTemporaryDirectory
Copy-Item -Path $rootPath/* -Destination $tempDir -Recurse
if (-not $?) {
Remove-Item $tempDir -Recurse
exit 1
}

updateVendor $tempDir/$subdir
if (-not $?) {
Remove-Item $tempDir -Recurse
exit 1
}

$hashesMatch = matchingHashes $rootPath/$subdir/vendor $tempDir/$subdir/vendor
if (-not $?) {
Remove-Item $tempDir -Recurse
exit 1
}

Remove-Item $tempDir -Recurse
if ($hashesMatch -ne $true) {
exit 1
}
Comment thread
dcantah marked this conversation as resolved.