-
Notifications
You must be signed in to change notification settings - Fork 5
60 lines (51 loc) · 1.83 KB
/
user-release-notes.yml
File metadata and controls
60 lines (51 loc) · 1.83 KB
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
60
name: Create User Release Notes Asset
on:
workflow_run:
workflows: [Create Release with Changelog]
types:
- completed
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Extract User Release Notes and Upload Asset
uses: actions/github-script@v8
with:
script: |
const REPO_OWNER = "diamondlightsource";
const REPO_NAME = "httomo";
const FILENAME = "user-release-notes.txt";
const USER_RELEASE_NOTES_HEADER = "Notable Changes for Users";
function extractUserReleaseNotes(text) {
if (!text.includes(USER_RELEASE_NOTES_HEADER)) {
return [];
}
const lines = text.split("\n");
const idx = lines.findIndex((element) => element === `### ${USER_RELEASE_NOTES_HEADER}`);
let notes = [];
for (const line of lines.slice(idx + 1)) {
if (line.slice(0, 2) === "* ") {
const prTitle = line.split(" by")[0];
notes.push(prTitle);
continue;
}
break;
}
return notes;
};
const release = await github.rest.repos.getReleaseByTag({
owner: REPO_OWNER,
repo: REPO_NAME,
tag: context.payload.workflow_run.head_branch
});
const lines = extractUserReleaseNotes(release.data.body);
if (lines.length > 0) {
const encoder = new TextEncoder();
await github.rest.repos.uploadReleaseAsset({
owner: REPO_OWNER,
repo: REPO_NAME,
release_id: release.data.id,
name: FILENAME,
data: encoder.encode(lines.join("\n")),
});
}