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
59 changes: 50 additions & 9 deletions .github/workflows/Release-Test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,18 @@ jobs:
name: Select the case and record the inventory
if: >-
${{ github.repository == 'PSModule/Release-GHRepository-Test'
&& (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository) }}
&& github.repository_id == '1477027955'
&& (github.event_name == 'push' || github.event.pull_request.head.repo.id == github.event.repository.id) }}
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 }}
before: ${{ steps.fixture.outputs.before }}
defaultBump: ${{ steps.fixture.outputs.defaultBump }}
whatIf: ${{ steps.fixture.outputs.whatIf }}
Expand All @@ -44,12 +50,17 @@ jobs:
Plan:
name: Calculate the version
needs: Prepare
if: ${{ needs.Prepare.outputs.caseId != '' }}
runs-on: ubuntu-24.04
permissions:
contents: read
pull-requests: read
outputs:
calculate: ${{ steps.calculate.outcome }}
control: >-
${{ steps.control.outcome == 'success' && steps.control.outputs.Decision == 'release'
&& steps.control.outputs.BumpSource == 'ActionInput' && steps.control.outputs.ReleaseVersion != ''
&& steps.control.outputs.ReleasePlan != '' }}
decision: ${{ steps.calculate.outputs.Decision }}
bumpSource: ${{ steps.calculate.outputs.BumpSource }}
version: ${{ steps.calculate.outputs.ReleaseVersion }}
Expand All @@ -61,9 +72,25 @@ jobs:
ref: ${{ github.sha }}
persist-credentials: false

- name: Check out the exact candidate
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
repository: PSModule/Release-GHRepository
ref: ${{ needs.Prepare.outputs.candidate }}
path: .release-action
persist-credentials: false

- name: Confirm the case can calculate with a default bump
id: control
if: ${{ needs.Prepare.outputs.scenario == 'missing-decision' }}
uses: ./.release-action
with:
Mode: calculate
DefaultBump: patch

- name: Calculate the version
id: calculate
uses: PSModule/Release-GHRepository@3f22cf227aee5709f430eeb79885a2121807a629 # PR 109 candidate
uses: ./.release-action
with:
Mode: calculate
DefaultBump: ${{ needs.Prepare.outputs.defaultBump }}
Expand All @@ -85,7 +112,7 @@ jobs:
ref: ${{ github.sha }}
persist-credentials: false

- name: Test the inventory assertions
- name: Test case selection and inventory assertions
uses: PSModule/Invoke-Pester@4ff33199141fdf22568990b6107fe3148ae93a1c # v5.1.0
with:
Path: tests
Expand All @@ -111,9 +138,9 @@ jobs:
name: Publish the tested commit
needs: [Prepare, Plan, CI]
if: >-
${{ github.repository == 'PSModule/Release-GHRepository-Test'
&& github.event_name == 'push' && github.ref_name == github.event.repository.default_branch
&& needs.Prepare.outputs.scenario != 'idle' && needs.Plan.outputs.decision == 'release' }}
${{ success() && github.event_name == 'push' && github.ref == 'refs/heads/main'
&& needs.Prepare.outputs.caseId != '' && needs.Plan.outputs.decision == 'release'
&& needs.CI.outputs.testedSha == github.sha }}
runs-on: ubuntu-24.04
permissions:
contents: write
Expand All @@ -125,6 +152,14 @@ jobs:
ref: ${{ github.sha }}
persist-credentials: false

- name: Check out the exact candidate
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
repository: PSModule/Release-GHRepository
ref: ${{ needs.Prepare.outputs.candidate }}
path: .release-action
persist-credentials: false

- name: Require the staged handoff
if: ${{ needs.Prepare.outputs.scenario != 'one-step' }}
shell: pwsh
Expand All @@ -137,7 +172,7 @@ jobs:

- name: Publish with the plan
if: ${{ needs.Prepare.outputs.scenario != 'one-step' }}
uses: PSModule/Release-GHRepository@3f22cf227aee5709f430eeb79885a2121807a629 # PR 109 candidate
uses: ./.release-action
with:
Mode: publish
DefaultBump: ${{ needs.Prepare.outputs.defaultBump }}
Expand All @@ -146,7 +181,7 @@ jobs:

