Skip to content

Commit

Permalink
fix(release-notes-preview): add breaking changes doc check
Browse files Browse the repository at this point in the history
This adds a new check that enforces that a breaking changes document has been created.
  • Loading branch information
greenkiwi committed Sep 14, 2023
1 parent 565ad60 commit 1076327
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 83 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: ./release-notes-preview
- uses: ./lint-release-notes
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
lint:
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ GitHub Actions for handling releases.

## Actions

### action: [`release-notes-preview`](./release-notes-preview)
### action: [`release-notes-preview`](./lint-release-notes)

Automatically generate release notes using semantic-release and post them as a comment in a pull request with the changes that would be included in the next version of the codebase if the pull request is merged.

See usage [here](./release-notes-preview/README.md#usage).
See usage [here](lint-release-notes/README.md#usage).

Documentation is found [here](./release-notes-preview/README.md).
Documentation is found [here](lint-release-notes/README.md).

## Get Help

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
release-notes:
name: Release notes preview
steps:
- uses: open-turo/actions-release/release-notes-preview@v1
- uses: open-turo/actions-release/lint-release-notes@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
```
Expand Down
163 changes: 163 additions & 0 deletions lint-release-notes/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
name: GitHub Action Release Notes Preview
description: GitHub Action that publishes a new release.
inputs:
github-token:
required: true
description: GitHub token that can checkout the repository as well as create tags/releases against it. e.g. 'secrets.GITHUB_TOKEN'
default: ${{ github.token }}
enforce-breaking-changes-docs:
required: false
description: Ensure that an appropriate `v<major-version>.md` doc has been created if there are breaking changes in the PR.
default: "true"
extra-plugins:
required: false
description: Extra plugins for pre-install. You can also specify specifying version range for the extra plugins if you prefer. Defaults to install @open-turo/semantic-release-config.
default: |
@open-turo/semantic-release-config
semantic-version:
required: false
description: Specify what version of semantic release to use
runs:
using: composite
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup tools
uses: open-turo/action-setup-tools@v1
with:
node: 18.16.1
- uses: jwalton/gh-find-current-pr@v1
id: find-pull-request
with:
state: open
- name: Generate release notes
id: release-notes-preview
uses: open-turo/actions-release/semantic-release@add-prerelease-support
env:
GITHUB_TOKEN: ${{ inputs.github-token }}
with:
branches: ${{ github.ref_name }}
dry-run: true
extra-plugins: ${{ inputs.extra-plugins }}
semantic-version: ${{ inputs.semantic-version }}

# Add release notes preview to PR
- name: Check for release notes comment
uses: peter-evans/find-comment@v2
id: fc-release-notes
if: steps.find-pull-request.outputs.number != ''
with:
issue-number: ${{ steps.find-pull-request.outputs.number }}
comment-author: "github-actions[bot]"
body-includes: "<!-- release notes preview comment -->"
- name: Delete previous release note
if: steps.fc-release-notes.outputs.comment-id != ''
uses: jungwinter/comment@v1
with:
type: delete
comment_id: ${{ steps.fc-release-notes.outputs.comment-id }}
token: ${{ inputs.github-token }}
- name: Comment release notes preview
uses: peter-evans/create-or-update-comment@v1
if: steps.release-notes-preview.outputs.new-release-notes != '' && steps.find-pull-request.outputs.number != ''
with:
issue-number: ${{ steps.find-pull-request.outputs.number }}
body: |
## Release notes preview
Below is a preview of the release notes if your PR gets merged.
---
<!-- release notes preview comment -->
${{ steps.release-notes-preview.outputs.new-release-notes }}
- name: Create no release created
uses: peter-evans/create-or-update-comment@v1
if: steps.release-notes-preview.outputs.new-release-notes == '' && steps.find-pull-request.outputs.number != ''
with:
issue-number: ${{ steps.find-pull-request.outputs.number }}
body: |
<!-- release notes preview comment -->
## Release notes preview
**_No_ new release will be created.**
If you are expecting a release, you will need to either fix a bug or add a feature.
Chores, CI, docs, refactoring, style and other changes will not trigger a release.
# Ensure that a breaking changes doc has been created
- name: Check for breaking changes comment
uses: peter-evans/find-comment@v2
id: fc-breaking-changes
if: steps.find-pull-request.outputs.number != ''
with:
issue-number: ${{ steps.find-pull-request.outputs.number }}
comment-author: "github-actions[bot]"
body-includes: "<!-- breaking changes comment -->"
- name: Delete previous breaking changes comment
if: steps.fc-breaking-changes.outputs.comment-id != ''
uses: jungwinter/comment@v1
with:
type: delete
comment_id: ${{ steps.fc-breaking-changes.outputs.comment-id }}
token: ${{ inputs.github-token }}
- name: "Check File Existence"
id: breaking-changes-file
uses: thebinaryfelix/[email protected]
with:
files: "docs/breaking-changes/v${{ steps.release-notes-preview.outputs.new-release-major-version }}.md"
- name: Comment missing breaking changes doc
uses: peter-evans/create-or-update-comment@v1
if: >
steps.release-notes-preview.outputs.new-release-published
&& inputs.enforce-breaking-changes-docs
&& steps.release-notes-preview.outputs.new-release-type == 'major'
&& !steps.breaking-changes-file.outputs.exists
with:
issue-number: ${{ steps.find-pull-request.outputs.number }}
body: |
steps.release-notes-preview.outputs.new-release-published = ${{ steps.release-notes-preview.outputs.new-release-published }}
&& inputs.enforce-breaking-changes-docs = ${{ inputs.enforce-breaking-changes-docs }}
&& steps.release-notes-preview.outputs.new-release-major-version '${{ steps.release-notes-preview.outputs.new-release-major-version }}' != steps.release-notes-preview.outputs.last-release-major-version '${{ steps.release-notes-preview.outputs.last-release-major-version }}'
&& ${{ hashFiles(format('docs/breaking-changes/v{0}.md', steps.release-notes-preview.outputs.new-release-major-version)) == '' }} '${{format('docs/breaking-changes/v{0}.md', steps.release-notes-preview.outputs.new-release-major-version)}}'
check: steps.release-notes-preview.outputs.new-release-type '${{ steps.release-notes-preview.outputs.new-release-type }}' != 'major' == ${{ steps.release-notes-preview.outputs.new-release-type != 'major' }}
check: steps.release-notes-preview.outputs.new-release-major-version != steps.release-notes-preview.outputs.last-release-major-version == ${{ steps.release-notes-preview.outputs.new-release-major-version != steps.release-notes-preview.outputs.last-release-major-version }}
check: steps.release-notes-preview.outputs.new-release-major-version == steps.release-notes-preview.outputs.last-release-major-version == ${{ steps.release-notes-preview.outputs.new-release-major-version == steps.release-notes-preview.outputs.last-release-major-version }}
## Error: missing breaking changes documentation
This pull request contains breaking changes, but no documentation has been added to `docs/breaking-changes/v${{ steps.release-notes-preview.outputs.new-release-major-version }}.md`.
<details>
<summary>Instructions for creating breaking changes document:</summary>
```shell
mkdir -p docs/breaking-changes
cat <<EOF > docs/breaking-changes/v${{ steps.release-notes-preview.outputs.new-release-major-version }}.md
# Breaking changes in v${{ steps.release-notes-preview.outputs.new-release-major-version }}
[//]: # "Brief description of current major version release scope"
## Description of changes
[//]: # "Elaborate and add context to help the developer understand the changes."
## Upgrade instructions
[//]: # "Required and suggested prerequisites, example code, etc."
EOF
```
</details>
---
<!-- breaking changes comment -->
- name: Fail if we are checking for the breaking changes doc and it is missing
if: >
steps.release-notes-preview.outputs.new-release-published
&& inputs.enforce-breaking-changes-docs
&& ${{ steps.release-notes-preview.outputs.new-release-type }} == 'major'
&& !steps.breaking-changes-file.outputs.exists
shell: bash
run: |
echo "::error::Breaking changes document is missing. Expected: ``docs/breaking-changes/v${{ steps.release-notes-preview.outputs.new-release-major-version }}.md``"
exit 1
78 changes: 0 additions & 78 deletions release-notes-preview/action.yaml

This file was deleted.

0 comments on commit 1076327

Please sign in to comment.