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
121 changes: 121 additions & 0 deletions .github/workflows/Legacy-Baseline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
name: Legacy baseline

on:
pull_request:
branches: [main, 'integration/**']
paths:
- '.github/workflows/Legacy-Baseline.yml'
- '.github/workflows/Legacy-Release-Test.yml'
- 'tests-baseline/**'
- 'tests/LegacyCase.psm1'
- 'tests/LegacyCase.Tests.ps1'
- 'tests/Invoke-LegacyFixture.ps1'
- 'tests/ReleaseInventory.psm1'

permissions: {}

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
LEGACY_ACTION_SHA: 750abed0ecab02394554b610dc3aa191e75e3248 # PSModule/Release-GHRepository v2.0.3

jobs:
Simulated:
name: Run the pinned v2.0.3 logic against doubles
runs-on: ubuntu-24.04
permissions:
contents: read
steps:
- name: Check out the fixture
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false

- name: Check out the pinned legacy action
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
repository: PSModule/Release-GHRepository
ref: ${{ env.LEGACY_ACTION_SHA }}
path: .release-action
persist-credentials: false

- name: Install the modules the action uses
shell: pwsh
run: |
Install-PSResource -Name GitHub, PSSemVer, powershell-yaml -Repository PSGallery -TrustRepository
Get-Module GitHub, PSSemVer, powershell-yaml -ListAvailable | Format-Table Name, Version

- name: Test the baseline scenarios
uses: PSModule/Invoke-Pester@4ff33199141fdf22568990b6107fe3148ae93a1c # v5.1.0
env:
LEGACY_ACTION_PATH: ${{ github.workspace }}/.release-action
with:
Path: tests-baseline
Version: 6.1.0

- name: Test the legacy lane guard and verdict
Comment thread
MariusStorhaug marked this conversation as resolved.
Resolved
shell: pwsh
run: |
Install-PSResource -Name Pester -Version 6.1.0 -Repository PSGallery -TrustRepository
Import-Module Pester -RequiredVersion 6.1.0
$result = Invoke-Pester -Path tests/LegacyCase.Tests.ps1 -Output Detailed -PassThru
if ($result.FailedCount -gt 0 -or $result.TotalCount -eq 0) { throw 'The lane tests failed.' }

WhatIf:
name: Run the real composite in WhatIf mode with a read-only token
runs-on: ubuntu-24.04
permissions:
contents: read
steps:
- name: Check out the fixture
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false

- name: Check out the pinned legacy action
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
repository: PSModule/Release-GHRepository
ref: ${{ env.LEGACY_ACTION_SHA }}
path: .release-action
persist-credentials: false

- name: Record the release and tag inventory
id: before
shell: pwsh
env:
GH_TOKEN: ${{ github.token }}
run: |
$releases = gh api --paginate "repos/$env:GITHUB_REPOSITORY/releases" --jq '.[] | "\(.id) \(.tag_name)"'
if ($LASTEXITCODE -ne 0) { throw 'The release read failed.' }
$tags = gh api --paginate "repos/$env:GITHUB_REPOSITORY/tags" --jq '.[] | "\(.name) \(.commit.sha)"'
Comment thread
MariusStorhaug marked this conversation as resolved.
Resolved
if ($LASTEXITCODE -ne 0) { throw 'The tag read failed.' }
$state = @($releases) + @($tags) -join ';'
Add-Content -LiteralPath $env:GITHUB_OUTPUT -Value "state=$state"

- name: Preview with the legacy inputs
uses: ./.release-action
env:
GH_TOKEN: ${{ github.token }}
with:
AutoPatching: 'false'
AutoCleanup: 'false'
CreateMajorTag: 'false'
CreateMinorTag: 'false'
PatchLabels: release:patch
WhatIf: 'true'

- name: Confirm the preview wrote nothing
shell: pwsh
env:
GH_TOKEN: ${{ github.token }}
BEFORE: ${{ steps.before.outputs.state }}
run: |
$releases = gh api --paginate "repos/$env:GITHUB_REPOSITORY/releases" --jq '.[] | "\(.id) \(.tag_name)"'
if ($LASTEXITCODE -ne 0) { throw 'The release read failed.' }
$tags = gh api --paginate "repos/$env:GITHUB_REPOSITORY/tags" --jq '.[] | "\(.name) \(.commit.sha)"'
if ($LASTEXITCODE -ne 0) { throw 'The tag read failed.' }
$state = @($releases) + @($tags) -join ';'
if ($state -cne $env:BEFORE) { throw 'The WhatIf preview changed the release or tag inventory.' }
172 changes: 172 additions & 0 deletions .github/workflows/Legacy-Release-Test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
name: Legacy release integration

