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
2 changes: 2 additions & 0 deletions dependency-updates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Target repositories contain dependency declarations and consistency tests, but n

The scheduled workflow reads `targets.json`, checks out each repository, and invokes the update
engine published by `AtlassianPS.Standards`.
The controller synchronizes workflow pins and the expected SHA in the existing
`Tests/Tools/StandardsVersionConsistency.Unit.Tests.ps1` assertion together.
It creates or refreshes `automation/update-powershell-dependencies` when files change.
The controller and workflow contract are validated by the repository's `CI` workflow.

Expand Down
32 changes: 32 additions & 0 deletions dependency-updates/Tests/Update-RepositoryDependencies.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,38 @@ Describe 'Update-RepositoryDependencies' {
[System.IO.File]::ReadAllBytes($plainPath)[0] | Should -Not -Be 0xEF
}

It 'synchronizes the existing <Variable> consistency assertion without renaming it' -ForEach @(
@{ Variable = '$expectedStandardsSha'; HasBom = $true; NewLine = "`r`n" }
@{ Variable = '$script:standardsActionSha'; HasBom = $false; NewLine = "`n" }
) {
$repositoryPath = Join-Path $TestDrive 'consistency-test'
New-TestRepository -Path $repositoryPath
$testsPath = Join-Path $repositoryPath 'Tests/Tools'
$null = New-Item -ItemType Directory -Path $testsPath -Force
$testPath = Join-Path $testsPath 'StandardsVersionConsistency.Unit.Tests.ps1'
$oldSha = '0' * 40
$newSha = 'c' * 40
$originalText = "$Variable = '$oldSha'" + $NewLine + '$actualSha | Should -Be @(' + $Variable + ')' + $NewLine
$encoding = [System.Text.UTF8Encoding]::new($HasBom)
[System.IO.File]::WriteAllText($testPath, $originalText, $encoding)
Mock Invoke-RestMethod { [PSCustomObject]@{ sha = $newSha } }
Mock Get-PSRepository { [PSCustomObject]@{ InstallationPolicy = 'Trusted' } }
Mock Get-Module { [PSCustomObject]@{ Version = [Version]'0.3.1' } }
Mock Import-Module
Mock Invoke-StandardsDependencyUpdate { [PSCustomObject]@{ Changed = $false } }

Invoke-RepositoryDependencyUpdate -RepositoryPath $repositoryPath -ModuleName TestModule -StandardsVersion '0.3.1'

$expectedText = $originalText.Replace($oldSha, $newSha)
[System.IO.File]::ReadAllText($testPath) | Should -BeExactly $expectedText
$expectedBytes = @($encoding.GetPreamble()) + @($encoding.GetBytes($expectedText))
[System.IO.File]::ReadAllBytes($testPath) | Should -Be $expectedBytes

Invoke-RepositoryDependencyUpdate -RepositoryPath $repositoryPath -ModuleName TestModule -StandardsVersion '0.3.1'

[System.IO.File]::ReadAllBytes($testPath) | Should -Be $expectedBytes
}

It 'fails when GitHub does not return a commit SHA' {
$repositoryPath = Join-Path $TestDrive 'invalid-sha'
New-TestRepository -Path $repositoryPath
Expand Down
14 changes: 14 additions & 0 deletions dependency-updates/Update-RepositoryDependencies.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,20 @@ function Sync-StandardsWorkflowReference {
Set-FileTextState -State $state -Text $updatedText
}
}

$consistencyTestPath = Join-Path $ProjectRoot 'Tests/Tools/StandardsVersionConsistency.Unit.Tests.ps1'
if (Test-Path -LiteralPath $consistencyTestPath -PathType Leaf) {
$state = Get-FileTextState -Path $consistencyTestPath
$updatedText = [regex]::Replace(
$state.Text,
'(?<prefix>\$(?:expectedStandardsSha|script:standardsActionSha)\s*=\s*[''"])[0-9a-f]{40}(?<suffix>[''"])',
('${prefix}' + $commit + '${suffix}')
)

if ($updatedText -ne $state.Text) {
Set-FileTextState -State $state -Text $updatedText
}
}
}

function Invoke-StandardsDependencyUpdate {
Expand Down
Loading