tests(bucket): Use BuildHelpers EnvVars (#5226)

This commit is contained in:
Hsiao-nan Cheung
2022-10-28 15:20:36 +08:00
committed by GitHub
parent e4f9734b88
commit ea6c73880a
3 changed files with 6 additions and 17 deletions

View File

@@ -32,6 +32,7 @@
- **unix:** Fix tests in Linux and macOS ([#5179](https://github.com/ScoopInstaller/Scoop/issues/5179)) - **unix:** Fix tests in Linux and macOS ([#5179](https://github.com/ScoopInstaller/Scoop/issues/5179))
- **pester:** Update to Pester 5 ([#5222](https://github.com/ScoopInstaller/Scoop/issues/5222)) - **pester:** Update to Pester 5 ([#5222](https://github.com/ScoopInstaller/Scoop/issues/5222))
- **bucket:** Use BuildHelpers' EnvVars ([#5226](https://github.com/ScoopInstaller/Scoop/issues/5226))
### Documentation ### Documentation

View File

@@ -1,4 +1,5 @@
#Requires -Version 5.1 #Requires -Version 5.1
#Requires -Modules @{ ModuleName = 'BuildHelpers'; ModuleVersion = '2.0.1' }
#Requires -Modules @{ ModuleName = 'Pester'; ModuleVersion = '5.2.0' } #Requires -Modules @{ ModuleName = 'Pester'; ModuleVersion = '5.2.0' }
param( param(
[String] $BucketPath = $MyInvocation.PSScriptRoot [String] $BucketPath = $MyInvocation.PSScriptRoot
@@ -14,18 +15,8 @@ Describe 'Manifest validates against the schema' {
$BucketPath $BucketPath
} }
if ($env:CI -eq $true) { if ($env:CI -eq $true) {
$commit = if ($env:GITHUB_SHA) { Set-BuildEnvironment -Force
# GitHub Actions $changedManifests = @(Get-GitChangedFile -Path $bucketDir -Include '*.json' -Commit $env:BHCommitHash)
$env:GITHUB_SHA
} elseif ($env:APPVEYOR_PULL_REQUEST_HEAD_COMMIT) {
# AppVeyor
$env:APPVEYOR_PULL_REQUEST_HEAD_COMMIT
} else {
$env:APPVEYOR_REPO_COMMIT
}
if ($commit) {
$changedManifests = @(Get-GitChangedFile -Path $bucketDir -Include '*.json' -Commit $commit)
}
} }
$manifestFiles = (Get-ChildItem $bucketDir -Filter '*.json' -Recurse).FullName $manifestFiles = (Get-ChildItem $bucketDir -Filter '*.json' -Recurse).FullName
if ($changedManifests) { if ($changedManifests) {

View File

@@ -26,17 +26,14 @@ if ($env:CI -eq $true) {
Write-Host "Load 'BuildHelpers' environment variables ..." Write-Host "Load 'BuildHelpers' environment variables ..."
Set-BuildEnvironment -Force Set-BuildEnvironment -Force
$commit = $env:BHCommitHash
$commitMessage = $env:BHCommitMessage
# Check if tests are called from the Core itself, if so, adding excludes # Check if tests are called from the Core itself, if so, adding excludes
if ($TestPath -eq (Convert-Path "$PSScriptRoot\..")) { if ($TestPath -eq (Convert-Path "$PSScriptRoot\..")) {
if ($commitMessage -match '!linter') { if ($env:BHCommitMessage -match '!linter') {
Write-Warning "Skipping code linting per commit flag '!linter'" Write-Warning "Skipping code linting per commit flag '!linter'"
$excludes += 'Linter' $excludes += 'Linter'
} }
$changedScripts = (Get-GitChangedFile -Include '*.ps1', '*.psd1', '*.psm1' -Commit $commit) $changedScripts = (Get-GitChangedFile -Include '*.ps1', '*.psd1', '*.psm1' -Commit $env:BHCommitHash)
if (!$changedScripts) { if (!$changedScripts) {
Write-Warning "Skipping tests and code linting for PowerShell scripts because they didn't change" Write-Warning "Skipping tests and code linting for PowerShell scripts because they didn't change"
$excludes += 'Linter' $excludes += 'Linter'