on:
pull_request:
branches: [main]
types: [closed]

permissions: {}

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

jobs:
Select:
name: Verify the merged legacy case
if: >-
${{ github.repository == 'PSModule/Release-GHRepository-Test-Legacy'
&& 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
&& github.event.pull_request.head.repo.full_name == github.repository
&& github.event.pull_request.base.repo.full_name == github.repository
&& github.event.pull_request.user.id == 314722336
&& github.event.pull_request.user.login == 'psmodule-s-shelly[bot]'
&& startsWith(github.event.pull_request.head.ref, 'release-fixture/') }}
runs-on: ubuntu-24.04
permissions:
contents: read
pull-requests: read
outputs:
caseId: ${{ steps.fixture.outputs.caseId }}
candidate: ${{ steps.fixture.outputs.candidate }}
scenario: ${{ steps.fixture.outputs.scenario }}
pullRequest: ${{ steps.fixture.outputs.pullRequest }}
head: ${{ steps.fixture.outputs.head }}
source: ${{ steps.fixture.outputs.source }}
steps:
- name: Check out the exact squash commit
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
ref: ${{ github.event.pull_request.merge_commit_sha }}
persist-credentials: false

- name: Verify the case, squash commit, and author
id: fixture
shell: pwsh
env:
GH_TOKEN: ${{ github.token }}
run: ./tests/Invoke-LegacyFixture.ps1 -Stage Select

CI:
name: Test the exact squash commit
needs: Select
runs-on: ubuntu-24.04
permissions:
contents: read
outputs:
testedSha: ${{ steps.source.outputs.sha }}
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: Test case selection and inventory assertions
uses: PSModule/Invoke-Pester@4ff33199141fdf22568990b6107fe3148ae93a1c # v5.1.0
with:
Path: tests
Version: 6.1.0

- name: Record the tested SHA
id: source
shell: pwsh
env:
SOURCE: ${{ needs.Select.outputs.source }}
run: |
$sha = git rev-parse HEAD
if ($LASTEXITCODE -ne 0 -or $sha -cne $env:SOURCE) {
throw 'CI did not test the squash commit.'
}
Add-Content -LiteralPath $env:GITHUB_OUTPUT -Value "sha=$sha"

Gate:
name: Require current main and an empty inventory
needs: [Select, CI]
if: ${{ needs.CI.outputs.testedSha == needs.Select.outputs.source }}
runs-on: ubuntu-24.04
permissions:
contents: read
outputs:
before: ${{ steps.gate.outputs.before }}
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
id: gate
shell: pwsh
env:
GH_TOKEN: ${{ github.token }}
FIXTURE_SOURCE: ${{ needs.Select.outputs.source }}
run: ./tests/Invoke-LegacyFixture.ps1 -Stage Gate

Publish:
name: Publish the legacy release
needs: [Select, CI, Gate]
if: ${{ needs.Gate.result == 'success' }}
runs-on: ubuntu-24.04
permissions:
contents: write
steps:
# The action runs git push origin --tags. Git needs the job token even when no local tag exists.
- name: Check out the exact squash commit with the job token
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
ref: ${{ needs.Select.outputs.source }}
persist-credentials: true

- name: Check main and the inventory again
shell: pwsh
env:
GH_TOKEN: ${{ github.token }}
FIXTURE_SOURCE: ${{ needs.Select.outputs.source }}
run: ./tests/Invoke-LegacyFixture.ps1 -Stage Gate

- name: Publish with the published legacy action
uses: PSModule/Release-GHRepository@750abed0ecab02394554b610dc3aa191e75e3248 # v2.0.3
env:
GH_TOKEN: ${{ github.token }}
with:
AutoPatching: 'false'
AutoCleanup: 'false'
CreateMajorTag: 'false'
CreateMinorTag: 'false'
PatchLabels: release:patch
WhatIf: 'false'