- name: Calculate and publish in one step
if: ${{ needs.Prepare.outputs.scenario == 'one-step' }}
uses: PSModule/Release-GHRepository@3f22cf227aee5709f430eeb79885a2121807a629 # PR 109 candidate
uses: ./.release-action
with:
Mode: publish
DefaultBump: ${{ needs.Prepare.outputs.defaultBump }}
Expand All @@ -155,7 +190,7 @@ jobs:
Verify:
name: Verify the fixture result
needs: [Prepare, Plan, CI, Publish]
if: ${{ !cancelled() && needs.Prepare.result == 'success' }}
if: ${{ !cancelled() && needs.Prepare.result == 'success' && needs.Prepare.outputs.caseId != '' }}
runs-on: ubuntu-24.04
permissions:
contents: read
Expand All @@ -171,9 +206,15 @@ jobs:
shell: pwsh
env:
GH_TOKEN: ${{ github.token }}
FIXTURE_CASE_ID: ${{ needs.Prepare.outputs.caseId }}
FIXTURE_CANDIDATE: ${{ needs.Prepare.outputs.candidate }}
FIXTURE_SCENARIO: ${{ needs.Prepare.outputs.scenario }}
FIXTURE_PR: ${{ needs.Prepare.outputs.pullRequest }}
FIXTURE_HEAD: ${{ needs.Prepare.outputs.head }}
FIXTURE_BEFORE: ${{ needs.Prepare.outputs.before }}
FIXTURE_PLAN: ${{ needs.Plan.result }}
FIXTURE_CALCULATE: ${{ needs.Plan.outputs.calculate }}
FIXTURE_CONTROL: ${{ needs.Plan.outputs.control }}
FIXTURE_DECISION: ${{ needs.Plan.outputs.decision }}
FIXTURE_BUMP_SOURCE: ${{ needs.Plan.outputs.bumpSource }}
FIXTURE_VERSION: ${{ needs.Plan.outputs.version }}
Expand Down
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
# Release-GHRepository-Test

