Release notes workflow WIP #11
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
name: Check release notes | |
on: | |
pull_request: | |
types: [opened, synchronize, reopened] | |
branches: | |
- 'main' | |
- 'release/*' | |
permissions: | |
contents: write | |
pull-requests: write | |
jobs: | |
check_release_notes: | |
#if: github.event.issue.pull_request != '' | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Get github ref | |
uses: actions/github-script@v3 | |
id: get-pr | |
with: | |
script: | | |
const result = await github.pulls.get({ | |
pull_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
}); | |
return { "pr_number": context.issue.number, "ref": result.data.head.ref, "repository": result.data.head.repo.full_name}; | |
- name: Checkout repo | |
uses: actions/checkout@v2 | |
with: | |
repository: ${{ fromJson(steps.get-pr.outputs.result).repository }} | |
ref: ${{ fromJson(steps.get-pr.outputs.result).ref }} | |
fetch-depth: 0 | |
- name: Check for release notes changes | |
id: release_notes_changes | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
# Check all changed paths | |
REPOSITORY=${{ fromJson(steps.get-pr.outputs.result).repository }} | |
PR_NUMBER=${{ fromJson(steps.get-pr.outputs.result).pr_number }} | |
RELEASE_NOTES_MESSAGE="" | |
_files=`gh pr view ${PR_NUMBER} --json files --jq '.files.[].path'` | |
RELEASE_NOTES_MESSAGE+=$'## Modified files\n' | |
RELEASE_NOTES_MESSAGE+=$'\\`\\`\\`\n' | |
RELEASE_NOTES_MESSAGE+=$'${_files}\n' | |
RELEASE_NOTES_MESSAGE+=$'\\`\\`\\`\n' | |
echo "release-notes-check-message=${RELEASE_NOTES_MESSAGE}" >> $GITHUB_OUTPUT | |
# Did bot already commented the PR? | |
- name: Find Comment | |
uses: peter-evans/find-comment@v2.4.0 | |
id: fc | |
with: | |
issue-number: ${{ github.event.pull_request.number }} | |
comment-author: 'github-actions[bot]' | |
body-includes: '<!-- DO_NOT_REMOVE: release_notes_check -->' | |
# If not, create a new comment | |
- name: Create comment | |
if: steps.fc.outputs.comment-id == '' | |
uses: peter-evans/create-or-update-comment@v3.1.0 | |
with: | |
issue-number: ${{ github.event.pull_request.number }} | |
body: | | |
<!-- DO_NOT_REMOVE: release_notes_check --> | |
${{steps.release_notes_changes.outputs.release-notes-check-message}} | |
#reactions: rocket | |
# If yes, update the comment | |
- name: Update comment | |
if: steps.fc.outputs.comment-id != '' | |
uses: peter-evans/create-or-update-comment@v3.1.0 | |
with: | |
comment-id: ${{ steps.fc.outputs.comment-id }} | |
edit-mode: replace | |
body: | | |
<!-- DO_NOT_REMOVE: release_notes_check --> | |
${{steps.release_notes_changes.outputs.release-notes-check-message}} | |
#reactions: hooray |