From 8eb48688cd7e6715253d547f3ee79d4092b4aa5d Mon Sep 17 00:00:00 2001 From: Adam Bovill Date: Wed, 13 Sep 2023 22:08:03 +0000 Subject: [PATCH] fix(release-notes-preview): add breaking changes doc check This adds a new check that enforces that a breaking changes document has been created. --- release-notes-preview/action.yaml | 77 +++++++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 4 deletions(-) diff --git a/release-notes-preview/action.yaml b/release-notes-preview/action.yaml index d80b929..6dda702 100644 --- a/release-notes-preview/action.yaml +++ b/release-notes-preview/action.yaml @@ -5,6 +5,10 @@ inputs: 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.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. @@ -29,7 +33,7 @@ runs: state: open - name: Generate release notes id: release-notes-preview - uses: open-turo/actions-release/semantic-release@v2 + uses: open-turo/actions-release/semantic-release@add-prerelease-support env: GITHUB_TOKEN: ${{ inputs.github-token }} with: @@ -37,20 +41,22 @@ runs: 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 + 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: "" - name: Delete previous release note - if: steps.fc.outputs.comment-id != '' + if: steps.fc-release-notes.outputs.comment-id != '' uses: jungwinter/comment@v1 with: type: delete - comment_id: ${{ steps.fc.outputs.comment-id }} + 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 @@ -76,3 +82,66 @@ runs: 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: "" + - 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-release-notes.outputs.comment-id }} + token: ${{ inputs.github-token }} + - 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-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)) == '' }} + with: + issue-number: ${{ steps.find-pull-request.outputs.number }} + body: | + ## 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`. + +
+ create doc + ```shell + mkdir -p docs/breaking-changes + cat < 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 + ``` +
+ + --- + + - 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-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)) == '' }} + 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