#211: Release notes entry enforcement #29
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Copyright 2021 ABSA Group Limited | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, | |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
# See the License for the specific language governing permissions and | |
# limitations under the License. | |
# | |
name: PR Release Note Comment Check | |
on: | |
issue_comment: | |
types: | |
- created | |
- edited | |
- deleted | |
pull_request: | |
types: | |
- opened | |
- synchronize | |
- reopened | |
- edited | |
- labeled | |
- unlabeled | |
branches: [ master ] | |
jobs: | |
check-for-release-notes-comments: | |
if: ${{ ( github.event_name == 'pull_request') || (github.event.issue.pull_request) }} | |
name: Check For Release Notes Comments | |
runs-on: ubuntu-latest | |
steps: | |
- name: Get PR branch | |
uses: xt0rted/pull-request-comment-branch@v1 | |
id: comment-branch | |
- name: Set latest commit status as pending | |
uses: myrotvorets/set-commit-status-action@master | |
with: | |
sha: ${{ steps.comment-branch.outputs.head_sha }} | |
token: ${{ secrets.GITHUB_TOKEN }} | |
status: pending | |
- name: Fetch all PR comments | |
if: ${{ ! contains( github.event.pull_request.labels.*.name, 'no RN') }} | |
id: get-comments | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{secrets.GITHUB_TOKEN}} | |
script: | | |
const issueNumber = context.issue.number; | |
const repoName = context.repo.repo; | |
const repoOwner = context.repo.owner; | |
const comments = await github.rest.issues.listComments({ | |
owner: repoOwner, | |
repo: repoName, | |
issue_number: issueNumber, | |
}); | |
return comments.data.map(comment => comment.body); | |
- name: Check for 'Release Notes' in comments | |
if: ${{ ! contains( github.event.pull_request.labels.*.name, 'no RN') }} | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const comments = ${{ steps.get-comments.outputs.result }}; | |
console.log("Comments:"); | |
console.log(comments); | |
const releaseNotesRegex = /release notes?:?/i; | |
const hasReleaseNotes = comments.some(comment => releaseNotesRegex.test(comment)); | |
if (!hasReleaseNotes) { | |
console.log('No "Release notes" found in PR comments'); | |
core.setFailed('No "Release notes" found in PR comments') | |
} else { | |
console.log('"Release notes" found in comments'); | |
} | |
- name: Set latest commit status as ${{ job.status }} | |
uses: myrotvorets/set-commit-status-action@master | |
if: always() | |
with: | |
sha: ${{ steps.comment-branch.outputs.head_sha }} | |
token: ${{ secrets.GITHUB_TOKEN }} | |
status: ${{ job.status }} |