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
75 changes: 75 additions & 0 deletions .github/workflows/Release-Decision.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Release decision

on:
pull_request:
branches:
- main
types:
- opened
- reopened
- synchronize
- labeled
- unlabeled
- edited

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

permissions:
contents: read
pull-requests: read

jobs:
ReleaseDecision:
name: Release decision
runs-on: ubuntu-latest
steps:
- name: Check out the candidate merge
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
ref: ${{ github.sha }}
persist-credentials: false

- name: Verify the pull request snapshot
shell: pwsh
env:
GH_TOKEN: ${{ github.token }}
run: $null = & '.\src\Test-ReleaseDecisionContext.ps1'

- name: Calculate the release decision
id: calculate
uses: ./
env:
PSMODULE_AUTO_RELEASE_CHECK_PUBLISHER: 'true'
with:
Mode: calculate

- name: Recheck and report the decision
shell: pwsh
env:
GH_TOKEN: ${{ github.token }}
RELEASE_DECISION: ${{ steps.calculate.outputs.Decision }}
RELEASE_VERSION: ${{ steps.calculate.outputs.ReleaseVersion }}
RELEASE_BUMP_SOURCE: ${{ steps.calculate.outputs.BumpSource }}
run: |
$ErrorActionPreference = 'Stop'
$checked = & '.\src\Test-ReleaseDecisionContext.ps1'
$decision = $env:RELEASE_DECISION
$version = $env:RELEASE_VERSION
$source = $env:RELEASE_BUMP_SOURCE
$hasVersion = -not [string]::IsNullOrWhiteSpace($version)
if ($decision -cnotin @('release', 'skip') -or -not $source -or
($decision -ceq 'release') -ne $hasVersion) {
throw 'Calculate did not return a complete release decision.'
}
[ordered]@{
PullRequest = $checked.Number
BaseBranch = $checked.BaseRef
BaseSha = $checked.BaseSha
HeadSha = $checked.HeadSha
MergeSha = $checked.MergeSha
Decision = $decision
BumpSource = $source
Candidate = $version
} | ConvertTo-Json
102 changes: 76 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,20 @@ The action ignores labels that are not in the table.

In `publish` mode during a pull request run with `WhatIf: false`, the action creates missing labels from the table.
It sets their colors and descriptions. It leaves all other labels unchanged.
If the event has no pull request, the action does not change labels or publish a release.
Push events do not change labels.

The action publishes a prerelease for an open pull request with `release:prerelease`.
The prerelease name uses the head branch name. When the tag does not exist, the action creates it at the exact pull request head commit.
The action publishes a prerelease for an open pull request with `release:prerelease`, or for a branch push that matches that pull request.
The prerelease name uses the head branch name. The version tag points to the exact pull request head commit.

A publishing run creates a stable release on a merge into the default branch unless the pull request has `release:skip`.
The version tag points to the merge commit. For a squash merge, this is the squash commit.
The action does not move an existing version tag. After publication, it sets each enabled major or minor tag to the same commit.
Only a push to the default branch can publish a stable release. The version tag points to the exact pushed commit.
If a pull request merged into the default branch at that commit, the action uses its current labels.
For a direct push without a matching pull request, set `DefaultBump` to `patch`, `minor`, or `major`.
The action does not move an existing stable version tag. After publication, it sets each enabled major or minor tag to the same commit.

By default, the release notes start with the pull request title and number, followed by the full pull request description.
Put release-specific upgrade instructions in that description.

If `AutoCleanup` is `true`, the action deletes matching prereleases and their tags when the pull request closes.
When the pull request closes, Publish does not create a release. If `AutoCleanup` is `true`, it deletes matching prereleases and their tags.
The `release:skip` label does not prevent cleanup.

