This is right but also not very useful

This commit is contained in:
Jacob Wallraff
2022-12-15 15:13:29 -08:00
parent 83deacf81c
commit 77674c74e1
2 changed files with 18 additions and 36 deletions
@@ -5,27 +5,18 @@ import {WorkflowContext} from "../context/workflow-context";
export function getJobContext(workflowContext: WorkflowContext): data.Dictionary {
// https://docs.github.com/en/actions/learn-github-actions/contexts#job-context
const keys = ["container", "services", "status"];
const jobContext = new data.Dictionary();
const job = workflowContext.job;
if (!job) {
return new data.Dictionary(
...keys.map(key => {
return {key, value: new data.Null()};
})
);
return jobContext
}
// Container
const jobContainer = job.container;
if (jobContainer && isMapping(jobContainer)) {
let containerContext = createContainerContext(jobContainer);
let containerContext = createContainerContext(jobContainer, false);
jobContext.add("container", containerContext);
}
else {
jobContext.add("container", new data.Null());
}
// Services
const jobServices = job.services;
@@ -35,14 +26,11 @@ export function getJobContext(workflowContext: WorkflowContext): data.Dictionary
if (!isMapping(service.value)) {
continue
}
let serviceContext = createContainerContext(service.value);
let serviceContext = createContainerContext(service.value, true);
servicesContext.add(service.key.toString(), serviceContext);
}
jobContext.add("services", servicesContext);
}
else {
jobContext.add("services", new data.Null());
}
// Status
jobContext.add("status", new data.Null());
@@ -50,30 +38,35 @@ export function getJobContext(workflowContext: WorkflowContext): data.Dictionary
return jobContext;
}
function createContainerContext(container: MappingToken): data.Dictionary {
function createContainerContext(container: MappingToken, isServices: boolean): data.Dictionary {
const containerContext = new data.Dictionary();
for (const token of container) {
if (isString(token.value)) {
// image and options
containerContext.add(token.key.toString(), new data.StringData(token.value.toString()));
// containerContext.add(token.key.toString(), new data.StringData(token.value.toString()));
}
else if (isSequence(token.value)) {
// ports and volumes
// service ports are the only thing that is part of the job context
const sequence = new data.Array();
for (const item of token.value) {
sequence.add(new data.StringData(item.toString()));
if (item.toString() === "ports" && isServices) {
sequence.add(new data.StringData(item.toString()));
}
}
containerContext.add(token.key.toString(), new data.Array(sequence));
}
else if (isMapping(token.value)) {
// credentials and env
const dict = new data.Dictionary();
for (const item of token.value) {
containerContext.add(item.key.toString(), new data.StringData(item.value.toString()));
}
containerContext.add(token.key.toString(), dict);
// const dict = new data.Dictionary();
// for (const item of token.value) {
// containerContext.add(item.key.toString(), new data.StringData(item.value.toString()));
// }
// containerContext.add(token.key.toString(), dict);
}
}
containerContext.add("id", new data.Null());
containerContext.add("network", new data.Null());
return containerContext;
}
@@ -269,24 +269,13 @@ jobs:
services:
nginx:
image: node:14.16
env:
NODE_ENV: development
ports:
- 80
volumes:
- my_docker_volume:/volume_mount
options: --cpus 1
credentials:
username: actor
password: password
steps:
- run: echo \${{ job.services.nginx }}
- run: echo \${{ job.services.nginx.image }}
- run: echo \${{ job.services.nginx.env }}
- run: echo \${{ job.services.nginx.id }}
- run: echo \${{ job.services.nginx.network }}
- run: echo \${{ job.services.nginx.ports }}
- run: echo \${{ job.services.nginx.volumes }}
- run: echo \${{ job.services.nginx.options }}
- run: echo \${{ job.services.nginx.credentials }}
`;
const result = await validate(createDocument("wf.yaml", input));