generated from actions/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.ts
More file actions
66 lines (54 loc) · 1.85 KB
/
main.ts
File metadata and controls
66 lines (54 loc) · 1.85 KB
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
import * as core from '@actions/core'
import { getComponentConfiguration } from './components-v4'
import { generateNomadJob } from './nomad/nomad_job'
import { ComponentDeploymentConfiguration } from './models/component_deployment_configuration'
/**
* The main function for the action.
* @returns {Promise<void>} Resolves when the action is complete.
*/
export async function run(): Promise<void> {
try {
const components = JSON.parse(
core.getInput('components', { required: true }),
) as Record<string, string>
const datacenters = (
core.getInput('datacenters', { required: false })?.split(',') || ['*']
)
.map(dc => dc.trim())
.filter(dc => dc.length > 0)
const resources = core
.getInput('resources', { required: false })
.split(';')
.map(resource => resource.trim())
.filter(resource => resource.length > 0)
const ouputJobs: Record<string, string> = {}
for (const [component, componentConfigurationPath] of Object.entries(
components,
)) {
if (!component || !componentConfigurationPath) {
core.setFailed('Invalid component configuration')
return
}
const componentConfiguration = getComponentConfiguration(
component,
resources,
componentConfigurationPath,
)
if (!componentConfiguration) {
continue
}
const [componentName, componentVersion] = component.split(':')
const job = generateNomadJob(
componentName,
componentVersion,
datacenters,
componentConfiguration.deployment as ComponentDeploymentConfiguration,
)
ouputJobs[component] = job
}
core.setOutput('nomad-files', JSON.stringify(ouputJobs))
} catch (error) {
// Fail the workflow run if an error occurs
if (error instanceof Error) core.setFailed(error.message)
}
}