generated from actions/typescript-action
/
Inputs.ts
240 lines (200 loc) · 6.49 KB
/
Inputs.ts
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
import * as core from '@actions/core';
import {Context} from "@actions/github/lib/context";
import {readFileSync} from 'fs';
import {ArtifactGlobber} from './ArtifactGlobber';
import {Artifact} from './Artifact';
export interface Inputs {
readonly allowUpdates: boolean
readonly artifactErrorsFailBuild: boolean
readonly artifacts: Artifact[]
readonly commit?: string
readonly createdDraft: boolean
readonly createdPrerelease: boolean
readonly createdReleaseBody?: string
readonly createdReleaseName?: string
readonly discussionCategory?: string
readonly generateReleaseNotes: boolean
readonly makeLatest?: string
readonly owner: string
readonly removeArtifacts: boolean
readonly replacesArtifacts: boolean
readonly repo: string
readonly skipIfReleaseExists: boolean
readonly tag: string
readonly token: string
readonly updatedDraft?: boolean
readonly updatedReleaseBody?: string
readonly updatedReleaseName?: string
readonly updatedPrerelease?: boolean
readonly updateOnlyUnreleased: boolean
}
export class CoreInputs implements Inputs {
private artifactGlobber: ArtifactGlobber
private context: Context
constructor(artifactGlobber: ArtifactGlobber, context: Context) {
this.artifactGlobber = artifactGlobber
this.context = context
}
get allowUpdates(): boolean {
const allow = core.getInput('allowUpdates')
return allow == 'true'
}
get artifacts(): Artifact[] {
let artifacts = core.getInput('artifacts')
if (!artifacts) {
artifacts = core.getInput('artifact')
}
if (artifacts) {
let contentType = core.getInput('artifactContentType')
if (!contentType) {
contentType = 'raw'
}
return this.artifactGlobber
.globArtifactString(artifacts, contentType, this.artifactErrorsFailBuild)
}
return []
}
get artifactErrorsFailBuild(): boolean {
const allow = core.getInput('artifactErrorsFailBuild')
return allow == 'true'
}
private get body(): string | undefined {
const body = core.getInput('body')
if (body) {
return body
}
const bodyFile = core.getInput('bodyFile')
if (bodyFile) {
return this.stringFromFile(bodyFile)
}
return ''
}
get createdDraft(): boolean {
const draft = core.getInput('draft')
return draft == 'true'
}
get createdPrerelease(): boolean {
const preRelease = core.getInput('prerelease')
return preRelease == 'true'
}
get createdReleaseBody(): string | undefined {
if (CoreInputs.omitBody) return undefined
return this.body
}
private static get omitBody(): boolean {
return core.getInput('omitBody') == 'true'
}
get createdReleaseName(): string | undefined {
if (CoreInputs.omitName) return undefined
return this.name
}
private static get omitName(): boolean {
return core.getInput('omitName') == 'true'
}
get commit(): string | undefined {
const commit = core.getInput('commit')
if (commit) {
return commit
}
return undefined
}
get discussionCategory(): string | undefined {
const category = core.getInput('discussionCategory')
if (category) {
return category
}
return undefined
}
private get name(): string | undefined {
const name = core.getInput('name')
if (name) {
return name
}
return this.tag
}
get generateReleaseNotes(): boolean {
const generate = core.getInput('generateReleaseNotes')
return generate == 'true'
}
get makeLatest(): string | undefined {
const makeLatest = core.getInput('makeLatest')
if (makeLatest) {
return makeLatest
}
return undefined
}
get owner(): string {
let owner = core.getInput('owner')
if (owner) {
return owner
}
return this.context.repo.owner
}
get removeArtifacts(): boolean {
const removes = core.getInput('removeArtifacts')
return removes == 'true'
}
get replacesArtifacts(): boolean {
const replaces = core.getInput('replacesArtifacts')
return replaces == 'true'
}
get repo(): string {
let repo = core.getInput('repo')
if (repo) {
return repo
}
return this.context.repo.repo
}
get skipIfReleaseExists(): boolean {
return core.getBooleanInput("skipIfReleaseExists")
}
get tag(): string {
const tag = core.getInput('tag')
if (tag) {
return tag;
}
const ref = this.context.ref
const tagPath = "refs/tags/"
if (ref && ref.startsWith(tagPath)) {
return ref.substr(tagPath.length, ref.length)
}
throw Error("No tag found in ref or input!")
}
get token(): string {
return core.getInput('token', {required: true})
}
get updatedDraft(): boolean | undefined {
if (CoreInputs.omitDraftDuringUpdate) return undefined
return this.createdDraft
}
private static get omitDraftDuringUpdate(): boolean {
return core.getInput('omitDraftDuringUpdate') == 'true'
}
get updatedPrerelease(): boolean | undefined {
if (CoreInputs.omitPrereleaseDuringUpdate) return undefined
return this.createdPrerelease
}
private static get omitPrereleaseDuringUpdate(): boolean {
return core.getInput('omitPrereleaseDuringUpdate') == 'true'
}
get updatedReleaseBody(): string | undefined {
if (CoreInputs.omitBody || CoreInputs.omitBodyDuringUpdate) return undefined
return this.body
}
private static get omitBodyDuringUpdate(): boolean {
return core.getInput('omitBodyDuringUpdate') == 'true'
}
get updatedReleaseName(): string | undefined {
if (CoreInputs.omitName || CoreInputs.omitNameDuringUpdate) return undefined
return this.name
}
get updateOnlyUnreleased(): boolean {
return core.getInput('updateOnlyUnreleased') == 'true'
}
private static get omitNameDuringUpdate(): boolean {
return core.getInput('omitNameDuringUpdate') == 'true'
}
stringFromFile(path: string): string {
return readFileSync(path, 'utf-8')
}
}