For cleanup, the action finds the version number after `VersionPrefix`. It then matches the exact, case-sensitive identifier for the head branch.
Expand All @@ -60,7 +61,7 @@ The action uses [GitHub-Script](https://github.com/PSModule/GitHub-Script), whic

## Usage

This example shows the publishing job.
This example shows the prerelease and cleanup job. It does not publish stable releases.

```yaml
name: Release-GHRepository
Expand Down Expand Up @@ -90,17 +91,10 @@ jobs:
if: ${{ github.event.pull_request.head.repo.full_name == github.repository }}
runs-on: ubuntu-24.04
steps:
- name: Require the merge commit SHA
if: ${{ github.event.action == 'closed' && github.event.pull_request.merged && !github.event.pull_request.merge_commit_sha }}
shell: pwsh
run: throw 'GitHub did not report the merge commit SHA.'

- name: Checkout code
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
ref: >-
${{ github.event.action == 'closed' && github.event.pull_request.merged
&& github.event.pull_request.merge_commit_sha || github.event.pull_request.base.sha }}
ref: ${{ github.event.pull_request.base.sha }}
persist-credentials: false

- name: Release repository
Expand All @@ -111,8 +105,7 @@ Pin the action to the full commit SHA of a published release that supports these
Do not use a pull request head in a production workflow.
Use a moving major tag only if the producer's release automation controls it and moves it only to compatible stable releases in that major version.

The example uses `pull_request`. The publishing job skips pull requests from forks, including on merge.
For a merge, it checks out the exact merge commit. For other events, it checks out the base commit, not the pull request head.
The publishing job skips pull requests from forks. It checks out the base commit, not the pull request head.

### Calculate a version

Expand Down Expand Up @@ -144,28 +137,82 @@ The action reads the current labels and latest stable release from the target re
If GitHub reports no latest stable release, the action uses `0.0.0` as the baseline.
A failed read, a stale pull request, or an invalid decision fails the run without outputs.

Use a separate read-only job for the [required release decision check][release-decision-check].
Include `labeled` and `unlabeled` to check label changes. Do not use a path filter to skip the check.
Apply `release:skip` when a change does not need a release.
### Check a pull request

This repository's `Release decision` job runs on pull requests to `main`, including forks and changes that affect only documentation.
It checks the candidate merge commit and uses the release settings and literal inputs from the local publisher in `.github/workflows/Release.yml`.
The publisher must check out this repository at the workspace root before it invokes the local action.
If the workflow route or its inputs cannot be resolved, the check fails. Do not use expressions for publisher inputs that this check must evaluate.
The default settings file is optional. If the publisher names a file, include it in the candidate checkout.

The job uses read-only permissions. It checks the current labels and revisions again before it reports its decision.
Apply `release:skip` when a change does not need a release. The job still runs and passes for a valid skip.
The job is separate from `Action-Test` and is advisory. It does not prevent merges, and a label rerun alone does not invalidate a previous pass.
See the [required check design][release-decision-check] for future enforcement.

If a fork contribution needs publication, follow [Prerelease a fork contribution][fork-prerelease].

### Publish a version from Calculate

Use the Calculate outputs from the same GitHub event and commit. Use the same version settings in both steps.
Pass `ReleaseVersion` without the tag prefix. If Calculate returns `CalculatedAt`, pass it unchanged.
Publish checks the current labels, stable release history, version settings, and target commit before it writes to GitHub.
It rejects a stale or invalid version, a conflicting tag, and a supplied version when the event cannot publish.
It does not replace a rejected value with a new version.

On an open pull request with `release:prerelease`, use these steps to preview the handoff without changing GitHub:

```yaml
- name: Calculate the prerelease version
id: calculate
uses: PSModule/Release-GHRepository@<released-commit-sha>
with:
Mode: calculate

- name: Preview the exact prerelease
if: ${{ steps.calculate.outputs.Decision == 'release' }}
uses: PSModule/Release-GHRepository@<released-commit-sha>
with:
Mode: publish
ReleaseVersion: ${{ steps.calculate.outputs.ReleaseVersion }}
CalculatedAt: ${{ steps.calculate.outputs.CalculatedAt }}
WhatIf: true
```

In another job of the same workflow run, expose both step outputs as job outputs and pass them through `needs`.
If you do not need a separate Calculate step, omit both inputs. Publish calculates a version only when the event can publish:

```yaml
- name: Preview a prerelease with automatic version selection
uses: PSModule/Release-GHRepository@<released-commit-sha>
with:
Mode: publish
WhatIf: true
```

For a stable release, calculate and publish from the same default-branch push. Do not pass a prerelease version to that run.
Before you adopt this version, update any workflow that publishes stable releases on a pull request close.
This action change does not install a push trigger. Track the production transition in [#108][push-rollout].

## Inputs

`SettingsFilePath` selects the settings file. For the other inputs, a file value overrides the default.
`SettingsFilePath` selects the settings file. For inputs that are also settings, a file value overrides the default.
A nonempty input overrides the file value, even if the input equals the default. For Boolean settings, `false` overrides the file value.
If you omit an input or supply `null` or an empty string, the action keeps the file value.

| Name | Description | Effective default | Required |
| --- | --- | --- | --- |
| `Mode` | Use `calculate` for a read-only version or `publish` for the existing pull request publication workflow. | `publish` | false |
| `PullRequest` | Select a pull request as `OWNER/REPO#NUMBER` for a branch push in Calculate mode. | `''` | false |
| `Mode` | Use `calculate` for a read-only version or `publish` to create the release. | `publish` | false |
| `PullRequest` | Select a pull request as `OWNER/REPO#NUMBER` for a branch push. Publish must run in the target repository. | `''` | false |
| `ReleaseVersion` | Use the exact unprefixed version from Calculate. Omit it to calculate the version during Publish. | `''` | false |
| `CalculatedAt` | Pass the unchanged ISO 8601 UTC Calculate output with `ReleaseVersion` for a date-dependent prerelease. | `''` | false |
| `AutoCleanup` | Delete prereleases after the pull request closes. | `true` | false |
| `SettingsFilePath` | Select the repository settings file before startup. | `.github\auto-release.yml` | false |
| `DefaultBump` | Select the bump when no bump or skip label exists. Accepts exactly `none`, `patch`, `minor`, or `major` with case-sensitive matching. | `none` | false |
| `CreateMajorTag` | Create or update the floating major tag after a stable release. | `true` | false |
| `CreateMinorTag` | Create or update the floating minor tag after a stable release. | `true` | false |
| `DatePrereleaseFormat` | Append a [.NET date and time format](https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings) to prerelease versions. | `''` | false |
| `IncrementalPrerelease` | Enable prerelease numbering. When false, replace a release that has the same calculated prerelease tag. | `true` | false |
| `IncrementalPrerelease` | Enable prerelease numbering. When false, replace a release at the same prerelease tag. A supplied `ReleaseVersion` cannot move that tag to a different commit. | `true` | false |
| `UsePRTitleAsReleaseName` | Use the pull-request title as the GitHub Release name. | `false` | false |
| `UsePRBodyAsReleaseNotes` | Use the pull-request body as release notes. | `true` | false |
| `UsePRTitleAsNotesHeading` | Add the pull-request title and number as the release-notes heading. | `true` | false |
Expand Down Expand Up @@ -193,7 +240,8 @@ File selection and execution follow this order:
3. The action reads the file once. If the file specifies a relative `WorkingDirectory`, the action resolves it from `github.workspace`, not from the file's directory.
4. The action applies the defaults from `action.yml`, then the file values, then nonempty inputs. It runs in the resulting `WorkingDirectory` without selecting another settings file.

Use the input names in the table as YAML keys, except `SettingsFilePath`. The file must contain a YAML mapping.
Use the input names in the table as YAML keys, except `SettingsFilePath`, `ReleaseVersion`, and `CalculatedAt`.
The file must contain a YAML mapping.
The action checks the defaults, the file values, and all nonempty inputs before GitHub-Script starts.
It rejects unknown keys, null file values, and invalid values, even if a later input would override them.
Each specified working directory must exist.
Expand Down Expand Up @@ -243,6 +291,7 @@ These outputs are available only in Calculate mode. For example, read `steps.cal
| Name | Description |
| --- | --- |
| `Decision` | `release` if the version is valid. `skip` for a valid `release:skip` decision. |
| `BumpSource` | The release label or settings layer that supplied the decision. |
| `ReleaseVersion` | The calculated SemVer string without `VersionPrefix`. Empty for `skip`. |
| `CalculatedAt` | The ISO 8601 UTC instant used to calculate a date-dependent prerelease. Empty for other results. |

Expand Down Expand Up @@ -274,5 +323,6 @@ The caller job runs the composite action with `WhatIf: true`. These checks do no
[automation-labels]: https://msx.no/docs/Ways-of-Working/Automation-Labels/#namespacing
[release-decision-check]: https://msx.no/docs/Capabilities/release-management/design/#required-pre-merge-decision-check
[fork-prerelease]: https://msx.no/docs/Capabilities/release-management/design/#prerelease-a-fork-contribution
[push-rollout]: https://github.com/PSModule/Release-GHRepository/issues/108
[consumer-upgrades]: https://msx.no/docs/Ways-of-Working/Consumer-Upgrades/
[release-notes]: https://github.com/PSModule/Release-GHRepository/releases
43 changes: 35 additions & 8 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,24 @@ branding:
inputs:
Mode:
description: >-
Use calculate to return a version without changing the repository. Use publish for pull-request publication.
Use calculate to return a version without changing the repository. Use publish to create the release.
Effective standard default: publish.
required: false
PullRequest:
description: >-
Select a pull request as OWNER/REPO#NUMBER for a Calculate branch push.
Select a pull request as OWNER/REPO#NUMBER for a branch push.
The action checks that the pull request matches the push.
required: false
ReleaseVersion:
description: >-
An exact, unprefixed SemVer from Calculate. Publish validates it against the current release plan.
Omit it to calculate the version during Publish.
required: false
CalculatedAt:
description: >-
Pass the unchanged Calculate output with ReleaseVersion for a date-dependent prerelease.
Use the ISO 8601 UTC format returned by Calculate.
required: false
AutoCleanup:
description: >-
Delete pull-request prereleases and their tags after the pull request closes.
Expand All @@ -35,12 +45,12 @@ inputs:
required: false
CreateMajorTag:
description: >-
Control whether to create a major tag when a pull request is merged into the main branch.
Control whether to create or update a major tag after a stable release.
Effective standard default: true.
required: false
CreateMinorTag:
description: >-
Control whether to create a minor tag when a pull request is merged into the main branch.
Control whether to create or update a minor tag after a stable release.
Effective standard default: true.
required: false
DatePrereleaseFormat:
Expand Down Expand Up @@ -106,6 +116,9 @@ outputs:
Decision:
description: The Calculate decision, release or skip.
value: ${{ fromJSON(steps.release.outputs.result || '{}').Decision }}
BumpSource:
description: The release label or settings layer that supplied the Calculate decision.
value: ${{ fromJSON(steps.release.outputs.result || '{}').BumpSource }}
ReleaseVersion:
description: The unprefixed semantic version. Empty for skip.
value: ${{ fromJSON(steps.release.outputs.result || '{}').ReleaseVersion }}
Expand Down Expand Up @@ -161,14 +174,24 @@ runs:
PSMODULE_AUTO_RELEASE_INPUT_Version: ${{ inputs.Version }}
PSMODULE_AUTO_RELEASE_INPUT_Prerelease: ${{ inputs.Prerelease }}
run: |
$null = & (Join-Path -Path $env:PSMODULE_AUTO_RELEASE_ACTION_PATH -ChildPath 'src\Initialize-ReleaseConfiguration.ps1')
$configuration = @{}
if ($env:PSMODULE_AUTO_RELEASE_CHECK_PUBLISHER -ceq 'true') {
if ($env:PSMODULE_AUTO_RELEASE_INPUT_Mode -cne 'calculate') {
throw 'Publisher settings can only be evaluated in Calculate mode.'
}
$configuration.PublisherBranch = $env:GITHUB_BASE_REF
}
$bootstrap = Join-Path -Path $env:PSMODULE_AUTO_RELEASE_ACTION_PATH -ChildPath 'src\Initialize-ReleaseConfiguration.ps1'
$null = & $bootstrap @configuration

- name: Release-GHRepository
id: release
uses: PSModule/GitHub-Script@8083ec1f733f00357ee4d0db0c6056686e483bc0 # v1.9.0
uses: PSModule/GitHub-Script@8083ec1f733f00357ee4d0db0c6056686e483bc0 # v1.9.0
env:
PSMODULE_AUTO_RELEASE_ACTION_PATH: ${{ github.action_path }}
PSMODULE_AUTO_RELEASE_RESOLVED_SETTINGS: ${{ steps.settings.outputs.ReleaseSettings }}
PSMODULE_AUTO_RELEASE_INPUT_ReleaseVersion: ${{ inputs.ReleaseVersion }}
PSMODULE_AUTO_RELEASE_INPUT_CalculatedAt: ${{ inputs.CalculatedAt }}
with:
Debug: ${{ steps.settings.outputs.Debug }}
Prerelease: ${{ steps.settings.outputs.Prerelease }}
Expand All @@ -177,5 +200,9 @@ runs:
Name: Release-GHRepository
WorkingDirectory: ${{ steps.settings.outputs.WorkingDirectory }}
Script: |
$releaseSettings = ConvertFrom-Json -InputObject $env:PSMODULE_AUTO_RELEASE_RESOLVED_SETTINGS
& (Join-Path -Path $env:PSMODULE_AUTO_RELEASE_ACTION_PATH -ChildPath 'src\main.ps1') -Settings $releaseSettings
$parameters = @{
Settings = ConvertFrom-Json -InputObject $env:PSMODULE_AUTO_RELEASE_RESOLVED_SETTINGS
ReleaseVersion = $env:PSMODULE_AUTO_RELEASE_INPUT_ReleaseVersion
CalculatedAt = $env:PSMODULE_AUTO_RELEASE_INPUT_CalculatedAt
}
& (Join-Path -Path $env:PSMODULE_AUTO_RELEASE_ACTION_PATH -ChildPath 'src\main.ps1') @parameters
Loading
Loading