Skip to content

Commit

Permalink
Merge pull request #6946 from guardian/mxdvl/peer-dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
mxdvl authored Jan 13, 2023
2 parents 2bd9283 + 0badf78 commit 11991ba
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 1 deletion.
6 changes: 5 additions & 1 deletion .github/workflows/scheduled.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: ⏰ Scheduled daily jobs
on:
schedule:
# Every work day of the week at 08:08
- cron: "8 8 * * MON-FRI"
- cron: '8 8 * * MON-FRI'

# Allows you to run this workflow manually from the Actions tab.
workflow_dispatch:
Expand All @@ -19,6 +19,10 @@ jobs:
with:
deno-version: v1.26.2

- uses: guardian/actions-setup-node@main
with:
cache: 'yarn'

- name: Run Deno scripts
run: scripts/ci-deno.sh
env:
Expand Down
7 changes: 7 additions & 0 deletions scripts/ci-deno.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,10 @@ deno run \
--allow-net \
--allow-env="GITHUB_TOKEN,CAPI_KEY" \
scripts/deno/iframe-titles.ts

deno run \
--no-check=remote \
--allow-net \
--allow-env="GITHUB_TOKEN" \
--allow-run=yarn,npm \
scripts/deno/peer-dependencies.ts
113 changes: 113 additions & 0 deletions scripts/deno/peer-dependencies.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import { octokit } from './github.ts';

const peers = async (cwd: string) => {
const process = Deno.run({
cwd,
cmd: ['yarn', '--force'],
stdout: 'null',
stderr: 'piped',
});

const [{ code }, rawOutput] = await Promise.all([
process.status(),
process.stderrOutput(),
]);

if (code !== 0) Deno.exit(code);

const deps = new TextDecoder()
.decode(rawOutput)
.split('\n')
// keep only incorrect peer dependencies warnings
.filter((line) => line.includes('has incorrect peer dependency'))
// strip out the workspace-aggregator-xyz-012 prefixes
.map((line) => line.replace(/workspace-aggregator-[a-z0-9-]+ > /, ''))
// apps-rendering are not part of the workspace
.map((line) => line.replace('" >', '"@guardian/apps-rendering >'));

return deps;
};

type Workspaces = { dcr: string[]; cr: string[]; ar: string[] };
const initialValue: Workspaces = { dcr: [], cr: [], ar: [] };

const { dcr, ar, cr } = (
await Promise.all(['.', './apps-rendering'].map(peers))
)
.flat()
.map((line) => {
const matches = line.match(
/warning "(.*?) > (.+?)" has incorrect peer dependency "(.+)"./,
);
if (!matches) throw new Error('Invalid string');

const [, workspace, dependency, peer] = matches;

return { workspace, dependency, peer };
})
.reduce<Workspaces>((acc, { workspace, dependency, peer }) => {
const line = `- [ ] \`${dependency}\` requires peer \`${peer}\``;
switch (workspace) {
case '@guardian/dotcom-rendering':
return {
...acc,
dcr: acc.dcr.concat(line),
};

case '@guardian/common-rendering':
return {
...acc,
cr: acc.cr.concat(line),
};

case '@guardian/apps-rendering':
return {
...acc,
ar: acc.ar.concat(line),
};
default:
return acc;
}
}, initialValue);

const body = `## Current peer dependencies mismatch
### dotcom-rendering
${dcr.length ? dcr.join('\n') : '- [X] all peer deps matched!'}
### apps-rendering
${ar.length ? ar.join('\n') : '- [X] all peer deps matched!'}
### common-rendering
${cr.length ? cr.join('\n') : '- [X] all peer deps matched!'}
`;

if (!octokit) {
console.log(body);
Deno.exit();
}

/** https://github.com/guardian/dotcom-rendering/issues/6945 */
const issue_number = 6945;

try {
const {
data: { html_url },
} = await octokit.rest.issues.update({
owner: 'guardian',
repo: 'dotcom-rendering',
issue_number,
body,
});

console.info(`Updated list of issues for dotcom-rendering#${issue_number}`);
console.info(html_url);
} catch (error) {
// do_something
console.warn(`Failed to update issue #${issue_number}`);
console.error(error);

console.log(body);
}

Deno.exit();

0 comments on commit 11991ba

Please sign in to comment.