[actions] Add GitHub action to compute the changelog for maestro bumps. (#14984)

And add that changelog as a comment to the PR. If there already is a comment
with a changelog, then update that comment instead.
This commit is contained in:
Rolf Bjarne Kvinge 2022-05-11 21:41:12 +02:00 коммит произвёл GitHub
Родитель cec44107a5
Коммит b56184b60d
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 59 добавлений и 0 удалений

59
.github/workflows/maestro-changelog.yml поставляемый Normal file
Просмотреть файл

@ -0,0 +1,59 @@
name: Add changelog for Maestro bump
on: pull_request
jobs:
add-changelog:
name: Add changelog
runs-on: ubuntu-latest
if: github.actor == 'dotnet-maestro[bot]'
steps:
- name: 'Compute changelog'
run: |
set -exo pipefail
git clone https://github.com/spouliot/dotnet-tools
cd dotnet-tools/changelog
dotnet run https://github.com/$GITHUB_REPOSITORY/pull/${GITHUB_REF_NAME/\/*/} > changelog.txt 2>&1
# need to replace newlines with actual "\n"
rm -f changelog2.txt
echo "CHANGELOG_MESSAGE<<EOF" >> changelog2.txt
cat changelog.txt | sed -e ':a' -e 'N' -e '$!ba' -e 's/\n/\\n/g' >> changelog2.txt
echo EOF >> changelog2.txt
cat changelog2.txt
# export the changelog message
cat changelog2.txt >> $GITHUB_ENV
- name: 'Add changelog'
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
// check if we've already added a changelog to this PR, and if so, update that comment, otherwise add a new comment
var commentId = ""
await github.paginate (github.rest.issues.listComments,
{
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number
}).then ((comments) =>
{
const changelogComment = comments.find(comment => comment.body.includes (".net ChangeLog for") && comment.user.login == 'github-actions[bot]')
commentId = changelogComment.id
})
if (commentId == "") {
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: '${{ env.CHANGELOG_MESSAGE }}'
})
} else {
github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: commentId,
body: '${{ env.CHANGELOG_MESSAGE }}'
})
}