Skip to content

Instantly share code, notes, and snippets.

@whynotavailable
Last active December 17, 2025 12:43
Show Gist options
  • Select an option

  • Save whynotavailable/88cc88d61f12fbd002e92fa6f076d70e to your computer and use it in GitHub Desktop.

Select an option

Save whynotavailable/88cc88d61f12fbd002e92fa6f076d70e to your computer and use it in GitHub Desktop.
A simple way to fix the nonsense that is the github actions format.
import { parseDocument, isMap, YAMLMap, Scalar } from 'yaml'
async function getInput(): Promise<string> {
return new Promise((resolve, reject) => {
let data = '';
process.stdin.setEncoding('utf8'); // Optional: interpret as text
process.stdin.on('readable', () => {
let chunk;
while ((chunk = process.stdin.read()) !== null) {
data += chunk;
}
});
// No idea what would cause this.
process.stdin.on('error', (error) => {
console.error(JSON.stringify(error))
reject()
})
process.stdin.on('end', () => {
resolve(data)
});
});
}
let doc = parseDocument(await getInput())
let jobs = doc.getIn(['jobs'], true)
let newJobList: any[] = [];
if (isMap<Scalar, YAMLMap>(jobs)) {
for (let job of jobs.items) {
let newObj = {
...(job.value?.toJSON()),
jobName: job.key.value,
}
newJobList.push(newObj)
}
}
doc.setIn(['jobs'], doc.createNode(newJobList))
console.log(JSON.stringify(doc.toJSON()))
@whynotavailable
Copy link
Author

What this does is an important job. It converts the yaml into JSON (much easier to deal with) and it turns the job list into an actual list. That is important as most languages do not retain an order for property maps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment