diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5c6e26c8e..bebbd2728 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -22,21 +22,33 @@ on: jobs: release: + # When this workflow is triggered by workflow_dispatch, the optic release + # action will create the release PR targeting the branch that the workflow + # is dispatched from. + # + # We only run this job when it's triggered by workflow_dispatch targeting + # the default branch, unless it's a prerelease, where we allow releases + # against branches other than the default. This is to ensure that actual + # releases tag commits on the main branch, to avoid confusion about where a + # release has come from. + # + # The workflow also runs when either a PR is closed or merged (the `types: + # [closed]` triggers this on both). We skip this job on PRs by authors other + # than optic-release-automation[bot]. When a PR is merged, the bot will + # publish the release to npm. When it's closed, the bot will delete the + # draft release that's created when the PR is opened. if: >- ${{ ( - startsWith(github.event.inputs.semver, 'pre') || - github.ref == format( - 'refs/heads/{0}', - github.event.repository.default_branch - ) - ) && - ( - github.event_name != 'pull_request' || + github.event_name == 'workflow_dispatch' && ( - github.event.pull_request.merged && - github.event.pull_request.user.login == 'optic-release-automation[bot]' + startsWith(github.event.inputs.semver, 'pre') || + github.ref == format('refs/heads/{0}', github.event.repository.default_branch) ) + ) || + ( + github.event_name == 'pull_request' && + github.event.pull_request.user.login == 'optic-release-automation[bot]' ) }} runs-on: ubuntu-latest @@ -51,8 +63,8 @@ jobs: commit-message: 'Release {version}' sync-semver-tags: false access: 'public' - # This prefix is added before the prerelease number, e.g. `v3.0.0-next.0` - prerelease-prefix: 'next' + # This prefix is added before the prerelease number, e.g. `v3.0.0-pre.0` + prerelease-prefix: 'pre' semver: ${{ github.event.inputs.semver }} # Prereleases are published under the `next` npm dist-tag npm-tag: ${{ startsWith(github.event.inputs.semver, 'pre') && 'next' || 'latest' }}