Verify:
name: Verify the fixture result
needs: [Select, CI, Gate, Publish]
if: ${{ !cancelled() && needs.Select.result == 'success' }}
runs-on: ubuntu-24.04
permissions:
contents: read
pull-requests: write
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: Verify and report the case
shell: pwsh
env:
GH_TOKEN: ${{ github.token }}
FIXTURE_CASE_ID: ${{ needs.Select.outputs.caseId }}
FIXTURE_CANDIDATE: ${{ needs.Select.outputs.candidate }}
FIXTURE_SCENARIO: ${{ needs.Select.outputs.scenario }}
FIXTURE_PR: ${{ needs.Select.outputs.pullRequest }}
FIXTURE_HEAD: ${{ needs.Select.outputs.head }}
FIXTURE_SOURCE: ${{ needs.Select.outputs.source }}
FIXTURE_BEFORE: ${{ needs.Gate.outputs.before }}
FIXTURE_CI: ${{ needs.CI.result }}
FIXTURE_TESTED_SHA: ${{ needs.CI.outputs.testedSha }}
FIXTURE_PUBLISH: ${{ needs.Publish.result }}
run: ./tests/Invoke-LegacyFixture.ps1 -Stage Verify
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,54 @@ Use **Verify the fixture result** or its PR report as the verdict. The overall r

Start with `staged` to publish a stable release at fixture `main`. Run `missing-decision` and `configured-default` only when `main` points to a published stable release. After a maintenance merge or a case that did not publish, use another explicit patch case to establish a new baseline. Keep test tags and releases as evidence. Use a new case instead of rerunning a push that already published.

## Legacy baseline

This layer follows fixture PR #3 and comes before the producer layers and the live comparison. [`Legacy-Baseline.yml`](.github/workflows/Legacy-Baseline.yml) verifies the published v2.0.3 (`750abed0ecab02394554b610dc3aa191e75e3248`) on pull requests with no write token and no release write. It never publishes.

| Job | Evidence |
| --- | --- |
| `Simulated` | Runs the unchanged `src/main.ps1` from the pinned checkout. A synthetic merged-PR event drives it. `gh` and `git` are doubles that answer the two read calls and record every other call as a write. Tests: [`tests-baseline`](tests-baseline). The real GitHub module supplies `LogGroup`. |
| `WhatIf` | Runs the real composite with `WhatIf: true` and a `contents: read` token. It compares the release and tag inventory before and after. |

The `Simulated` job covers these scenarios with the legacy inputs (`AutoPatching`, `AutoCleanup` and both alias tags off, `PatchLabels: release:patch`): explicit patch, first stable tag `v0.0.1` and a bump of the latest tag, preview with no writes, the `NoRelease` skip, an unnamespaced `major` label that overrides the patch label, and unmerged or non-main PRs. It also shows what the default inputs do: auto-patching, `release:skip` ignored, alias tags moved with `git tag -f`, and a configuration file that overrides the inputs.

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 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.

Run the baseline locally with the pinned checkout:

```powershell
git clone https://github.com/PSModule/Release-GHRepository.git "$env:TEMP/legacy-action"
git -C "$env:TEMP/legacy-action" checkout 750abed0ecab02394554b610dc3aa191e75e3248
Install-PSResource -Name GitHub, PSSemVer, powershell-yaml -TrustRepository
$env:LEGACY_ACTION_PATH = "$env:TEMP/legacy-action"
Invoke-Pester -Path .\tests-baseline
```

## Maintain the suite

[`tests/FixtureContract.json`](tests/FixtureContract.json) lists the supported cases and their labels. Shelly opens a same-repository PR from `release-fixture/<run-id>-<attempt>` to `main`. It adds `tests/cases/<run-id>-<attempt>.json` with `scenario` and `candidate`. On a push, the suite selects a case only from the Shelly PR merged at that commit. Other PRs and pushes run the fixture tests but do not run the action.

[`Release-Test.yml`](.github/workflows/Release-Test.yml) checks out the public producer at the exact candidate SHA and runs the local action. Only the Publish job can write fixture tags and releases. Only the Verify job can add reports to the fixture PR. The fixture does not mint or use Shelly's token. Never add app credentials or real release data to this repository.

## 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.

Requirements for the legacy repository:

- 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.
- 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.

Run the case selection and inventory tests without GitHub credentials:

```powershell
Expand Down
Loading
Loading