Skip to content

Commit 2c0b58a

Browse files
committed
Add dry runs to CI
1 parent 4011b70 commit 2c0b58a

File tree

10 files changed

+125
-50
lines changed

10 files changed

+125
-50
lines changed

.github/workflows/ci.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,21 @@ jobs:
3636
run: yarn lint
3737
- name: test
3838
run: yarn test
39+
publish-packages-dry-run:
40+
needs: build_and_test
41+
uses: ./.github/workflows/publish-packages.yml
42+
with:
43+
dry-run: true
44+
publish-registry-dry-run:
45+
needs: build_and_test
46+
uses: ./.github/workflows/publish-registry.yml
47+
with:
48+
dry-run: true
49+
retag-dry-run:
50+
needs: build_and_test
51+
uses: ./.github/workflows/retag.yml
52+
with:
53+
dry-run: true
3954
publish_alpha:
4055
name: publish alpha release
4156
runs-on: ubuntu-latest
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Publish packages
2+
#description: Find changed @types packages in the DT repo and publish them to npm.
3+
on:
4+
workflow_call:
5+
inputs:
6+
dry-run:
7+
type: boolean
8+
workflow_dispatch:
9+
inputs:
10+
dry-run:
11+
type: boolean
12+
jobs:
13+
publish-packages:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v3
17+
- uses: actions/setup-node@v3
18+
with:
19+
cache: yarn
20+
- run: yarn install --frozen-lockfile
21+
- run: yarn build
22+
- name: Parse declarations
23+
run: yarn workspace @definitelytyped/publisher parse
24+
- uses: actions/cache@v3
25+
with:
26+
path: packages/utils/cache/
27+
key: cache-${{ github.run_id }}
28+
restore-keys: cache-
29+
- name: Calculate versions
30+
run: yarn workspace @definitelytyped/publisher calculate-versions
31+
- name: Generate packages
32+
run: yarn workspace @definitelytyped/publisher generate
33+
- name: Publish packages${{ (inputs || github.event.inputs).dry-run && ' dry run' || '' }}
34+
run: yarn workspace @definitelytyped/publisher publish-packages${{ (inputs || github.event.inputs).dry-run && ' --dry' || '' }}
35+
env:
36+
GH_API_TOKEN: ${{ github.token }}
37+
NPM_TOKEN: ${{ secrets.NPM_RETAG_TOKEN }}
38+
- if: always()
39+
uses: actions/upload-artifact@v3
40+
with:
41+
name: ${{ github.job }}
42+
path: packages/definitions-parser/data/

.github/workflows/publish-registry.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
name: Publish registry
2+
#description: Publish the types-regsitry package to npm (a list of all @types packages in the DT repo).
23
on:
34
schedule:
45
# https://crontab.guru/#0_0_*_*_0
56
- cron: 0 0 * * 0
7+
workflow_call:
8+
inputs:
9+
dry-run:
10+
type: boolean
611
workflow_dispatch:
12+
inputs:
13+
dry-run:
14+
type: boolean
715
jobs:
816
publish-registry:
17+
if: github.event_name != 'schedule' || github.repository == 'microsoft/DefinitelyTyped-tools'
918
runs-on: ubuntu-latest
1019
steps:
1120
- uses: actions/checkout@v3
@@ -21,11 +30,12 @@ jobs:
2130
path: packages/utils/cache/
2231
key: cache-${{ github.run_id }}
2332
restore-keys: cache-
24-
- name: Publish registry
25-
run: yarn workspace @definitelytyped/publisher publish-registry
33+
- name: Publish registry${{ (inputs || github.event.inputs).dry-run && ' dry run' || '' }}
34+
run: yarn workspace @definitelytyped/publisher publish-registry${{ (inputs || github.event.inputs).dry-run && ' --dry' || '' }}
2635
env:
2736
NPM_TOKEN: ${{ secrets.NPM_RETAG_TOKEN }}
2837
- if: always()
2938
uses: actions/upload-artifact@v3
3039
with:
40+
name: ${{ github.job }}
3141
path: packages/definitions-parser/data/

.github/workflows/retag.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Update npm tags
2+
#description: Refresh tags on all DT-published packages in the @types scope.
3+
on:
4+
schedule:
5+
# https://crontab.guru/#0_0_*_*_0
6+
- cron: 0 0 * * 0
7+
workflow_call:
8+
inputs:
9+
dry-run:
10+
type: boolean
11+
workflow_dispatch:
12+
inputs:
13+
dry-run:
14+
type: boolean
15+
jobs:
16+
retag:
17+
if: github.event_name != 'schedule' || github.repository == 'microsoft/DefinitelyTyped-tools'
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v3
21+
- uses: actions/setup-node@v3
22+
with:
23+
cache: yarn
24+
- run: yarn install --frozen-lockfile
25+
- run: yarn build
26+
- uses: actions/cache@v3
27+
with:
28+
path: packages/utils/cache/
29+
key: cache-${{ github.run_id }}
30+
restore-keys: cache-
31+
- name: Update npm tags${{ (inputs || github.event.inputs).dry-run && ' dry run' || '' }}
32+
run: yarn retag${{ (inputs || github.event.inputs).dry-run && ' --dry' || '' }}
33+
env:
34+
NPM_TOKEN: ${{ secrets.NPM_RETAG_TOKEN }}
35+
- if: always()
36+
uses: actions/upload-artifact@v3
37+
with:
38+
name: ${{ github.job }}
39+
path: packages/definitions-parser/data/

