-
Notifications
You must be signed in to change notification settings - Fork 514
59 lines (56 loc) · 2.18 KB
/
maestro-changelog.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
name: Add changelog for Maestro bump
on: pull_request
jobs:
add-changelog:
name: Add changelog
runs-on: ubuntu-latest
# GITHUB_TOKEN change from read-write to read-only on 2024-02-01 requires permissions block
# https://docs.opensource.microsoft.com/github/apps/permission-changes/
# https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs
permissions:
issues: write
pull-requests: write
contents: read
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/\/*/} > /tmp/changelog.txt 2>&1
- name: 'Add changelog'
uses: actions/github-script@v7.0.1
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const fs = require('fs');
const changelog_message = fs.readFileSync('/tmp/changelog.txt', 'utf8');
// 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]')
if (changelogComment)
commentId = changelogComment.id
})
if (commentId == "") {
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: changelog_message
})
} else {
github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: commentId,
body: changelog_message
})
}