-
Notifications
You must be signed in to change notification settings - Fork 567
/
release.js
73 lines (61 loc) · 1.77 KB
/
release.js
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
61
62
63
64
65
66
67
68
69
70
71
72
73
'use strict'
// Called from .github/workflows
const generateReleaseNotes = async ({ github, owner, repo, versionTag, defaultBranch }) => {
const { data: releases } = await github.rest.repos.listReleases({
owner,
repo
})
const previousRelease = releases.find((r) => r.tag_name.startsWith('v6'))
const { data: { body } } = await github.rest.repos.generateReleaseNotes({
owner,
repo,
tag_name: versionTag,
target_commitish: defaultBranch,
previous_tag_name: previousRelease?.tag_name
})
const bodyWithoutReleasePr = body.split('\n')
.filter((line) => !line.includes('[Release] v'))
.join('\n')
return bodyWithoutReleasePr
}
const generatePr = async ({ github, context, defaultBranch, versionTag }) => {
const { owner, repo } = context.repo
const releaseNotes = await generateReleaseNotes({ github, owner, repo, versionTag, defaultBranch })
await github.rest.pulls.create({
owner,
repo,
head: `release/${versionTag}`,
base: defaultBranch,
title: `[Release] ${versionTag}`,
body: releaseNotes
})
}
const release = async ({ github, context, defaultBranch, versionTag }) => {
const { owner, repo } = context.repo
const releaseNotes = await generateReleaseNotes({ github, owner, repo, versionTag, defaultBranch })
await github.rest.repos.createRelease({
owner,
repo,
tag_name: versionTag,
target_commitish: defaultBranch,
name: versionTag,
body: releaseNotes,
draft: false,
prerelease: false,
generate_release_notes: false
})
try {
await github.rest.git.deleteRef({
owner,
repo,
ref: `heads/release/${versionTag}`
})
} catch (err) {
console.log("Couldn't delete release PR ref")
console.log(err)
}
}
module.exports = {
generatePr,
release
}