.github/workflows/update-ts-version-tags.yml

Lines changed: 0 additions & 35 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"format": "prettier --write 'packages/**/*.ts'",
1212
"test": "jest",
1313
"build": "tsc -b .",
14-
"retag": "node packages/retag/dist/retag.js"
14+
"retag": "node --require source-map-support/register packages/retag/"
1515
},
1616
"devDependencies": {
1717
"@types/jest": "^25.1.3",

packages/publisher/src/generate-packages.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { makeTypesVersionsForPackageJson } from "@definitelytyped/header-parser";
22
import { emptyDir, mkdir, mkdirp, readFileSync } from "fs-extra";
33
import path = require("path");
4+
import process from "process";
45
import yargs = require("yargs");
56

6-
import { defaultLocalOptions } from "./lib/common";
7+
import { defaultLocalOptions, defaultRemoteOptions } from "./lib/common";
78
import { outputDirPath, sourceBranch } from "./lib/settings";
89
import {
910
assertNever,
@@ -42,7 +43,7 @@ if (!module.parent) {
4243
const tgz = !!yargs.argv.tgz;
4344
logUncaughtErrors(async () => {
4445
const log = loggerWithErrors()[0];
45-
const dt = await getDefinitelyTyped(defaultLocalOptions, log);
46+
const dt = await getDefinitelyTyped(process.env.GITHUB_ACTIONS ? defaultRemoteOptions : defaultLocalOptions, log);
4647
const allPackages = await AllPackages.read(dt);
4748
await generatePackages(dt, allPackages, await readChangedPackages(allPackages), tgz);
4849
});

packages/publisher/src/publish-packages.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import process from "process";
12
import applicationinsights = require("applicationinsights");
23
import * as yargs from "yargs";
34

4-
import { defaultLocalOptions } from "./lib/common";
5+
import { defaultLocalOptions, defaultRemoteOptions } from "./lib/common";
56
import { publishNotNeededPackage, publishTypingsPackage } from "./lib/package-publisher";
67
import { getDefinitelyTyped, AllPackages } from "@definitelytyped/definitions-parser";
78
import {
@@ -19,7 +20,10 @@ import { getSecret, Secret } from "./lib/secrets";
1920
if (!module.parent) {
2021
const dry = !!yargs.argv.dry;
2122
logUncaughtErrors(async () => {
22-
const dt = await getDefinitelyTyped(defaultLocalOptions, loggerWithErrors()[0]);
23+
const dt = await getDefinitelyTyped(
24+
process.env.GITHUB_ACTIONS ? defaultRemoteOptions : defaultLocalOptions,
25+
loggerWithErrors()[0]
26+
);
2327
await publishPackages(
2428
await readChangedPackages(await AllPackages.read(dt)),
2529
dry,
@@ -42,7 +46,7 @@ export default async function publishPackages(
4246
log("=== Publishing packages ===");
4347
}
4448

45-
const client = await NpmPublishClient.create(await getSecret(Secret.NPM_TOKEN), undefined);
49+
const client = await NpmPublishClient.create(dry ? "" : await getSecret(Secret.NPM_TOKEN), undefined);
4650

4751
for (const cp of changedPackages.changedTypings) {
4852
log(`Publishing ${cp.pkg.desc}...`);

packages/retag/package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@
3131
"@types/yargs": "^15.0.5"
3232
},
3333
"main": "dist/index.js",
34-
"bin": {
35-
"retag": "./dist/retag.js"
36-
},
3734
"publishConfig": {
3835
"access": "public"
3936
}

packages/retag/src/index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env node
2-
31
import assert = require("assert");
42
import yargs from "yargs";
53
import process = require("process");
@@ -49,10 +47,14 @@ async function main() {
4947
*/
5048
async function tag(dry: boolean, nProcesses: number, name?: string) {
5149
const log = loggerWithErrors()[0];
52-
const options = { definitelyTypedPath: "../DefinitelyTyped", progress: true, parseInParallel: true };
50+
const options = process.env.GITHUB_ACTIONS
51+
? { definitelyTypedPath: undefined, progress: false, parseInParallel: false }
52+
: { definitelyTypedPath: "../DefinitelyTyped", progress: true, parseInParallel: true };
5353
await parseDefinitions(
5454
await getDefinitelyTyped(options, log),
55-
{ nProcesses: nProcesses || os.cpus().length, definitelyTypedPath: "../DefinitelyTyped" },
55+
options.parseInParallel
56+
? { nProcesses: nProcesses || os.cpus().length, definitelyTypedPath: "../DefinitelyTyped" }
57+
: undefined,
5658
log
5759
);
5860

0 commit comments

Comments
 (0)