Skip to content

Commit

Permalink
Mark removed types as deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
jablko committed May 9, 2022
1 parent a919c12 commit 0bd18b7
Show file tree
Hide file tree
Showing 9 changed files with 479 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ jobs:
uses: ./.github/workflows/retag.yml
with:
dry: true
deprecate-dry:
needs: build_and_test
uses: ./.github/workflows/deprecate.yml
with:
dry: true
publish_alpha:
name: publish alpha release
runs-on: ubuntu-latest
Expand Down
34 changes: 34 additions & 0 deletions .github/workflows/deprecate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Mark removed types as deprecated
on:
workflow_call:
inputs:
dry:
description: Dry run
type: boolean
workflow_dispatch:
inputs:
dry:
description: Dry run
type: boolean
jobs:
deprecate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
cache: yarn
- run: yarn install --frozen-lockfile
- run: yarn build
- name: Parse declarations
run: yarn workspace @definitelytyped/publisher parse
- name: Mark removed types as deprecated${{ (inputs || github.event.inputs).dry && ' dry run' }}
run: node --require source-map-support/register packages/deprecate/${{ (inputs || github.event.inputs).dry && ' --dry' }}
env:
GH_API_TOKEN: ${{ secrets.GH_API_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_RETAG_TOKEN }}
- if: always()
uses: actions/upload-artifact@v3
with:
name: ${{ github.job }}
path: packages/definitions-parser/data/
3 changes: 0 additions & 3 deletions .github/workflows/retag.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
name: Update npm tags
on:
schedule:
# https://crontab.guru/#0_0_*_*_0
- cron: 0 0 * * 0
workflow_call:
inputs:
dry:
Expand Down
19 changes: 19 additions & 0 deletions .github/workflows/weekly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Weekly
on:
schedule:
# https://crontab.guru/#0_0_*_*_0
- cron: 0 0 * * 0
workflow_dispatch:
inputs:
dry:
description: Dry run
type: boolean
jobs:
retag:
uses: ./.github/workflows/retag.yml
with:
dry: ${{ github.event.inputs.dry }}
deprecate:
uses: ./.github/workflows/deprecate.yml
with:
dry: ${{ github.event.inputs.dry }}
20 changes: 20 additions & 0 deletions packages/deprecate/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@definitelytyped/deprecate",
"version": "1.0.0",
"description": "Loop over npm @types packages and mark as deprecated any that no longer exist in the DT repo.",
"license": "MIT",
"main": "dist/index.js",
"scripts": {
"build": "tsc --build"
},
"dependencies": {
"@definitelytyped/definitions-parser": "0.0.113-next.7",
"@definitelytyped/utils": "0.0.113-next.7",
"@octokit/graphql": "^4.8.0",
"libnpmsearch": "^5.0.3",
"yargs": "^17.4.1"
},
"devDependencies": {
"@types/libnpmsearch": "^2.0.3"
}
}
89 changes: 89 additions & 0 deletions packages/deprecate/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/usr/bin/env node

import process from "process";
import { AllPackages, getDefinitelyTyped } from "@definitelytyped/definitions-parser";
import { loggerWithErrors, NpmPublishClient } from "@definitelytyped/utils";
import { graphql } from "@octokit/graphql";
import search from "libnpmsearch";
import yargs from "yargs";

main();

async function main() {
const { dry } = yargs.argv;
const [log] = loggerWithErrors();
const options = { definitelyTypedPath: undefined, progress: false, parseInParallel: false };
const dt = await getDefinitelyTyped(options, log);
const allPackages = await AllPackages.read(dt);
const client = await NpmPublishClient.create(process.env.NPM_TOKEN!);
// Loop over npm @types packages and mark as deprecated any that no longer exist in the DT repo.
let from = 0;
let results;
do {
const opts = { limit: 250, from };
results = await search("@types", opts);
for (const result of results) {
const types = result.name.slice("@types/".length);
// Skip ones that exist, either in the types/ directory or in notNeededPackages.json.
if (allPackages.tryGetLatestVersion(types) || allPackages.getNotNeededPackage(types)) continue;
// Reference the commit/PR that removed it.
const msg = await fetchMsg(types);
if (!msg) {
log.info(`Could not find the commit that removed types/${types}/.`);
continue
}
log.info(`Deprecating ${result.name}: ${msg}`);
if (!dry) await client.deprecate(result.name, "*", msg);
}
from += results.length;
} while (results.length >= 250 && from <= 5000);
}

async function fetchMsg(types: string) {
const {
repository: {
defaultBranchRef: {
target: {
history: {
nodes: [commit],
},
},
},
},
} = await graphql(
`
query ($path: String!) {
repository(name: "DefinitelyTyped", owner: "DefinitelyTyped") {
defaultBranchRef {
target {
... on Commit {
history(first: 1, path: $path) {
nodes {
associatedPullRequests(first: 1) {
nodes {
url
}
}
messageHeadline
}
}
}
}
}
}
}
`,
{
headers: { authorization: `token ${process.env.GH_API_TOKEN}` },
path: `types/${types}/`,
}
);
if (!commit) return;
const {
associatedPullRequests: {
nodes: [pullRequest],
},
messageHeadline,
} = commit;
return pullRequest ? `${messageHeadline} ${pullRequest.url}` : messageHeadline;
}
8 changes: 8 additions & 0 deletions packages/deprecate/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "dist"
},
"references": [{ "path": "../definitions-parser/" }, { "path": "../utils/" }]
}
5 changes: 3 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
"files": [],
"references": [
{ "path": "packages/definitions-parser" },
{ "path": "packages/deprecate" },
{ "path": "packages/dts-critic" },
{ "path": "packages/dtslint" },
{ "path": "packages/dtslint-runner" },
{ "path": "packages/header-parser" },
{ "path": "packages/perf" },
{ "path": "packages/publisher" },
{ "path": "packages/retag" },
{ "path": "packages/typescript-versions" },
{ "path": "packages/utils" },
{ "path": "packages/retag" }
{ "path": "packages/utils" }
]
}
Loading

0 comments on commit 0bd18b7

Please sign in to comment.