Last active
December 17, 2025 12:43
-
-
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.
This file contains hidden or 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
| 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())) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.