Skip to content

Commit

Permalink
feat(types): fail on CI if mismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
mxdvl committed Jan 17, 2023
1 parent df27387 commit 4727604
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/dcr-dependencies.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: 📦 DCR Dependencies checks
on:
pull_request:
paths:
- 'dotcom-rendering/package.json'
- '**/yarn.lock'

# Allows you to run this workflow manually from the Actions tab.
workflow_dispatch:

jobs:
types-dependencies:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup deno
uses: denoland/setup-deno@v1
with:
deno-version: v1.29.4

- name: Check @types/ dependencies
run: deno run --allow-env="GITHUB_TOKEN" scripts/deno/types-dependencies.ts --ci
27 changes: 27 additions & 0 deletions scripts/deno/types-dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { octokit } from './github.ts';

const prefix = '@types/';

const ci = Deno.args[0] === '--ci';

const dependencies = Object.entries(pkg.dependencies)
.filter(([dependency]) => dependency.startsWith(prefix))
.map(([dependency, version]) => ({
Expand All @@ -26,6 +28,31 @@ if (nonTildeVersions.length) {
Deno.exit(1);
}

if (ci) {
/** For the following @types packages, we accept mismatches */
const knownErrors = [
'he', // https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/he
'webpack-node-externals', // https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/webpack-node-externals
];

const mismatches = dependencies
.filter(
(o): o is { type: [string, string]; main: [string, string] } =>
!!o.main,
)
.filter(({ main, type }) => main[1] !== type[1])
.map(({ main: [dependency] }) => dependency)
.filter((dependency) => !knownErrors.includes(dependency));

if (mismatches.length > 0) {
console.error('Mismatches in @types/ packages:', mismatches);
} else {
console.info('No @types/ package dependency mismatches found!');
}

Deno.exit(mismatches.length);
}

const body = `## Audit of \`@types/\` packages
### No main package found
Expand Down

0 comments on commit 4727604

Please sign in to comment.