@@ -31,11 +31,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
31
31
return ( mod && mod . __esModule ) ? mod : { "default" : mod } ;
32
32
} ;
33
33
Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
34
+ exports . run = exports . booleanInput = exports . optionalInput = exports . optionalArrayInput = void 0 ;
34
35
const axios_1 = __importDefault ( require ( "axios" ) ) ;
35
36
const mablApiClient_1 = require ( "./mablApiClient" ) ;
36
37
const table_1 = require ( "./table" ) ;
37
38
const core = __importStar ( require ( "@actions/core" ) ) ;
38
39
const github = __importStar ( require ( "@actions/github" ) ) ;
40
+ const constants_1 = require ( "./constants" ) ;
39
41
const DEFAULT_MABL_APP_URL = 'https://app.mabl.com' ;
40
42
const EXECUTION_POLL_INTERVAL_MILLIS = 10000 ;
41
43
const EXECUTION_COMPLETED_STATUSES = [
@@ -46,34 +48,56 @@ const EXECUTION_COMPLETED_STATUSES = [
46
48
'terminated' ,
47
49
] ;
48
50
const GITHUB_BASE_URL = 'https://api.github.com' ;
51
+ function optionalArrayInput ( name ) {
52
+ return core
53
+ . getInput ( name , {
54
+ required : false ,
55
+ } )
56
+ . split ( / [ , \n ] / )
57
+ . filter ( ( item ) => item . length )
58
+ . map ( ( item ) => item . trim ( ) ) ;
59
+ }
60
+ exports . optionalArrayInput = optionalArrayInput ;
61
+ function optionalInput ( name ) {
62
+ const rawValue = core . getInput ( name , {
63
+ required : false ,
64
+ } ) ;
65
+ if ( rawValue . length > 0 ) {
66
+ return rawValue ;
67
+ }
68
+ return ;
69
+ }
70
+ exports . optionalInput = optionalInput ;
71
+ function booleanInput ( name ) {
72
+ return ( core
73
+ . getInput ( name , {
74
+ required : false ,
75
+ } )
76
+ . toLowerCase ( ) === 'true' ) ;
77
+ }
78
+ exports . booleanInput = booleanInput ;
49
79
function run ( ) {
50
80
var _a , _b , _c ;
51
81
return __awaiter ( this , void 0 , void 0 , function * ( ) {
52
82
try {
53
83
core . startGroup ( 'Gathering inputs' ) ;
54
- const applicationId = core . getInput ( 'application-id' , {
55
- required : false ,
56
- } ) ;
57
- const environmentId = core . getInput ( 'environment-id' , {
58
- required : false ,
59
- } ) ;
60
- const apiKey = process . env . MABL_API_KEY || '' ;
84
+ const applicationId = optionalInput ( constants_1 . ActionInputs . ApplicationId ) ;
85
+ const environmentId = optionalInput ( constants_1 . ActionInputs . EnvironmentId ) ;
86
+ const apiKey = process . env . MABL_API_KEY ;
61
87
if ( ! apiKey ) {
62
- core . setFailed ( 'MABL_API_KEY required' ) ;
88
+ core . setFailed ( 'env var MABL_API_KEY required' ) ;
89
+ return ;
63
90
}
64
- const browserTypes = core . getInput ( 'browser-types' , {
65
- required : false ,
66
- } ) ;
67
- const uri = core . getInput ( 'uri' , { required : false } ) ;
68
- const rebaselineImages = parseBoolean ( core . getInput ( 'rebaseline-images' , {
69
- required : false ,
70
- } ) ) ;
71
- const setStaticBaseline = parseBoolean ( core . getInput ( 'set-static-baseline' , {
72
- required : false ,
73
- } ) ) ;
74
- const continueOnPlanFailure = parseBoolean ( core . getInput ( 'continue-on-failure' , { required : false } ) ) ;
91
+ const planLabels = optionalArrayInput ( constants_1 . ActionInputs . PlanLabels ) ;
92
+ const browserTypes = optionalArrayInput ( constants_1 . ActionInputs . BrowserTypes ) ;
93
+ const httpHeaders = optionalArrayInput ( constants_1 . ActionInputs . HttpHeaders ) ;
94
+ const uri = optionalInput ( constants_1 . ActionInputs . Uri ) ;
95
+ const mablBranch = optionalInput ( constants_1 . ActionInputs . MablBranch ) ;
96
+ const rebaselineImages = booleanInput ( constants_1 . ActionInputs . RebaselineImages ) ;
97
+ const setStaticBaseline = booleanInput ( constants_1 . ActionInputs . SetStaticBaseline ) ;
98
+ const continueOnPlanFailure = booleanInput ( constants_1 . ActionInputs . ContinueOnFailure ) ;
75
99
const pullRequest = yield getRelatedPullRequest ( ) ;
76
- const eventTimeString = core . getInput ( 'event-time' , { required : false } ) ;
100
+ const eventTimeString = optionalInput ( constants_1 . ActionInputs . EventTime ) ;
77
101
const eventTime = eventTimeString ? parseInt ( eventTimeString ) : Date . now ( ) ;
78
102
let properties = {
79
103
triggering_event_name : process . env . GITHUB_EVENT_NAME ,
@@ -98,18 +122,28 @@ function run() {
98
122
const revision = process . env . GITHUB_EVENT_NAME === 'pull_request'
99
123
? ( _c = ( _b = github . context . payload . pull_request ) === null || _b === void 0 ? void 0 : _b . head ) === null || _c === void 0 ? void 0 : _c . sha
100
124
: process . env . GITHUB_SHA ;
125
+ if ( mablBranch ) {
126
+ core . info ( `Using mabl branch [${ mablBranch } ]` ) ;
127
+ }
101
128
core . info ( `Using git revision [${ revision } ]` ) ;
102
129
core . endGroup ( ) ;
103
130
core . startGroup ( 'Creating deployment event' ) ;
104
131
const apiClient = new mablApiClient_1 . MablApiClient ( apiKey ) ;
105
- const deployment = yield apiClient . postDeploymentEvent ( applicationId , environmentId , browserTypes , uri , rebaselineImages , setStaticBaseline , revision , eventTime , properties ) ;
106
- core . setOutput ( 'mabl-deployment-id' , deployment . id ) ;
107
- let outputLink = baseApiUrl ;
132
+ const deployment = yield apiClient . postDeploymentEvent ( browserTypes , planLabels , httpHeaders , rebaselineImages , setStaticBaseline , eventTime , properties , applicationId , environmentId , uri , revision , mablBranch ) ;
133
+ core . setOutput ( constants_1 . ActionOutputs . DeploymentId , deployment . id ) ;
134
+ let appOrEnv ;
108
135
if ( applicationId ) {
109
- const application = yield apiClient . getApplication ( applicationId ) ;
110
- outputLink = `${ baseApiUrl } /workspaces/${ application . organization_id } /events/${ deployment . id } ` ;
111
- core . info ( `Deployment triggered. View output at: ${ outputLink } ` ) ;
136
+ appOrEnv = yield apiClient . getApplication ( applicationId ) ;
137
+ }
138
+ else if ( environmentId ) {
139
+ appOrEnv = yield apiClient . getEnvironment ( environmentId ) ;
112
140
}
141
+ if ( ! appOrEnv ) {
142
+ core . setFailed ( 'Invalid configuration. Valid "application-id" or "environment-id" must be set. No tests started.' ) ;
143
+ return ;
144
+ }
145
+ const outputLink = `${ baseApiUrl } /workspaces/${ appOrEnv . organization_id } /events/${ deployment . id } ` ;
146
+ core . info ( `Deployment triggered. View output at: ${ outputLink } ` ) ;
113
147
core . startGroup ( 'Await completion of tests' ) ;
114
148
let executionComplete = false ;
115
149
while ( ! executionComplete ) {
@@ -132,12 +166,12 @@ function run() {
132
166
finalExecutionResult . executions . forEach ( ( execution ) => {
133
167
core . info ( table_1 . prettyFormatExecution ( execution ) ) ;
134
168
} ) ;
135
- core . setOutput ( 'plans_run' , '' + finalExecutionResult . plan_execution_metrics . total ) ;
136
- core . setOutput ( 'plans_passed' , '' + finalExecutionResult . plan_execution_metrics . passed ) ;
137
- core . setOutput ( 'plans_failed' , '' + finalExecutionResult . plan_execution_metrics . failed ) ;
138
- core . setOutput ( 'tests_run' , '' + finalExecutionResult . journey_execution_metrics . total ) ;
139
- core . setOutput ( 'tests_passed' , '' + finalExecutionResult . journey_execution_metrics . passed ) ;
140
- core . setOutput ( 'tests_failed' , '' + finalExecutionResult . journey_execution_metrics . failed ) ;
169
+ core . setOutput ( constants_1 . ActionOutputs . PlansRun , '' + finalExecutionResult . plan_execution_metrics . total ) ;
170
+ core . setOutput ( constants_1 . ActionOutputs . PlansPassed , '' + finalExecutionResult . plan_execution_metrics . passed ) ;
171
+ core . setOutput ( constants_1 . ActionOutputs . PlansFailed , '' + finalExecutionResult . plan_execution_metrics . failed ) ;
172
+ core . setOutput ( constants_1 . ActionOutputs . TestsRun , '' + finalExecutionResult . journey_execution_metrics . total ) ;
173
+ core . setOutput ( constants_1 . ActionOutputs . TestsPassed , '' + finalExecutionResult . journey_execution_metrics . passed ) ;
174
+ core . setOutput ( constants_1 . ActionOutputs . TestsFailed , '' + finalExecutionResult . journey_execution_metrics . failed ) ;
141
175
if ( finalExecutionResult . journey_execution_metrics . failed === 0 ) {
142
176
core . debug ( 'Deployment plans passed' ) ;
143
177
}
@@ -154,9 +188,7 @@ function run() {
154
188
}
155
189
} ) ;
156
190
}
157
- function parseBoolean ( toParse ) {
158
- return ( toParse === null || toParse === void 0 ? void 0 : toParse . toLowerCase ( ) ) === 'true' ;
159
- }
191
+ exports . run = run ;
160
192
function getExecutionsStillPending ( executionResult ) {
161
193
return executionResult . executions . filter ( ( execution ) => {
162
194
return ! ( EXECUTION_COMPLETED_STATUSES . includes ( execution . status ) &&
@@ -176,7 +208,7 @@ function getRelatedPullRequest() {
176
208
Authorization : `token ${ githubToken } ` ,
177
209
Accept : 'application/vnd.github.groot-preview+json' ,
178
210
'Content-Type' : 'application/json' ,
179
- 'User-Agent' : 'mabl-action' ,
211
+ 'User-Agent' : constants_1 . USER_AGENT ,
180
212
} ,
181
213
} ;
182
214
const client = axios_1 . default . create ( config ) ;
0 commit comments