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
18 changes: 11 additions & 7 deletions .github/workflows/Legacy-Release-Test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ on:
permissions: {}

concurrency:
group: Release-GHRepository-Test-Legacy
group: Release-GHRepository-Test
queue: max

jobs:
Select:
name: Verify the merged legacy case
if: >-
${{ github.repository == 'PSModule/Release-GHRepository-Test-Legacy'
${{ github.repository == 'PSModule/Release-GHRepository-Test'
&& github.repository_id == '1477027955'
&& github.event_name == 'pull_request' && github.event.action == 'closed'
&& github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'main'
&& github.event.pull_request.head.repo.id == github.event.pull_request.base.repo.id
Expand Down Expand Up @@ -52,6 +53,7 @@ jobs:
CI:
name: Test the exact squash commit
needs: Select
if: ${{ needs.Select.outputs.caseId != '' }}
runs-on: ubuntu-24.04
permissions:
contents: read
Expand Down Expand Up @@ -83,22 +85,23 @@ jobs:
Add-Content -LiteralPath $env:GITHUB_OUTPUT -Value "sha=$sha"

Gate:
name: Require current main and an empty inventory
name: Require current main and calculate the expected tag
needs: [Select, CI]
if: ${{ needs.CI.outputs.testedSha == needs.Select.outputs.source }}
if: ${{ needs.Select.outputs.caseId != '' && needs.CI.outputs.testedSha == needs.Select.outputs.source }}
runs-on: ubuntu-24.04
permissions:
contents: read
outputs:
before: ${{ steps.gate.outputs.before }}
expectedTag: ${{ steps.gate.outputs.expectedTag }}
steps:
- name: Check out the exact squash commit
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
ref: ${{ needs.Select.outputs.source }}
persist-credentials: false

- name: Check main and the release and tag inventory
- name: Check main and calculate the expected tag
id: gate
shell: pwsh
env:
Expand All @@ -121,7 +124,7 @@ jobs:
ref: ${{ needs.Select.outputs.source }}
persist-credentials: true

- name: Check main and the inventory again
- name: Check main and the expected tag again
shell: pwsh
env:
GH_TOKEN: ${{ github.token }}
Expand All @@ -143,7 +146,7 @@ jobs:
Verify:
name: Verify the fixture result
needs: [Select, CI, Gate, Publish]
if: ${{ !cancelled() && needs.Select.result == 'success' }}
if: ${{ !cancelled() && needs.Select.result == 'success' && needs.Select.outputs.caseId != '' }}
runs-on: ubuntu-24.04
permissions:
contents: read
Expand All @@ -166,6 +169,7 @@ jobs:
FIXTURE_HEAD: ${{ needs.Select.outputs.head }}
FIXTURE_SOURCE: ${{ needs.Select.outputs.source }}
FIXTURE_BEFORE: ${{ needs.Gate.outputs.before }}
FIXTURE_EXPECTED_TAG: ${{ needs.Gate.outputs.expectedTag }}
FIXTURE_CI: ${{ needs.CI.result }}
FIXTURE_TESTED_SHA: ${{ needs.CI.outputs.testedSha }}
FIXTURE_PUBLISH: ${{ needs.Publish.result }}
Expand Down
25 changes: 18 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Known v2.0.3 behavior that the candidate changes on purpose:

- With `AutoPatching` off (the lane setting) and no deciding label, the "Skipping release creation" branch does not skip. It only leaves its `LogGroup` block, and the script attempts the unchanged version (`v0.0.0` on an empty inventory, or the latest tag again, which `gh` rejects). This is command evidence from the doubles. The released defaults (`AutoPatching` on) patch without a label. The candidate requires a decision.
- `release:skip` is unknown to v2.0.3. With auto-patching on, it still releases.
- The source of a release is the tip of `main` when `gh release create` runs. The doubles cannot show it. Only a hosted write run in the isolated legacy repository can.
- The source of a release is the tip of `main` when `gh release create` runs. The doubles cannot show it. Only a hosted write run of the legacy lane can.

The legacy lane below provides the hosted write evidence: one stable tag at the exact squash commit. The staged plan and the push CI gate exist only in the candidate. No legacy equivalent exists for those cases, so the baseline does not cover them. The doubles prove the logic only. They do not prove GitHub permissions, tag targets or the git push.

Expand All @@ -59,17 +59,28 @@ Invoke-Pester -Path .\tests-baseline

## Legacy lane

[`Legacy-Release-Test.yml`](.github/workflows/Legacy-Release-Test.yml) tests the published v2.0.3 composite (`PSModule/Release-GHRepository@750abed0ecab02394554b610dc3aa191e75e3248`) on a real merged pull request. It runs only in the separate repository `PSModule/Release-GHRepository-Test-Legacy`. This repository does not publish through it. The legacy repository is not provisioned yet.
[`Legacy-Release-Test.yml`](.github/workflows/Legacy-Release-Test.yml) tests the published v2.0.3 composite (`PSModule/Release-GHRepository@750abed0ecab02394554b610dc3aa191e75e3248`) on a real merged pull request in this repository. It does not use a separate repository.

Requirements for the legacy repository:
Routing: a case file whose `candidate` is the v2.0.3 SHA belongs to the legacy lane. The candidate lane skips it. Any other case belongs to the candidate lane, and the legacy lane skips it. Each case runs in exactly one lane.

- Create it as a separate repository with exactly the same `main` as this repository at provisioning time. Pin its numeric ID after creation.
- Keep its release and tag inventory empty before the case. The workflow stops if a release or tag exists, or if `main` is not the squash commit.
- Use normal review. Do not merge any other PR while the case runs. `gh release create` tags the current tip of `main`, so a concurrent merge breaks the case.
- Both lanes share one concurrency group and one release and tag inventory. v2.0.3 bumps the patch number of the latest release, or starts at `v0.0.1`. The `Gate` job calculates that tag from the inventory, and `Verify` expects exactly that one new stable release and tag at the squash commit.
- Use normal review. Do not merge any other PR while a legacy case runs. `gh release create` tags the current tip of `main`, so a concurrent merge breaks the case. `Gate` and `Publish` stop if `main` is not the squash commit.
- Shelly opens `release-fixture/<run-id>-<attempt>` with `release:patch` as the only label. v2.0.3 also reads `major`, `breaking`, `minor`, `feature` and `NoRelease`, so any other label fails the case. `Select` also fails if `.github/auto-release.yml` exists at the squash, because v2.0.3 lets that file override the workflow inputs. The PR adds only `tests/cases/<run-id>-<attempt>.json` with `{"scenario":"one-step","candidate":"750abed0ecab02394554b610dc3aa191e75e3248"}`. A verified single-parent squash must contain the same file.

Read-only jobs select the case, test the exact squash commit, and gate on current `main` and the empty inventory. Only `Publish` has `contents: write`. It uses only `GITHUB_TOKEN`, with `AutoPatching`, `AutoCleanup`, and the alias tags turned off. v2.0.3 runs `git push origin --tags`, which fails without credentials, so only `Publish` persists the job token at checkout. `Verify` expects one new stable `v<major>.<minor>.<patch>` release and tag at the squash commit. It reports a schema 2 `release-fixture-result` comment on the PR.
Read-only jobs select the case, test the exact squash commit, and gate on current `main` and the expected tag. Only `Publish` has `contents: write`. It uses only `GITHUB_TOKEN`, with `AutoPatching`, `AutoCleanup`, and the alias tags turned off. v2.0.3 runs `git push origin --tags`, which fails without credentials, so only `Publish` persists the job token at checkout. `Verify` reports a schema 2 `release-fixture-result` comment on the PR.

## Upgrade tracking

To see what an upgrade needs, run the same scenario twice: once with the legacy SHA and once with the candidate SHA. Compare the two reports (`candidate`, `tag`, `run`). The differences that the candidate introduces:

| Area | v2.0.3 (legacy) | Candidate |
| --- | --- | --- |
| Inputs | No `Mode`, `DefaultBump` or `ReleasePlan` | Has all three |
| Staged plan and push CI gate | None | Yes |
| No deciding label | Patches when `AutoPatching` is on | Requires a decision |
| `release:skip` | Unknown | Supported |
| `major`, `minor`, `NoRelease` and similar labels | Read without a prefix | Namespaced |
| Release source | Tip of `main` when `gh release create` runs | Exact squash commit |
Run the case selection and inventory tests without GitHub credentials:

```powershell
Expand Down
28 changes: 22 additions & 6 deletions tests/Invoke-LegacyFixture.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ $ErrorActionPreference = 'Stop'
Import-Module (Join-Path $PSScriptRoot 'ReleaseInventory.psm1')
Import-Module (Join-Path $PSScriptRoot 'LegacyCase.psm1')

if ($env:GITHUB_REPOSITORY -cne 'PSModule/Release-GHRepository-Test-Legacy' -or $env:GITHUB_EVENT_NAME -cne 'pull_request') {
throw 'This suite runs only for pull requests in PSModule/Release-GHRepository-Test-Legacy.'
if ($env:GITHUB_REPOSITORY -cne 'PSModule/Release-GHRepository-Test' -or $env:GITHUB_REPOSITORY_ID -ne '1477027955' -or
$env:GITHUB_EVENT_NAME -cne 'pull_request') {
throw 'This suite runs only for pull requests in PSModule/Release-GHRepository-Test.'
}
$repository = $env:GITHUB_REPOSITORY

Expand Down Expand Up @@ -74,11 +75,17 @@ if ($Stage -ceq 'Select') {
$squash = [string] $pullRequest.merge_commit_sha
if (-not $caseId -or $squash -cnotmatch '\A[0-9a-f]{40}\z') { throw 'The pull request does not identify a case and squash commit.' }

$squashCase = Get-CaseFile -Id $caseId -Ref $squash
if (-not (Test-LegacyCase -CaseJson $squashCase)) {
Write-Information "Case [$caseId] is not pinned to the legacy action. The candidate lane owns it." -InformationAction Continue
return
}

$commit = gh api "repos/$repository/commits/$squash" | ConvertFrom-Json -AsHashtable
if ($LASTEXITCODE -ne 0) { throw "Could not read the squash commit [$squash]." }
$case = Get-LegacyFixtureCase -EventPayload $eventPayload -Repository $repository `
-RepositoryId ([long] $env:GITHUB_REPOSITORY_ID) -Commit $commit -CommitFiles @($commit.files) `
-HeadCase (Get-CaseFile -Id $caseId -Ref $pullRequest.head.sha) -SquashCase (Get-CaseFile -Id $caseId -Ref $squash)
-HeadCase (Get-CaseFile -Id $caseId -Ref $pullRequest.head.sha) -SquashCase $squashCase

# v2.0.3 lets this file override the workflow inputs. The path uses a backslash by default.
foreach ($configuration in '.github/auto-release.yml', '.github\auto-release.yml') {
Expand All @@ -98,9 +105,17 @@ if ($Stage -ceq 'Select') {

if ($Stage -ceq 'Gate') {
$inventory = Get-ReleaseInventory
Assert-LegacyPublicationReady -MainSha (Get-MainSha) -Source $env:FIXTURE_SOURCE -Inventory $inventory
$latestTag = ''
if (@($inventory.releases).Count -gt 0) {
$latestTag = gh api "repos/$repository/releases/latest" --jq .tag_name
if ($LASTEXITCODE -ne 0) { throw 'Could not read the latest release.' }
}
$expectedTag = Get-LegacyExpectedTag -MainSha (Get-MainSha) -Source $env:FIXTURE_SOURCE -Inventory $inventory -LatestTag $latestTag
if ($env:GITHUB_OUTPUT) {
Add-Content -LiteralPath $env:GITHUB_OUTPUT -Value "before=$(Get-ReleaseInventoryFingerprint -Inventory $inventory)"
Add-Content -LiteralPath $env:GITHUB_OUTPUT -Value @(
"before=$(Get-ReleaseInventoryFingerprint -Inventory $inventory)"
"expectedTag=$expectedTag"
)
}
return
}
Expand Down Expand Up @@ -132,7 +147,8 @@ try {
if ((Get-MainSha) -cne $report.source) { throw 'Main moved during the run.' }

$after = Get-ReleaseInventory
$tag = Get-LegacyObservedTag -Source $report.source -After $after
$tag = $env:FIXTURE_EXPECTED_TAG
if ($tag -cnotmatch '\Av[0-9]+\.[0-9]+\.[0-9]+\z') { throw 'The gate did not supply a stable expected tag.' }
Assert-ReleaseInventory -Before $env:FIXTURE_BEFORE -After $after -Source $report.source -ExpectedTag $tag
$report.tag = $tag
$report.oracle = 'success'
Expand Down
87 changes: 52 additions & 35 deletions tests/LegacyCase.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
BeforeAll {
Import-Module (Join-Path $PSScriptRoot 'LegacyCase.psm1') -Force

$script:repository = 'PSModule/Release-GHRepository-Test-Legacy'
$script:repository = 'PSModule/Release-GHRepository-Test'
$script:candidate = '750abed0ecab02394554b610dc3aa191e75e3248'
$script:squash = 'c' * 40
$script:workflow = Get-Content -LiteralPath (Join-Path $PSScriptRoot '..\.github\workflows\Legacy-Release-Test.yml') -Raw
Expand All @@ -12,15 +12,15 @@ Describe 'Legacy fixture case' {
$caseFile = "{`"scenario`":`"one-step`",`"candidate`":`"$candidate`"}"
$script:arguments = @{
Repository = $repository
RepositoryId = 77
RepositoryId = 1477027955
EventPayload = @{
action = 'closed'
pull_request = @{
number = 3
merged = $true
user = @{ id = 314722336; login = 'psmodule-s-shelly[bot]' }
base = @{ ref = 'main'; repo = @{ id = 77; full_name = $repository } }
head = @{ ref = 'release-fixture/123-1'; sha = 'b' * 40; repo = @{ id = 77; full_name = $repository } }
base = @{ ref = 'main'; repo = @{ id = 1477027955; full_name = $repository } }
head = @{ ref = 'release-fixture/123-1'; sha = 'b' * 40; repo = @{ id = 1477027955; full_name = $repository } }
labels = @(@{ name = 'release:patch' })
merge_commit_sha = $squash
}
Expand All @@ -46,8 +46,11 @@ Describe 'Legacy fixture case' {
$case.Scenario | Should -BeExactly 'one-step'
}

It 'rejects the candidate repository' {
$arguments.Repository = 'PSModule/Release-GHRepository-Test'
It 'rejects another repository or repository ID' {
$arguments.Repository = 'PSModule/Release-GHRepository-Test-Legacy'
{ Get-LegacyFixtureCase @arguments } | Should -Throw '*Only*'
$arguments.Repository = $repository
$arguments.RepositoryId = 77
{ Get-LegacyFixtureCase @arguments } | Should -Throw '*Only*'
}

Expand Down Expand Up @@ -94,39 +97,47 @@ Describe 'Legacy fixture case' {
}
}

Describe 'Legacy publication gate and verdict' {
It 'requires main at the squash and an empty inventory' {
$empty = @{ tags = @(); releases = @() }
{ Assert-LegacyPublicationReady -MainSha $squash -Source $squash -Inventory $empty } | Should -Not -Throw
{ Assert-LegacyPublicationReady -MainSha ('d' * 40) -Source $squash -Inventory $empty } | Should -Throw '*moved*'
{ Assert-LegacyPublicationReady -MainSha $squash -Source $squash -Inventory @{
tags = @(@{ name = 'v0.0.1'; sha = $squash }); releases = @()
} } | Should -Throw '*no release or tag*'
Describe 'Legacy case routing' {
It 'owns only cases pinned to the published legacy action' {
Test-LegacyCase -CaseJson "{`"scenario`":`"one-step`",`"candidate`":`"$candidate`"}" | Should -BeTrue
Test-LegacyCase -CaseJson ('{"scenario":"one-step","candidate":"' + ('f' * 40) + '"}') | Should -BeFalse
Test-LegacyCase -CaseJson 'not json' | Should -BeFalse
Test-LegacyCase -CaseJson '[]' | Should -BeFalse
}
}

Context 'observed tag' {
BeforeEach {
$script:after = @{
tags = @(@{ name = 'v0.0.1'; sha = $squash })
releases = @(@{ tag = 'v0.0.1'; id = 9; draft = $false; prerelease = $false })
}
Describe 'Legacy publication gate' {
BeforeEach {
$script:inventory = @{
tags = @(@{ name = 'v1.2.9'; sha = 'a' * 40 }, @{ name = 'v1.2.10'; sha = 'b' * 40 })
releases = @(@{ tag = 'v1.2.9'; id = 1; draft = $false; prerelease = $false }, @{ tag = 'v1.2.10'; id = 2; draft = $false; prerelease = $false })
}
}

It 'returns the one stable tag at the squash' {
Get-LegacyObservedTag -Source $squash -After $after | Should -BeExactly 'v0.0.1'
}
It 'starts at v0.0.1 in an empty inventory' {
Get-LegacyExpectedTag -MainSha $squash -Source $squash -Inventory @{ tags = @(); releases = @() } |
Should -BeExactly 'v0.0.1'
}

It 'rejects <Name>' -ForEach @(
@{ Name = 'a tag at another commit'; Change = { $after.tags[0].sha = 'd' * 40 } }
@{ Name = 'an alias tag'; Change = { $after.tags += @{ name = 'v0'; sha = $squash } } }
@{ Name = 'a prerelease'; Change = { $after.releases[0].prerelease = $true } }
@{ Name = 'a draft'; Change = { $after.releases[0].draft = $true } }
@{ Name = 'no release'; Change = { $after.releases = @() } }
@{ Name = 'a release for another tag'; Change = { $after.releases[0].tag = 'v0.0.2' } }
) {
& $Change
{ Get-LegacyObservedTag -Source $squash -After $after } | Should -Throw
It 'bumps the patch number of the latest release numerically' {
Get-LegacyExpectedTag -MainSha $squash -Source $squash -Inventory $inventory -LatestTag 'v1.2.10' |
Should -BeExactly 'v1.2.11'
}

It 'rejects <Name>' -ForEach @(
@{ Name = 'a main that moved'; Change = { $script:main = 'd' * 40 } }
@{ Name = 'a latest tag that is not stable'; Change = { $script:latest = 'v1.2.3-beta1' } }
@{ Name = 'releases without a latest release'; Change = { $script:latest = '' } }
@{ Name = 'an existing tag for the next version'; Change = { $inventory.tags += @{ name = 'v1.2.11'; sha = 'c' * 40 } } }
@{ Name = 'an existing release for the next version'; Change = {
$inventory.releases += @{ tag = 'v1.2.11'; id = 3; draft = $true; prerelease = $false }
}
}
) {
$script:main = $squash
$script:latest = 'v1.2.10'
& $Change
{ Get-LegacyExpectedTag -MainSha $main -Source $squash -Inventory $inventory -LatestTag $latest } | Should -Throw
}
}

Expand Down Expand Up @@ -154,8 +165,14 @@ Describe 'Legacy workflow contract' {
$workflow | Should -Not -Match 'pull_request_target|workflow_dispatch|\bpush:'
}

It 'guards on the exact legacy repository, merged Shelly case, and main' {
foreach ($guard in "github.repository == 'PSModule/Release-GHRepository-Test-Legacy'",
It 'shares the candidate lane concurrency group and runs jobs only for legacy cases' {
$workflow | Should -Match '(?m)^ group: Release-GHRepository-Test$'
([regex]::Matches($workflow, "needs\.Select\.outputs\.caseId != ''")).Count | Should -BeGreaterOrEqual 3
}

It 'guards on this repository, a merged Shelly case, and main' {
foreach ($guard in "github.repository == 'PSModule/Release-GHRepository-Test'",
"github.repository_id == '1477027955'",
"github.event.action == 'closed'", 'github.event.pull_request.merged == true',
'head.repo.id == github.event.pull_request.base.repo.id', 'user.id == 314722336',
"'psmodule-s-shelly[bot]'", "'release-fixture/'") {
Expand Down
Loading
Loading