|
| 1 | +/********************************************************************** |
| 2 | + * Companion script to create individual auto publication workflows for |
| 3 | + * specifications contained in the repository. Run the script any time |
| 4 | + * the auto-publish-template.yml is updated or when the list of specs |
| 5 | + * changes below. |
| 6 | + **********************************************************************/ |
| 7 | + |
| 8 | +/** |
| 9 | + * List of properties that can appear to describe a spec. |
| 10 | + */ |
| 11 | +const properties = [ |
| 12 | + // Spec shortname (without level), e.g., 'webcodecs' |
| 13 | + // (Shortname does not *have* to be the actual published shortname, just |
| 14 | + // an identifier used to tell specs apart internally) |
| 15 | + // The shortname is derived from the source file name if not provided, |
| 16 | + // replacing "_" with "-" |
| 17 | + 'shortname', |
| 18 | + |
| 19 | + // Spec status on /TR, e.g., 'WD' |
| 20 | + 'publicationStatus', |
| 21 | + |
| 22 | + // Relative path to source file |
| 23 | + 'source', |
| 24 | + |
| 25 | + // Relative path to destination file in gh-pages branch (Optional) |
| 26 | + // If not provided, the destination file is computed from the source by |
| 27 | + // removing `.src`. |
| 28 | + 'destination', |
| 29 | + |
| 30 | + // Name of the repository secret that contains the publication token for |
| 31 | + // Echidna (Optional). |
| 32 | + // If not provided, the name is computed from the shortname, e.g., |
| 33 | + // `ECHIDNA_TOKEN_WEBCODECS` for `webcodecs` |
| 34 | + 'tokenName', |
| 35 | + |
| 36 | + // Additional paths that should trigger the auto-publish script if changed |
| 37 | + // on top of the actual source (Optional). Glob patterns may be used. |
| 38 | + 'additionalPaths' |
| 39 | +]; |
| 40 | + |
| 41 | + |
| 42 | +/** |
| 43 | + * List of specs for which an auto-publish script needs to be created. |
| 44 | + */ |
| 45 | +const specs = [ |
| 46 | + { |
| 47 | + shortname: 'webcodecs', |
| 48 | + source: 'index.src.html', |
| 49 | + publicationStatus: 'WD' |
| 50 | + }, |
| 51 | + { |
| 52 | + source: 'codec_registry.src.html', |
| 53 | + publicationStatus: 'DRY' |
| 54 | + }, |
| 55 | + { |
| 56 | + source: 'avc_codec_registration.src.html', |
| 57 | + publicationStatus: 'NOTE-WD' |
| 58 | + }, |
| 59 | + { |
| 60 | + source: 'vorbis_codec_registration.src.html', |
| 61 | + publicationStatus: 'NOTE-WD' |
| 62 | + }, |
| 63 | + { |
| 64 | + source: 'mp3_codec_registration.src.html', |
| 65 | + publicationStatus: 'NOTE-WD' |
| 66 | + }, |
| 67 | + { |
| 68 | + source: 'aac_codec_registration.src.html', |
| 69 | + publicationStatus: 'NOTE-WD' |
| 70 | + }, |
| 71 | + { |
| 72 | + source: 'flac_codec_registration.src.html', |
| 73 | + publicationStatus: 'NOTE-WD' |
| 74 | + }, |
| 75 | + { |
| 76 | + source: 'opus_codec_registration.src.html', |
| 77 | + publicationStatus: 'NOTE-WD' |
| 78 | + }, |
| 79 | + { |
| 80 | + source: 'av1_codec_registration.src.html', |
| 81 | + publicationStatus: 'NOTE-WD' |
| 82 | + }, |
| 83 | + { |
| 84 | + source: 'vp9_codec_registration.src.html', |
| 85 | + publicationStatus: 'NOTE-WD' |
| 86 | + }, |
| 87 | + { |
| 88 | + source: 'vp8_codec_registration.src.html', |
| 89 | + publicationStatus: 'NOTE-WD' |
| 90 | + }, |
| 91 | + { |
| 92 | + source: 'pcm_codec_registration.src.html', |
| 93 | + publicationStatus: 'NOTE-WD' |
| 94 | + }, |
| 95 | + { |
| 96 | + source: 'alaw_codec_registration.src.html', |
| 97 | + publicationStatus: 'NOTE-WD' |
| 98 | + }, |
| 99 | + { |
| 100 | + source: 'ulaw_codec_registration.src.html', |
| 101 | + publicationStatus: 'NOTE-WD' |
| 102 | + }, |
| 103 | + { |
| 104 | + source: 'hevc_codec_registration.src.html', |
| 105 | + publicationStatus: 'NOTE-WD' |
| 106 | + }, |
| 107 | + { |
| 108 | + source: 'video_frame_metadata_registry.src.html', |
| 109 | + publicationStatus: 'DRY', |
| 110 | + tokenName: 'ECHIDNA_TOKEN_VIDEOFRAMEMETADATA_REGISTRY' |
| 111 | + } |
| 112 | +]; |
| 113 | + |
| 114 | + |
| 115 | +/** |
| 116 | + * Main loop, create a workflow per spec |
| 117 | + */ |
| 118 | +import assert from 'node:assert'; |
| 119 | +import { readFile, writeFile } from 'node:fs/promises'; |
| 120 | +import { dirname, join } from 'node:path'; |
| 121 | +import { fileURLToPath } from 'node:url'; |
| 122 | + |
| 123 | +const scriptPath = dirname(fileURLToPath(import.meta.url)); |
| 124 | +let template = await readFile(join(scriptPath, 'auto-publish-template.yml'), 'utf8'); |
| 125 | +template = template.replace(/#{5,}.*#{5,}/s, |
| 126 | +`###################################################################### |
| 127 | +# IMPORTANT: Do not edit this file directly! |
| 128 | +# |
| 129 | +# This workflow was automatically generated through the |
| 130 | +# generate-auto-publish-workflows.mjs script. To update the workflow, |
| 131 | +# make changes to the template file and run the script again. |
| 132 | +######################################################################`); |
| 133 | + |
| 134 | +for (const spec of specs) { |
| 135 | + if (!spec.shortname) { |
| 136 | + spec.shortname = spec.source.split('.')[0].replace(/_/g, '-'); |
| 137 | + } |
| 138 | + if (!spec.destination) { |
| 139 | + spec.destination = spec.source.replace(/\.src/, ''); |
| 140 | + } |
| 141 | + if (!spec.tokenName) { |
| 142 | + spec.tokenName = 'ECHIDNA_TOKEN_' + |
| 143 | + spec.shortname.toUpperCase() |
| 144 | + .replace(/-/g, '_') |
| 145 | + .replace(/_CODEC_/, '_'); // Tokens don't have "_CODEC_" in their name |
| 146 | + } |
| 147 | + if (spec.additionalPaths) { |
| 148 | + spec.additionalPaths = spec.additionalPaths.map(path => `\n - '${path}'`).join(''); |
| 149 | + } |
| 150 | + |
| 151 | + let content = template; |
| 152 | + for (const prop of properties) { |
| 153 | + content = content.replace(new RegExp('{{' + prop + '}}', 'g'), spec[prop] ?? ''); |
| 154 | + } |
| 155 | + |
| 156 | + const filename = join(scriptPath, 'workflows', `auto-publish-${spec.shortname}.yml`); |
| 157 | + await writeFile(filename, content, 'utf8'); |
| 158 | +} |
0 commit comments