generated from actions/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 188
/
Inputs.ts
199 lines (167 loc) · 5.34 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
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 createdReleaseBody?: string
readonly createdReleaseName?: string
readonly discussionCategory?: string
readonly draft: boolean
readonly owner: string
readonly createdPrerelease: boolean
readonly removeArtifacts: boolean
readonly replacesArtifacts: boolean
readonly repo: string
readonly tag: string
readonly token: string
readonly updatedReleaseBody?: string
readonly updatedReleaseName?: string
readonly updatedPrerelease?: 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'
}
get createdReleaseBody(): string | undefined {
if (CoreInputs.omitBody) return undefined
return this.body
}
private static get omitBody(): boolean {
return core.getInput('omitBody') == '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 commit(): string {
return core.getInput('commit')
}
get createdReleaseName(): string | undefined {
if (CoreInputs.omitName) return undefined
return this.name
}
get discussionCategory(): string | undefined {
const category = core.getInput('discussionCategory')
if (category) {
return category
}
return undefined
}
private static get omitName(): boolean {
return core.getInput('omitName') == 'true'
}
private get name(): string | undefined {
const name = core.getInput('name')
if (name) {
return name
}
return this.tag
}
get draft(): boolean {
const draft = core.getInput('draft')
return draft == 'true'
}
get owner(): string {
let owner = core.getInput('owner')
if (owner) {
return owner
}
return this.context.repo.owner
}
get createdPrerelease(): boolean {
const preRelease = core.getInput('prerelease')
return preRelease == 'true'
}
private static get omitPrereleaseDuringUpdate(): boolean {
return core.getInput('omitPrereleaseDuringUpdate') == 'true'
}
get updatedPrerelease(): boolean | undefined {
if (CoreInputs.omitPrereleaseDuringUpdate) return undefined
return this.createdPrerelease
}
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 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 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
}
private static get omitNameDuringUpdate(): boolean {
return core.getInput('omitNameDuringUpdate') == 'true'
}
stringFromFile(path: string): string {
return readFileSync(path, 'utf-8')
}
}