From 63838128668fc7acce73767c4f94608e80d0ebfa Mon Sep 17 00:00:00 2001 From: Max Duval Date: Fri, 16 Jun 2023 14:40:55 +0100 Subject: [PATCH] feat: ensure node versions are aligned check the following places: - .nvmrc - riff-raff.yaml - Containerfile --- .github/workflows/cicd.yml | 13 +++++- scripts/deno/deno.lock | 91 ++++++++++++++++++++++++++++++++++++++ scripts/deno/node.ts | 86 +++++++++++++++++++++++++++++++++++ 3 files changed, 188 insertions(+), 2 deletions(-) create mode 100644 scripts/deno/node.ts diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index 3d958af4bcc..f23570b8dfe 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -3,8 +3,8 @@ name: DCR CICD on: push: paths-ignore: - - "apps-rendering/**" - - "dotcom-rendering/docs/**" + - 'apps-rendering/**' + - 'dotcom-rendering/docs/**' jobs: container: @@ -21,6 +21,15 @@ jobs: lint: uses: ./.github/workflows/lint.yml + node: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v3 + - uses: denoland/setup-deno@v1 + with: + deno-version: v1.x + - run: deno run -A scripts/deno/node.ts + cypress: needs: [container] uses: ./.github/workflows/cypress.yml diff --git a/scripts/deno/deno.lock b/scripts/deno/deno.lock index 24916ab0106..c56693cff36 100644 --- a/scripts/deno/deno.lock +++ b/scripts/deno/deno.lock @@ -1,6 +1,97 @@ { "version": "2", "remote": { + "https://deno.land/std@0.192.0/_util/asserts.ts": "178dfc49a464aee693a7e285567b3d0b555dc805ff490505a8aae34f9cfb1462", + "https://deno.land/std@0.192.0/_util/os.ts": "d932f56d41e4f6a6093d56044e29ce637f8dcc43c5a90af43504a889cf1775e3", + "https://deno.land/std@0.192.0/bytes/copy.ts": "939d89e302a9761dcf1d9c937c7711174ed74c59eef40a1e4569a05c9de88219", + "https://deno.land/std@0.192.0/io/buffer.ts": "17f4410eaaa60a8a85733e8891349a619eadfbbe42e2f319283ce2b8f29723ab", + "https://deno.land/std@0.192.0/path/_constants.ts": "e49961f6f4f48039c0dfed3c3f93e963ca3d92791c9d478ac5b43183413136e0", + "https://deno.land/std@0.192.0/path/_interface.ts": "6471159dfbbc357e03882c2266d21ef9afdb1e4aa771b0545e90db58a0ba314b", + "https://deno.land/std@0.192.0/path/_util.ts": "d7abb1e0dea065f427b89156e28cdeb32b045870acdf865833ba808a73b576d0", + "https://deno.land/std@0.192.0/path/common.ts": "ee7505ab01fd22de3963b64e46cff31f40de34f9f8de1fff6a1bd2fe79380000", + "https://deno.land/std@0.192.0/path/glob.ts": "d479e0a695621c94d3fd7fe7abd4f9499caf32a8de13f25073451c6ef420a4e1", + "https://deno.land/std@0.192.0/path/mod.ts": "f065032a7189404fdac3ad1a1551a9ac84751d2f25c431e101787846c86c79ef", + "https://deno.land/std@0.192.0/path/posix.ts": "8b7c67ac338714b30c816079303d0285dd24af6b284f7ad63da5b27372a2c94d", + "https://deno.land/std@0.192.0/path/separator.ts": "0fb679739d0d1d7bf45b68dacfb4ec7563597a902edbaf3c59b50d5bcadd93b1", + "https://deno.land/std@0.192.0/path/win32.ts": "d186344e5583bcbf8b18af416d13d82b35a317116e6460a5a3953508c3de5bba", + "https://deno.land/std@0.192.0/semver/_shared.ts": "7101b4118e96b8c7b600d54a8455d93afd96eaf43a69a3bff34513890ac264ae", + "https://deno.land/std@0.192.0/semver/cmp.ts": "4faca58ad459a8c7663ac84ed8410fb5cf932042969f5c25d285f319456d55c1", + "https://deno.land/std@0.192.0/semver/comparator_format.ts": "329e05d914c064590ded4801fc601bf1c5d0f461c5524b1578e10f180551ef6f", + "https://deno.land/std@0.192.0/semver/comparator_intersects.ts": "61920121a6c1600306dbcf8944c4cc55e45c3a1bdbefe41b79a0884bf02d9e1b", + "https://deno.land/std@0.192.0/semver/comparator_max.ts": "f4cc5f528abd8aab68c66bbead732e3c59102b13a318cd8e4f8a47aa3debec76", + "https://deno.land/std@0.192.0/semver/comparator_min.ts": "eea382428ebf0c50168f780898df8519c88da5a10d1f8babbfebdc89fb75942e", + "https://deno.land/std@0.192.0/semver/compare.ts": "503bb7b0ca67b722a0a8a5570486c20eb27ed9bc2316f25699fbd6317a3233ac", + "https://deno.land/std@0.192.0/semver/compare_build.ts": "dc315387ffba691206be83bb4195dff23af6df9983cf8dfb91c29e3f62b9bdca", + "https://deno.land/std@0.192.0/semver/constants.ts": "bb0c7652c433c7ec1dad5bf18c7e7e1557efe9ddfd5e70aa6305153e76dc318c", + "https://deno.land/std@0.192.0/semver/difference.ts": "b86b72f75308c0ab78a41bc676bdca0d933d75e0be8b06dafdc393689e70497f", + "https://deno.land/std@0.192.0/semver/eq.ts": "b8fc7184507423a2448f4b052fc4d9090bf316807b3c9c930afc3775d7a3f3a5", + "https://deno.land/std@0.192.0/semver/format.ts": "236cc8b5d2e8031258dcff3ca89e14ba926434d5b789730e2c781db172e76bd9", + "https://deno.land/std@0.192.0/semver/gt.ts": "2f20b21456179b3ac034656a09b5c259bf52dc2626a941ca038be5d201c415be", + "https://deno.land/std@0.192.0/semver/gte.ts": "d1ed0195a2b38ef0df586374eac4ad860d3b7e181ec1683e734912ce795aaddb", + "https://deno.land/std@0.192.0/semver/gtr.ts": "b0442acf1d52ceb337ec4f82afaa0da3b5251a9a08f4f0b8839ca4629d617078", + "https://deno.land/std@0.192.0/semver/increment.ts": "e41ffc906ea1d57e66987aa1b18ba1d0223d6fb0cd806448d012e4f8117e8513", + "https://deno.land/std@0.192.0/semver/is_semver.ts": "b21011d2afea366576bd283705df7515e8c85f5d03015aca83bc5a721f0cf344", + "https://deno.land/std@0.192.0/semver/is_semver_comparator.ts": "120ad68896e3481dbcda81ddd914c10d3fc891fe62cc99028cb69ebfa6c1427c", + "https://deno.land/std@0.192.0/semver/is_semver_range.ts": "0ea096e1edcb8e95200d3bee549c97b53e93ac60d4c2b3601ad7a01f27a0f4da", + "https://deno.land/std@0.192.0/semver/lt.ts": "c8711ffa1c40a3f98921b9bf0d80b59970d8cbc0a12696ebccacf6bccfa9dcc8", + "https://deno.land/std@0.192.0/semver/lte.ts": "721e5f9d353ecea757c1d5d42f4f6699d46cd24cdbd45b2bf88efdf82c0eaac4", + "https://deno.land/std@0.192.0/semver/ltr.ts": "2a10f426605408adcb6cb62e65e871eb6b235d74cbcc2160e58207751e7ca11d", + "https://deno.land/std@0.192.0/semver/max_satisfying.ts": "a8c550100582a9ad2f68026edef8a5ed09debbda0a65d28dceea302508aee41a", + "https://deno.land/std@0.192.0/semver/min_satisfying.ts": "04331cc956f55bc6d14f911ff2561dbab81e1218bfe6a080fe520b999e33e693", + "https://deno.land/std@0.192.0/semver/mod.ts": "79eaeb8015f3f34a34b1e2a98f524dbd5a9a5d7fa1d977cdfc5d6157965e8920", + "https://deno.land/std@0.192.0/semver/neq.ts": "c4116ac01149c4c090bdb5da2bbf946d1f9d74634c97486f3d7e55e75bb35bb0", + "https://deno.land/std@0.192.0/semver/outside.ts": "3ca074513c6f5ac4b3e9c0eda2deb3a83cdfcecc589f1ec69786d41f47885a89", + "https://deno.land/std@0.192.0/semver/parse.ts": "190dab1b5231da1fa6ec40567f58550209e7304dcb655fd8ae46eb7c2966a82b", + "https://deno.land/std@0.192.0/semver/parse_comparator.ts": "f07f9be8322b1f61a36b94c3c65a0dc4124958ee54cf744c92ca4028bf156d5e", + "https://deno.land/std@0.192.0/semver/parse_range.ts": "39a18608a8026004b218ef383e7ae624a9e663b82327948c1810f16d875113c2", + "https://deno.land/std@0.192.0/semver/range_format.ts": "3de31fd0b74dd565e052840e73a8e9ee1d9d289ca60b85749167710b978cc078", + "https://deno.land/std@0.192.0/semver/range_intersects.ts": "e646300d9a10868ae51dc70399c1eee31a503f24610506146eadbeac6bcc6777", + "https://deno.land/std@0.192.0/semver/range_max.ts": "9c10c65bbc7796347ce6f765a77865cead88870d17481ac78259400a2378af2e", + "https://deno.land/std@0.192.0/semver/range_min.ts": "b7849e70e0b0677b382eddaa822b6690521449a659c5b8ec84cbd438f6e6ca59", + "https://deno.land/std@0.192.0/semver/rcompare.ts": "fe4e95bf671bd119df89bc4dd9ceb3fdcc95bad543a78fa3b8ae67ce6b54bc03", + "https://deno.land/std@0.192.0/semver/rsort.ts": "d4bfa2b9fffa6e1afddeead68c7cb470ed932b3846acf45eccde2b46be021644", + "https://deno.land/std@0.192.0/semver/sort.ts": "301d18f7f96f9e46bb6d0327d3d97579fa2d49558c185a0a5035b8e6fbd4a73b", + "https://deno.land/std@0.192.0/semver/test_comparator.ts": "eff5394cb82d133ed18f96fe547de7e7264bf0d25d16cbc6126664aa06ef8f37", + "https://deno.land/std@0.192.0/semver/test_range.ts": "b236c276268e92bbbc65e7c4b4b6b685ea6b4534a71b2525b53093d094f631c6", + "https://deno.land/std@0.192.0/semver/try_parse.ts": "fc7eeafc18686563b0cc35b518eda57690e513e634527a0ff48c600ba7798ce4", + "https://deno.land/std@0.192.0/semver/try_parse_range.ts": "49be2271c4c07374fc2d986d5212fab7bb1f49daa485141e9bedd78d851ca5ca", + "https://deno.land/std@0.192.0/semver/types.ts": "d44f442c2f27dd89bd6695b369e310b80549746f03c38f241fe28a83b33dd429", + "https://deno.land/std@0.192.0/yaml/_dumper/dumper.ts": "a2c937a53a2b0473125a31a330334cc3f30e98fd82f8143bc225583d1260890b", + "https://deno.land/std@0.192.0/yaml/_dumper/dumper_state.ts": "f0d0673ceea288334061ca34b63954c2bb5feb5bf6de5e4cfe9a942cdf6e5efe", + "https://deno.land/std@0.192.0/yaml/_error.ts": "b59e2c76ce5a47b1b9fa0ff9f96c1dd92ea1e1b17ce4347ece5944a95c3c1a84", + "https://deno.land/std@0.192.0/yaml/_loader/loader.ts": "47b9592efcb390b58b1903cc471bfdf1fc71a0d2d2b31e37b5cae7d8804c7aed", + "https://deno.land/std@0.192.0/yaml/_loader/loader_state.ts": "0841870b467169269d7c2dfa75cd288c319bc06f65edd9e42c29e5fced91c7a4", + "https://deno.land/std@0.192.0/yaml/_mark.ts": "dcd8585dee585e024475e9f3fe27d29740670fb64ebb970388094cad0fc11d5d", + "https://deno.land/std@0.192.0/yaml/_state.ts": "ef03d55ec235d48dcfbecc0ab3ade90bfae69a61094846e08003421c2cf5cfc6", + "https://deno.land/std@0.192.0/yaml/_type/binary.ts": "d34d8c8d8ed521e270cfede3401c425b971af4f6c69da1e2cb32b172d42c7da7", + "https://deno.land/std@0.192.0/yaml/_type/bool.ts": "5bfa75da84343d45347b521ba4e5aeace9fe6f53447405290d53315a3fc20e66", + "https://deno.land/std@0.192.0/yaml/_type/float.ts": "056bd3cb9c5586238b20517511014fb24b0e36f98f9f6073e12da308b6b9808a", + "https://deno.land/std@0.192.0/yaml/_type/function.ts": "ff574fe84a750695302864e1c31b93f12d14ada4bde79a5f93197fc33ad17471", + "https://deno.land/std@0.192.0/yaml/_type/int.ts": "563ad074f0fa7aecf6b6c3d84135bcc95a8269dcc15de878de20ce868fd773fa", + "https://deno.land/std@0.192.0/yaml/_type/map.ts": "7b105e4ab03a361c61e7e335a0baf4d40f06460b13920e5af3fb2783a1464000", + "https://deno.land/std@0.192.0/yaml/_type/merge.ts": "8192bf3e4d637f32567917f48bb276043da9cf729cf594e5ec191f7cd229337e", + "https://deno.land/std@0.192.0/yaml/_type/mod.ts": "060e2b3d38725094b77ea3a3f05fc7e671fced8e67ca18e525be98c4aa8f4bbb", + "https://deno.land/std@0.192.0/yaml/_type/nil.ts": "606e8f0c44d73117c81abec822f89ef81e40f712258c74f186baa1af659b8887", + "https://deno.land/std@0.192.0/yaml/_type/omap.ts": "cfe59a294726f5cea705c39a61fd2b08199cf48f4ccd6b040cb550ec0f38d0a1", + "https://deno.land/std@0.192.0/yaml/_type/pairs.ts": "0032fdfe57558d21696a4f8cf5b5cfd1f698743177080affc18629685c905666", + "https://deno.land/std@0.192.0/yaml/_type/regexp.ts": "1ce118de15b2da43b4bd8e4395f42d448b731acf3bdaf7c888f40789f9a95f8b", + "https://deno.land/std@0.192.0/yaml/_type/seq.ts": "95333abeec8a7e4d967b8c8328b269e342a4bbdd2585395549b9c4f58c8533a2", + "https://deno.land/std@0.192.0/yaml/_type/set.ts": "f28ba44e632ef2a6eb580486fd47a460445eeddbdf1dbc739c3e62486f566092", + "https://deno.land/std@0.192.0/yaml/_type/str.ts": "a67a3c6e429d95041399e964015511779b1130ea5889fa257c48457bd3446e31", + "https://deno.land/std@0.192.0/yaml/_type/timestamp.ts": "706ea80a76a73e48efaeb400ace087da1f927647b53ad6f754f4e06d51af087f", + "https://deno.land/std@0.192.0/yaml/_type/undefined.ts": "94a316ca450597ccbc6750cbd79097ad0d5f3a019797eed3c841a040c29540ba", + "https://deno.land/std@0.192.0/yaml/_utils.ts": "26b311f0d42a7ce025060bd6320a68b50e52fd24a839581eb31734cd48e20393", + "https://deno.land/std@0.192.0/yaml/mod.ts": "28ecda6652f3e7a7735ee29c247bfbd32a2e2fc5724068e9fd173ec4e59f66f7", + "https://deno.land/std@0.192.0/yaml/parse.ts": "1fbbda572bf3fff578b6482c0d8b85097a38de3176bf3ab2ca70c25fb0c960ef", + "https://deno.land/std@0.192.0/yaml/schema.ts": "96908b78dc50c340074b93fc1598d5e7e2fe59103f89ff81e5a49b2dedf77a67", + "https://deno.land/std@0.192.0/yaml/schema/core.ts": "fa406f18ceedc87a50e28bb90ec7a4c09eebb337f94ef17468349794fa828639", + "https://deno.land/std@0.192.0/yaml/schema/default.ts": "0047e80ae8a4a93293bc4c557ae8a546aabd46bb7165b9d9b940d57b4d88bde9", + "https://deno.land/std@0.192.0/yaml/schema/extended.ts": "0784416bf062d20a1626b53c03380e265b3e39b9409afb9f4cb7d659fd71e60d", + "https://deno.land/std@0.192.0/yaml/schema/failsafe.ts": "d219ab5febc43f770917d8ec37735a4b1ad671149846cbdcade767832b42b92b", + "https://deno.land/std@0.192.0/yaml/schema/json.ts": "5f41dd7c2f1ad545ef6238633ce9ee3d444dfc5a18101e1768bd5504bf90e5e5", + "https://deno.land/std@0.192.0/yaml/schema/mod.ts": "4472e827bab5025e92bc2eb2eeefa70ecbefc64b2799b765c69af84822efef32", + "https://deno.land/std@0.192.0/yaml/stringify.ts": "fffc09c65c68d3d63f8159e8cbaa3f489bc20a8e55b4fbb61a8c2e9f914d1d02", + "https://deno.land/std@0.192.0/yaml/type.ts": "1aabb8e0a3f4229ce0a3526256f68826d9bdf65a36c8a3890ead8011fcba7670", "https://deno.land/x/deno_dom@v0.1.22-alpha/build/deno-wasm/deno-wasm.js": "077162a693528034d8ef84b6602e3562db3ce07c15ce2cf547fe76f7ef48f940", "https://deno.land/x/deno_dom@v0.1.22-alpha/deno-dom-wasm.ts": "bfd999a493a6974e9fca4d331bee03bfb68cfc600c662cd0b48b21d67a2a8ba0", "https://deno.land/x/deno_dom@v0.1.22-alpha/src/api.ts": "cddf406ac2bb73b3b92b1c587acf0a74519884a6e6798b2dbebe9a7ba8842d35", diff --git a/scripts/deno/node.ts b/scripts/deno/node.ts new file mode 100644 index 00000000000..a1d24233fc0 --- /dev/null +++ b/scripts/deno/node.ts @@ -0,0 +1,86 @@ +import { + fromFileUrl, + resolve, +} from 'https://deno.land/std@0.192.0/path/mod.ts'; +import { eq } from 'https://deno.land/std@0.192.0/semver/eq.ts'; +import { parse as parseSemVer } from 'https://deno.land/std@0.192.0/semver/mod.ts'; +import { SemVer } from 'https://deno.land/std@0.192.0/semver/types.ts'; +import { parse as parseYaml } from 'https://deno.land/std@0.192.0/yaml/mod.ts'; +import z from 'npm:zod@3'; + +const root = fromFileUrl(import.meta.resolve('../../')); +const issues: string[] = []; + +const nodeVersion = parseSemVer( + await Deno.readTextFile(resolve(root, '.nvmrc')), +); + +const format = ({ major, minor, patch }: SemVer) => + 'v' + [major, minor, patch].join('.'); + +console.info('Found node version:', format(nodeVersion)); + +const riffRaffFilepath = resolve( + root, + 'dotcom-rendering', + 'scripts', + 'deploy', + 'riff-raff.yaml', +); +const { + deployments: { + 'frontend-cfn': { + parameters: { + amiParametersToTags: { + AMI: { Recipe: riffRaffRecipe }, + }, + }, + }, + }, +} = z + .object({ + deployments: z.object({ + 'frontend-cfn': z.object({ + parameters: z.object({ + amiParametersToTags: z.object({ + AMI: z.object({ + Recipe: z.string(), + }), + }), + }), + }), + }), + }) + .parse(parseYaml(await Deno.readTextFile(riffRaffFilepath))); + +if (!riffRaffRecipe.split('-').includes(`node${nodeVersion.major}`)) { + issues.push( + 'Mismatches node version in Riff-Raff AMI', + riffRaffRecipe, + riffRaffFilepath, + ); +} + +const dcrContainerFilepath = resolve(root, 'dotcom-rendering', 'Containerfile'); +const containerNodeVersion = parseSemVer( + (await Deno.readTextFile(dcrContainerFilepath)).match( + /^FROM node:([0-9\.]+)-alpine$/m, + )?.[1] ?? '---', +); + +if (!eq(nodeVersion, containerNodeVersion)) { + issues.push( + 'Mismatched node versions in Containerfile', + format(containerNodeVersion), + dcrContainerFilepath, + ); +} + +if (issues.length > 0) { + for (const issue of issues) { + console.error(issue); + } + Deno.exit(1); +} else { + console.info('All Node versions match'); +}