Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#211: Release notes entry enforcement #212

Merged
merged 32 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
e77987e
#211: Release notes entry enforcement
benedeki Jun 13, 2024
0b2b7d1
Merge branch 'master' into feature/211-release-notes-entry-enforcement
lsulak Jun 13, 2024
6e0afae
* added on-issue-comment trigger
benedeki Jun 14, 2024
6688ff6
* testing
benedeki Jun 14, 2024
ac2ed7a
* experimenting with on-issue-comment
benedeki Jun 14, 2024
8935beb
* further experimenting
benedeki Jun 14, 2024
1ade8a4
* test X
benedeki Jun 14, 2024
19a773c
* test XI
benedeki Jun 14, 2024
e1b0775
* test XII
benedeki Jun 14, 2024
f92d564
* test XII
benedeki Jun 14, 2024
7b83c24
* Test XIII
benedeki Jun 14, 2024
ac0738e
Update .github/workflows/release_draft.yml
benedeki Jun 14, 2024
829b97c
Merge branch 'master' into feature/211-release-notes-entry-enforcement
benedeki Jun 14, 2024
8b3e36d
* Experiment XIV
benedeki Jun 17, 2024
d65f890
Merge branch 'feature/211-release-notes-entry-enforcement' of https:/…
benedeki Jun 17, 2024
f2a700c
* Experiment XV
benedeki Jun 17, 2024
615359a
* Experiment XVI
benedeki Jun 17, 2024
58b8b56
* added test filenames check action
benedeki Jun 18, 2024
bdaec35
Merge branch 'master' into feature/211-release-notes-entry-enforcement
benedeki Jun 18, 2024
b7ca0b7
* fixes
benedeki Jun 19, 2024
d41d26c
Merge branch 'feature/211-release-notes-entry-enforcement' of https:/…
benedeki Jun 19, 2024
50be6b2
Apply suggestions from code review
benedeki Jun 20, 2024
d40d31e
* removed demo code
benedeki Jun 20, 2024
157deaa
* Fixes
benedeki Jun 20, 2024
ea02daa
* Fixed filename patterns
benedeki Jun 20, 2024
d00bd4d
* added excludes
benedeki Jun 20, 2024
ab081b5
* better alignment
benedeki Jun 21, 2024
4893740
* Typo fix
benedeki Jun 23, 2024
b921521
* still wrong
benedeki Jun 23, 2024
7592de1
* multi-line needs different style
benedeki Jun 23, 2024
883cf28
* last try
benedeki Jun 23, 2024
3f632f8
* back to one line excludes
benedeki Jun 23, 2024
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
94 changes: 94 additions & 0 deletions .github/workflows/pr_release_note_comment_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#
# 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 }}
1 change: 1 addition & 0 deletions .github/workflows/release_draft.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ jobs:
{"title": "Bugfixes 🛠", "label": "bug"}
]
warnings: true
skip-release-notes: "no RN"
- name: Create draft release
uses: softprops/action-gh-release@v1
env:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#
# 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: Release Notes Comments Copy from PR to Linked Issues
lsulak marked this conversation as resolved.
Show resolved Hide resolved

on:
pull_request:
types: [closed]
branches: [ master ]

jobs:
copy_release_notes:
if: github.event.pull_request.merged == true
name: Copy Release Notes
runs-on: ubuntu-latest
steps:
- name: Fetch PR Comments
id: get-comments
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const prNumber = context.payload.pull_request.number;
const repoName = context.repo.repo;
const repoOwner = context.repo.owner;
const releaseNotesRegex = /release notes?:?/i;

const comments = await github.rest.issues.listComments({
owner: repoOwner,
repo: repoName,
issue_number: prNumber,
});

const releaseNoteComment = comments.data.find(comment => releaseNotesRegex.test(comment.body));
const releaseNoteBody = releaseNoteComment ? releaseNoteComment.body : '';
console.log(`Release Note Body: ${releaseNoteBody}`);
core.setOutput('releaseNoteBody', releaseNoteBody);

