-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.js
190 lines (157 loc) · 3.88 KB
/
main.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
import {
error,
getInput,
group,
info,
notice,
setFailed,
warning,
} from "@actions/core";
import { context, getOctokit } from "@actions/github";
import { setOutput } from "./actions.js";
import { modifyReleaseAssets } from "./asset.js";
import { renderReleaseBody } from "./body.js";
import { readConfig } from "./config/reading.js";
import {
determineRef,
determineTagType,
fetchTagAnnotation,
readTagAnnotation,
} from "./git.js";
import {
createDiscussionReactions,
createReleaseReactions,
} from "./reaction.js";
import { parseRef } from "./ref.js";
import { createOrUpdateRelease } from "./release.js";
try {
await main();
} catch (e) {
setFailed(e.stack);
}
async function main() {
const config = await readConfig({ getInput, group, info });
const { env } = process;
const {
repo: { owner, repo },
} = context;
const ref = await determineRef({ group, info });
const { isTag, isSemVer, isStable, tag } = parseRef(ref);
if (!isTag) {
setFailed("Cannot create a release from a non-tag");
return;
}
info(`Detected tag ${JSON.stringify(tag)}`);
setOutput("tagIsSemVer", isSemVer ? "true" : "");
setOutput("tagIsStable", isStable ? "true" : "");
setOutput("tagName", tag);
if (!(await fetchTagAnnotation({ group, tag }))) {
setFailed("Unable to fetch the tag annotation");
return;
}
const [isTagTypeSuccess, tagType] = await determineTagType({ group, tag });
if (!isTagTypeSuccess) {
setFailed("Unable to determine the tag type");
return;
}
if (tagType !== "tag") {
setFailed("Unable to create a release from a lightweight tag");
return;
}
const tagSemVerLabel = isSemVer ? "SemVer" : "Non-Semver";
const tagStabilityLabel = isStable ? "stable release" : "pre-release";
if (typeof config.prerelease === "boolean") {
info(
`Release has been explicitly configured to be a ${
config.prerelease ? "pre-release" : "stable release"
}`
);
if (isStable === config.prerelease) {
info(
`Normally, ${tagSemVerLabel} tag would have been treated as a ${tagStabilityLabel}`
);
}
} else {
info(`${tagSemVerLabel} tag will be treated as a ${tagStabilityLabel}`);
}
const [isTagAnnotationReadSuccess, tagSubject, tagBody] =
await readTagAnnotation({ group, tag });
if (!isTagAnnotationReadSuccess) {
setFailed("Unable to read the tag annotation");
return;
}
setOutput("tagBody", tagBody);
setOutput("tagSubject", tagSubject);
const {
graphql,
request,
rest: { markdown, reactions, repos },
} = getOctokit(getInput("token"));
const releaseBody = await renderReleaseBody({
config,
env,
group,
info,
markdown,
owner,
repo,
repos,
setOutput,
tag,
tagBody,
});
setOutput("releaseBody", releaseBody);
const [release, wasCreated] = await createOrUpdateRelease({
config,
group,
info,
isStable,
owner,
releaseBody,
repo,
repos,
tag,
tagSubject,
});
setOutput("releaseId", release.id);
setOutput("releaseName", release.name);
setOutput("releaseUploadUrl", release.upload_url);
setOutput("releaseUrl", release.html_url);
setOutput("releaseWasCreated", wasCreated ? "true" : "");
notice(`${wasCreated ? "Created" : "Updated"} ${release.html_url}`, {
title: `Released - ${tagSubject}`,
});
const [assetResult, assets] = await modifyReleaseAssets({
config,
error,
group,
info,
owner,
release,
repo,
repos,
request,
warning,
});
if (!assetResult) setFailed("Unable to modify release assets");
setOutput("assets", JSON.stringify(assets));
await createReleaseReactions({
config,
group,
info,
owner,
reactions,
release,
repo,
});
await createDiscussionReactions({
config,
graphql,
group,
info,
owner,
release,
repo,
setOutput,
});
}