-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
479 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/" }] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.