- name: Print Extracted releaseNoteBody
run: |
echo "Extracted Release Note Body:"
echo "${{ steps.get-comments.outputs.releaseNoteBody }}"
echo "RELEASE_NOTE_BODY<<EOF" >> $GITHUB_ENV
echo "${{ steps.get-comments.outputs.releaseNoteBody }}" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV

- name: Parse PR Description for Related Issues
id: find-issues
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const description = context.payload.pull_request.body;
const issueNumbers = [];
const regexPattern = /([Cc]los(e|es|ed)|[Ff]ix(es|ed)?|[Rr]esolv(e|es|ed))\s*#\s*([0-9]+)/g;

let match;
while ((match = regexPattern.exec(description)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (match.index === regexPattern.lastIndex) {
regexPattern.lastIndex++;
}

// The actual issue number is in the last group of the match
const issueNumber = match[match.length - 1];
if (issueNumber) {
issueNumbers.push(issueNumber);
}
}

core.setOutput('issueNumbers', issueNumbers.join(', '));

- name: Print Extracted Issue Numbers
run: |
echo "Extracted Issue Numbers: ${{ steps.find-issues.outputs.issueNumbers }}"
echo "ISSUE_NUMBERS=${{ steps.find-issues.outputs.issueNumbers }}" >> $GITHUB_ENV

- name: Post Comment to Issues
if: ${{ (steps.get-comments.outputs.releaseNoteBody) && (steps.find-issues.outputs.issueNumbers) }}
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const issueNumbers = process.env.ISSUE_NUMBERS;
const commentBody = process.env.RELEASE_NOTE_BODY;
const repoName = context.repo.repo;
const repoOwner = context.repo.owner;

for (const issueNumber of issueNumbers.split(', ')) {
if (issueNumber && commentBody) {
await github.rest.issues.createComment({
owner: repoOwner,
repo: repoName,
issue_number: issueNumber,
body: commentBody
});
}
}
41 changes: 41 additions & 0 deletions .github/workflows/test_filenames_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#
# 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: Test Filenames Check

on:
pull_request:
branches: [ master ]
types: [ opened, synchronize, reopened ]

jobs:
test_filenames_check:
name: Test Filenames Check
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Filename Inspector
id: scan-test-files
uses: AbsaOSS/filename-inspector@master
with:
name-patterns: '*UnitTests.*,*IntegrationTests.*'
paths: '**/src/test/scala/**'
report-format: 'console'
excludes: 'server/src/test/scala/za/co/absa/atum/server/api/TestData.scala,server/src/test/scala/za/co/absa/atum/server/api/TestTransactorProvider.scala,server/src/test/scala/za/co/absa/atum/server/ConfigProviderTest.scala'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possiblE to add multi-line exclusions instead of 1 line? Also, is it possible to regexp it? Or at least use wildcard(s)?

Copy link
Collaborator

@miroslavpojer miroslavpojer Jun 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For multi-line exclusion, see and use filename-inspector branch feature/fix-to-use-correct-syntax in your yaml.

  • See updated README.md for an example.

Regex

  • paths support glob patterns (supports **)
  • name-patterns and excludes support fnmatch pattern (do not support **)

Feel free to help with PR review on named branch and its PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think wildcards are possible. RegExpt no, at least not yet now (it hasn't been released yet even).
I actually thought to move the classes into own directories, to make the exclusions simpler. But in its own PR.

Copy link
Collaborator

@miroslavpojer miroslavpojer Jun 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add wildcards, here is my testing example:

- name: Test filename-inspector check
  id: test-file-suffix
  uses: AbsaOSS/filename-inspector@feature/fix-to-use-correct-syntax
  with:
    name-patterns: |
      *GUI*,
      *Unit*
    paths: |
      **/src/test/java/**,
      **/src/test/scala/**
    excludes: |
      *1UnitTest.*,
      *thServiceTest.*
    report-format: 'csv'
    verbose-logging: 'true'
    fail-on-violation: 'true'

See link.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The multiline example doesn't seem to work. 😠 Reverting to single line, that worked.
(Tried all kind of formats)

verbose-logging: 'false'
fail-on-violation: 'true'
Loading