Release notes workflow WIP #28
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: | | |
set -e | |
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) | |
_release_notes_base_path='docs/release-notes' | |
_fsharp_core_release_notes_path="${_release_notes_base_path}/FSharp.Core/VERSION_PLACEHOLDER.md" | |
_fsharp_compiler_release_notes_path="${_release_notes_base_path}/FSharp.Compiler.Service/VERSION_PLACEHOLDER.md" | |
_fsharp_language_release_notes_path="${_release_notes_base_path}/Language/preview.md" | |
readonly paths=( | |
"src/FSharp.Core|${_fsharp_core_release_notes_path}" | |
"src/Compiler|${_fsharp_compiler_release_notes_path}" | |
"src/Compiler/Facilities/LanguageFeatures.fsi|${_fsharp_language_release_notes_path}" | |
"global.json|FAKE_PATH_FOR_TESTING.md" | |
".github|FAKE2_PATH2_FOR2_TESTING2.md" | |
) | |
# Check all changed paths | |
RELEASE_NOTES_MESSAGE="" | |
RELEASE_NOTES_MESSAGE_DETAILS="" | |
RELEASE_NOTES_FOUND="" | |
RELEASE_NOTES_NOT_FOUND="" | |
_modified_paths=`gh pr view ${PR_NUMBER} --json files --jq '.files.[].path'` | |
for fields in ${paths[@]} | |
do | |
IFS=$'|' read -r path release_notes <<< "$fields" | |
echo "Checking for changed files in: $path" | |
# Check if path is in modified files: | |
if [[ "${_modified_paths[@]}" =~ "${path}" ]]; then | |
echo "Found $path in modified files" | |
echo "Checking if release notes modified in: $release_notes" | |
if [[ "${_modified_paths[@]}" =~ "${release_notes}" ]]; then | |
echo "Found $release_notes in modified files" | |
RELEASE_NOTES_FOUND+="| \`$path\` | \`$release_notes\` |" | |
RELEASE_NOTES_FOUND+=$'\n' | |
else | |
echo "Did not find $release_notes in modified files" | |
RELEASE_NOTES_NOT_FOUND+="| \`$path\` | \`$release_notes\` |" | |
RELEASE_NOTES_NOT_FOUND+=$'\n' | |
fi | |
else | |
echo "Nothing found, no release notes required" | |
fi | |
done | |
if [[ $RELEASE_NOTES_FOUND != "" ]]; then | |
RELEASE_NOTES_MESSAGE_DETAILS+=$"Found changes and release notes in following paths:" | |
RELEASE_NOTES_MESSAGE_DETAILS+=$'\n' | |
RELEASE_NOTES_MESSAGE_DETAILS+='| Change path | Release notes path |' | |
RELEASE_NOTES_MESSAGE_DETAILS+=$'\n' | |
RELEASE_NOTES_MESSAGE_DETAILS+='| ---------------- | ------------------ |' | |
RELEASE_NOTES_MESSAGE_DETAILS+=$'\n' | |
RELEASE_NOTES_MESSAGE_DETAILS+="${RELEASE_NOTES_FOUND}" | |
RELEASE_NOTES_MESSAGE_DETAILS+=$'\n' | |
fi | |
if [[ $RELEASE_NOTES_NOT_FOUND != "" ]]; then | |
RELEASE_NOTES_MESSAGE_DETAILS+=$"Found changes and release notes in following paths:" | |
RELEASE_NOTES_MESSAGE_DETAILS+=$'\n' | |
RELEASE_NOTES_MESSAGE_DETAILS+='| Change path | Release notes path |' | |
RELEASE_NOTES_MESSAGE_DETAILS+=$'\n' | |
RELEASE_NOTES_MESSAGE_DETAILS+='| ---------------- | ------------------ |' | |
RELEASE_NOTES_MESSAGE_DETAILS+=$'\n' | |
RELEASE_NOTES_MESSAGE_DETAILS+="${RELEASE_NOTES_NOT_FOUND}" | |
RELEASE_NOTES_MESSAGE_DETAILS+=$'\n' | |
fi | |
RELEASE_NOTES_MESSAGE+=$'## Release notes check:\n\n' | |
RELEASE_NOTES_MESSAGE+=$'## Release notes check\n\n' | |
if [[ $RELEASE_NOTES_MESSAGE_DETAILS == "" ]]; then | |
RELEASE_NOTES_MESSAGE+=$'### No release notes required.' | |
else | |
RELEASE_NOTES_MESSAGE+=$'### Release notes required.\n\n' | |
RELEASE_NOTES_MESSAGE+=$RELEASE_NOTES_MESSAGE_DETAILS | |
fi | |
echo "release-notes-check-message<<$EOF" >>$GITHUB_OUTPUT | |
echo "${RELEASE_NOTES_MESSAGE}" >>$GITHUB_OUTPUT | |
echo "$EOF" >>$GITHUB_OUTPUT | |
# Did bot already commented the PR? | |
- name: Find Comment | |
uses: peter-evans/[email protected] | |
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/[email protected] | |
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/[email protected] | |
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 |