Skip to content

Ensure Node versions are aligned #7959

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ name: DCR CICD
on:
push:
paths-ignore:
- "apps-rendering/**"
- "dotcom-rendering/docs/**"
- 'apps-rendering/**'
- 'dotcom-rendering/docs/**'

jobs:
container:
Expand All @@ -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
Expand Down
91 changes: 91 additions & 0 deletions scripts/deno/deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

86 changes: 86 additions & 0 deletions scripts/deno/node.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import {
fromFileUrl,
resolve,
} from 'https://deno.land/[email protected]/path/mod.ts';
import { eq } from 'https://deno.land/[email protected]/semver/eq.ts';
import { parse as parseSemVer } from 'https://deno.land/[email protected]/semver/mod.ts';
import { SemVer } from 'https://deno.land/[email protected]/semver/types.ts';
import { parse as parseYaml } from 'https://deno.land/[email protected]/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');
}