Created
October 14, 2022 02:45
-
-
Save uphy/755bcb544f3faf81950c5e1d8a598172 to your computer and use it in GitHub Desktop.
CUE: File content injection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Embed: { | |
files: [string]: string | |
} | |
#Resource: { | |
#embed: [string]: #Embed | *{} | |
... | |
} | |
#Deliverable: { | |
destination: string | |
resources: [...#Resource] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
command: dump: X={ | |
for name, deliverable in deliverables { | |
for resource in deliverable.resources { | |
// Inject external file content | |
for embedVarName, embed in resource.#embed { | |
for i, f in embed.files { | |
"\(f)": file.Read & { | |
filename: f | |
contents: string | |
} | |
// hack: read the file content before write resource | |
"print-\(f)": os.Getenv & { | |
"dummy": X[f].contents | |
} | |
} | |
} | |
} | |
"write-\(name)": file.Create & { | |
filename: deliverable.destination | |
contents: yaml.MarshalStream([ for x in deliverable.resources { | |
x & { | |
for embedVarName, embed in x.#embed { | |
"\(embedVarName)": [ for f in embed.files { | |
{ | |
"\(f)": X[f].contents | |
} | |
}] | |
} | |
} | |
}]) | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
deliverables: sample: #Deliverable & { | |
destination: "foo.yaml" | |
resources: [ #Resource & { | |
// Special field for embedding | |
#embed: { | |
// target variable name | |
"a": { | |
files: { | |
// filename to filepath | |
"config.yaml": "path/to/config.yaml" | |
} | |
} | |
} | |
// Injection target | |
a: _ | *"" | |
}] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment