-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
113 lines (93 loc) · 3.51 KB
/
index.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
import path from 'node:path'
import * as github from '@actions/github'
import * as core from '@actions/core'
import type { PullRequestEvent } from '@octokit/webhooks-types'
import type { InputsParams } from './src/input.js'
import { getParams, logsParams } from './src/input.js'
import { getSources } from './src/source.js'
import { runBundler } from './src/bundler.js'
import { runUploaders } from './src/uploader.js'
import { handleError, logsErrors } from './src/errors.js'
import { updateClosedPRInteraction, updateModifiedBundleInteraction } from './src/interaction.js'
import { autoCommitUuid } from './src/auto.js'
try {
run()
}
catch (error) {
core.setFailed('An error occurred while running the action.')
logsErrors(path.resolve(), handleError(error))
}
async function run() {
const context = github.context
const params = await getParams(context)
logsParams(params)
if (core.isDebug()) {
core.startGroup('Debug context')
core.debug(JSON.stringify(context, null, 2))
core.endGroup()
}
switch (params.mode) {
case 'manual':
return await runManual(params)
case 'push':
return await runPush(params)
case 'pull_request':
return await runPullRequest(params)
}
}
async function runManual(params: InputsParams) {
const context = github.context
const sources = await getSources(params, context)
if (params.ci.autoCommitUuid) {
try {
await autoCommitUuid(params, sources)
}
catch (error) {
logsErrors(path.resolve(), handleError(error))
core.setFailed('An error occurred while auto-commiting UUID')
return
}
}
const bundlerResult = params.bundler.enabled
? await runBundler(params, sources)
: { memoryBundles: [], diskBundles: [], validationErrors: [] }
if (params.upload.artifact.enabled || params.upload.store.enabled)
await runUploaders(params, context, bundlerResult)
}
async function runPush(params: InputsParams) {
const context = github.context
const sources = await getSources(params, context)
if (params.ci.autoCommitUuid) {
try {
await autoCommitUuid(params, sources)
}
catch (error) {
logsErrors(path.resolve(), handleError(error))
core.setFailed('An error occurred while auto-commiting UUID')
return
}
}
const bundlerResult = params.bundler.enabled
? await runBundler(params, sources)
: { memoryBundles: [], diskBundles: [], validationErrors: [] }
if (params.upload.artifact.enabled || params.upload.store.enabled)
await runUploaders(params, context, bundlerResult)
await updateClosedPRInteraction(params, context, sources, bundlerResult)
}
async function runPullRequest(params: InputsParams) {
const context = github.context
if (context.eventName !== 'pull_request')
throw new Error('This action is supposed to run on pull_request event')
const payload = context.payload as PullRequestEvent
core.info(`Running Pull Request mode / ${payload.action}`)
const sources = await getSources(params, context)
const bundler = await runBundler(params, sources)
if (bundler.memoryBundles.filter(bundle => bundle.status !== 'unchanged').length === 0) {
core.info('No bundles changed stopping the action')
return
}
if (['opened', 'reopened', 'synchronize'].includes(payload.action)) {
const uploader = await runUploaders(params, context, bundler)
await updateModifiedBundleInteraction(params, context, sources, bundler, uploader)
}
}