This private repository tests [Release-GHRepository](https://github.com/PSModule/Release-GHRepository) on GitHub Actions. It contains only synthetic data. Use it to verify a pinned action candidate before the producer publishes it. Test releases and tags belong to this repository only.
This public repository tests [Release-GHRepository](https://github.com/PSModule/Release-GHRepository) on GitHub Actions. It contains only synthetic data. Use it to verify a pinned action candidate before the producer publishes it. Test releases and tags belong to this repository only.

## Run a case

1. Use a short-lived GitHub App installation token scoped to `PSModule/Release-GHRepository-Test`. Use `Contents: write` for fixture branches and `Pull requests: write` for PRs, labels, and reading reports. Shelly already has these permissions. Do not store an app key or token in the fixture.
2. Open a same-repository PR to `main` that sets [`tests/Scenario.txt`](tests/Scenario.txt) to one case below. Include a unique synthetic change if the selected case is already on `main`. Apply only the labels listed for the case.
3. Use the `release-fixture-result` comment for the intended PR head and event. Its JSON has `source`, `head`, `run`, `attempt`, `scenario`, and `verified`. Wait for `verified: true` before continuing. Adding a label can start a new run; do not use the report from the unlabeled run to judge the labeled run.
4. For a push case, have an authorized reviewer follow the normal branch rules and squash-merge the PR. Use the `push` report on the same PR that names the exact squash commit. Do not merge `missing-decision`. Run one case at a time; the suite compares the whole test release and tag inventory before and after each run.
1. Dispatch the Shelly fixture driver from `main` in the [producer repository](https://github.com/PSModule/Release-GHRepository/actions). Select a scenario and, if needed, a same-repository producer PR to test. Shelly opens a fixture PR with that exact action SHA.
2. Wait for a schema 2 `release-fixture-result` comment from `github-actions[bot]` with `oracle: "success"` and `verified: true`. Match its case ID, candidate SHA, PR head, and event. For cases that need a label, use the `labeled` report. The opening event without the label runs only the fixture tests.
3. For a push case, follow the normal review rules and squash-merge the fixture PR. Run the producer driver again with the fixture PR number to verify the report for the exact squash commit. Close the `missing-decision` PR without merging it. Run one case at a time; each case compares the whole test release and tag inventory before and after the run.

| Case | Release label | Expected result |
| --- | --- | --- |
| `preview` | `release:patch` | Plan and CI pass. Publish previews the tested commit after merge and creates no tag or release. |
| `staged` | `release:patch` | After merge, Publish consumes the same-run plan and creates one stable release and tag at the tested commit. |
| `one-step` | `release:patch` | After merge, Publish calculates on demand and writes the same version Plan previewed, at the exact tested commit. |
| `configured-default` | None | Plan uses the explicit `DefaultBump: patch`. After merge, the staged publisher creates the release and tag. |
| `missing-decision` | None | Calculate fails. CI still runs. Verify confirms that no version, release, or tag was created. |
| `missing-decision` | None | A Calculate run with `DefaultBump: patch` succeeds. Without the default, Calculate fails. CI still runs and Verify confirms that no release or tag was created. |
| `skip` | `release:skip` | Plan returns `skip`. CI passes and Publish does not run. The release and tag inventory is unchanged. |
| `ci-failure` | `release:patch` | The PR can pass CI. After merge, CI fails deliberately on the pushed commit. Publish does not run and the inventory is unchanged. |
| `idle` | `release:skip` for a PR | The bootstrap case. It does not publish. |

Use the **Verify the fixture result** job or its PR report as the verdict. The overall run can fail for a deliberate negative case. Look for `No release bump` in Plan for the missing-decision case and for the intentional failure step for `ci-failure`. A missing report is not a pass. The app can read PR comments without new Actions permissions; people with Actions read access can follow the run link.
Use **Verify the fixture result** or its PR report as the verdict. The overall run fails for a deliberate missing decision or push CI failure. A missing report is not a pass. The driver reads PR comments without Actions permissions. Follow `run` in the report to see the separate jobs.

Keep test tags and releases as evidence. A subsequent write case must cover earlier merged changes that did not publish. Use the coverage marker and explicit bump from the action's [release range guidance](https://github.com/PSModule/Release-GHRepository/tree/3f22cf227aee5709f430eeb79885a2121807a629#usage). Use a new fixture commit instead of rerunning a push that already published.
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.

## Maintain the suite

Only a maintainer updates the three action pins together in [`Release-Test.yml`](.github/workflows/Release-Test.yml). The app only needs to change synthetic fixture files. The suite uses repository-scoped Actions tokens for publication and reports; it does not mint or expose the orchestrator's credential.
[`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.

Run the inventory assertion tests without GitHub credentials:
[`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.

Run the case selection and inventory tests without GitHub credentials:

```powershell
Import-Module -Name Pester -RequiredVersion 6.1.0
Expand Down
12 changes: 12 additions & 0 deletions tests/FixtureContract.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"schema": 2,
"scenarios": {
"preview": "release:patch",
"staged": "release:patch",
"one-step": "release:patch",
"configured-default": "",
"missing-decision": "",
"skip": "release:skip",
"ci-failure": "release:patch"
}
}
71 changes: 41 additions & 30 deletions tests/Invoke-ReleaseFixture.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ param(
$ErrorActionPreference = 'Stop'
Import-Module (Join-Path $PSScriptRoot 'ReleaseInventory.psm1')

if ($env:GITHUB_REPOSITORY -cne 'PSModule/Release-GHRepository-Test' -or
if ($env:GITHUB_REPOSITORY -cne 'PSModule/Release-GHRepository-Test' -or $env:GITHUB_REPOSITORY_ID -ne '1477027955' -or
$env:GITHUB_EVENT_NAME -cnotin @('pull_request', 'push') -or
$env:GITHUB_SHA -cnotmatch '^[0-9a-f]{40}$') {
$env:GITHUB_SHA -cnotmatch '\A[0-9a-f]{40}\z') {
throw 'This suite runs only for PRs and pushes in PSModule/Release-GHRepository-Test.'
}

Expand Down Expand Up @@ -54,33 +54,52 @@ function Get-ReleaseInventory {
}
}

$scenario = (Get-Content -LiteralPath (Join-Path $PSScriptRoot 'Scenario.txt') -Raw).Trim()
if ($scenario -cnotin @('idle', 'preview', 'staged', 'one-step', 'configured-default', 'missing-decision', 'skip', 'ci-failure')) {
throw "Unknown release fixture scenario [$scenario]."
}
$isPush = $env:GITHUB_EVENT_NAME -ceq 'push'
$eventPayload = Get-Content -LiteralPath $env:GITHUB_EVENT_PATH -Raw | ConvertFrom-Json -AsHashtable

if ($Stage -ceq 'Prepare') {
Import-Module (Join-Path $PSScriptRoot 'ReleaseCase.psm1')
$pullRequests = if ($isPush) {
if ($eventPayload.ref -cne 'refs/heads/main' -or $eventPayload.after -cne $env:GITHUB_SHA -or $eventPayload.deleted) {
throw 'The push must identify an exact fixture commit on main.'
}
Get-GitHubCollection -Resource "repos/$env:GITHUB_REPOSITORY/commits/$env:GITHUB_SHA/pulls"
} else {
$eventPayload.pull_request
}
$case = Get-ReleaseFixtureCase -Path $PSScriptRoot -EventName $env:GITHUB_EVENT_NAME -Source $env:GITHUB_SHA `
-PullRequests @($pullRequests | Where-Object { $_ })
if (-not $case) {
Write-Information 'No active release case. Run only the fixture tests.' -InformationAction Continue
return
}

$before = Get-ReleaseInventoryFingerprint -Inventory (Get-ReleaseInventory)
$defaultBump = if ($scenario -ceq 'configured-default') { 'patch' } else { 'none' }
$whatIf = if ($scenario -cin @('idle', 'preview')) { 'true' } else { 'false' }
$defaultBump = if ($case.Scenario -ceq 'configured-default') { 'patch' } else { 'none' }
$whatIf = if ($case.Scenario -ceq 'preview') { 'true' } else { 'false' }
Add-Content -LiteralPath $env:GITHUB_OUTPUT -Value @(
"scenario=$scenario"
"caseId=$($case.Id)"
"candidate=$($case.Candidate)"
"scenario=$($case.Scenario)"
"pullRequest=$($case.PullRequest)"
"head=$($case.Head)"
"before=$before"
"defaultBump=$defaultBump"
"whatIf=$whatIf"
)
return
}

$isPush = $env:GITHUB_EVENT_NAME -ceq 'push'
$eventPayload = Get-Content -LiteralPath $env:GITHUB_EVENT_PATH -Raw | ConvertFrom-Json -AsHashtable
$scenario = $env:FIXTURE_SCENARIO
$report = [ordered]@{
schema = 1
schema = 2
caseId = $env:FIXTURE_CASE_ID
candidate = $env:FIXTURE_CANDIDATE
scenario = $scenario
event = $env:GITHUB_EVENT_NAME
activity = $eventPayload.action
source = $env:GITHUB_SHA
head = $eventPayload.pull_request.head.sha
head = $env:FIXTURE_HEAD
run = "$env:GITHUB_SERVER_URL/$env:GITHUB_REPOSITORY/actions/runs/$env:GITHUB_RUN_ID"
attempt = $env:GITHUB_RUN_ATTEMPT
plan = $env:FIXTURE_PLAN
Expand All @@ -91,19 +110,23 @@ $report = [ordered]@{
testedSource = $env:FIXTURE_TESTED_SHA
publish = $env:FIXTURE_PUBLISH
tag = $null
oracle = 'failure'
verified = $false
}

try {
$expectMissing = $scenario -ceq 'missing-decision'
$expectSkip = $scenario -cin @('idle', 'skip')
$expectSkip = $scenario -ceq 'skip'
$expectFailure = $isPush -and $scenario -ceq 'ci-failure'
$expectPublish = $isPush -and -not ($expectMissing -or $expectSkip -or $expectFailure)

$planResult = if ($expectMissing) { 'failure' } else { 'success' }
if ($report.plan -cne $planResult -or $env:FIXTURE_CALCULATE -cne $planResult) {
throw "Expected the Calculate step and Plan job to report [$planResult]."
}
if ($expectMissing -and $env:FIXTURE_CONTROL -cne 'true') {
throw 'The missing-decision case must first calculate a release with a configured default.'
}
if ($expectMissing -or $expectSkip) {
$expectedDecision = if ($expectMissing) { '' } else { 'skip' }
if ($report.decision -cne $expectedDecision -or $report.version -or $env:FIXTURE_HAS_PLAN -cne 'false') {
Expand Down Expand Up @@ -136,25 +159,13 @@ try {
}
Assert-ReleaseInventory -Before $env:FIXTURE_BEFORE -After (Get-ReleaseInventory) -Source $report.source -ExpectedTag $expectedTag
$report.tag = $expectedTag
$report.oracle = 'success'
$report.verified = $true
} finally {
$body = @('<!-- release-fixture-result -->', '```json', (ConvertTo-Json $report -Compress), '```') -join "`n"
Add-Content -LiteralPath $env:GITHUB_STEP_SUMMARY -Value $body

$pullRequest = $eventPayload.pull_request.number
if ($isPush -and $scenario -cne 'idle') {
$mergedPullRequests = @(
Get-GitHubCollection -Resource "repos/$env:GITHUB_REPOSITORY/commits/$env:GITHUB_SHA/pulls" |
Where-Object {
$_.merged_at -and $_.merge_commit_sha -ceq $env:GITHUB_SHA -and
$_.head.repo.full_name -ceq $env:GITHUB_REPOSITORY -and $_.base.ref -ceq 'main'
}
)
if ($mergedPullRequests.Count -ne 1) { throw 'Expected one merged fixture PR at the pushed commit.' }
$pullRequest = $mergedPullRequests[0].number
}
if ($pullRequest) {
gh api --method POST "repos/$env:GITHUB_REPOSITORY/issues/$pullRequest/comments" -f "body=$body" --silent
if ($LASTEXITCODE -ne 0) { throw "Could not report the fixture result on PR [$pullRequest]." }
}
$pullRequest = $env:FIXTURE_PR
gh api --method POST "repos/$env:GITHUB_REPOSITORY/issues/$pullRequest/comments" -f "body=$body" --silent
if ($LASTEXITCODE -ne 0) { throw "Could not report the fixture result on PR [$pullRequest]." }
}
Loading