Skip to content

Commit bfc96b8

Browse files
committed
Add dry runs to CI
1 parent 30a91f7 commit bfc96b8

13 files changed

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

.github/workflows/retag.yml

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { defaultLocalOptions } from "./lib/common";
1+
import process from "process";
2+
import { defaultLocalOptions, defaultRemoteOptions } from "./lib/common";
23
import { ChangedPackages, ChangedPackagesJson, ChangedTypingJson, versionsFilename } from "./lib/versions";
34
import { getDefinitelyTyped, AllPackages, NotNeededPackage, writeDataFile } from "@definitelytyped/definitions-parser";
45
import { logUncaughtErrors, loggerWithErrors, FS, LoggerWithErrors, defaultCacheDir } from "@definitelytyped/utils";
@@ -7,7 +8,12 @@ import * as pacote from "pacote";
78

89
if (!module.parent) {
910
const log = loggerWithErrors()[0];
10-
logUncaughtErrors(async () => calculateVersions(await getDefinitelyTyped(defaultLocalOptions, log), log));
11+
logUncaughtErrors(async () =>
12+
calculateVersions(
13+
await getDefinitelyTyped(process.env.GITHUB_ACTIONS ? defaultRemoteOptions : defaultLocalOptions, log),
14+
log
15+
)
16+
);
1117
}
1218

1319
export default async function calculateVersions(dt: FS, log: LoggerWithErrors): Promise<ChangedPackages> {

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/parse-definitions.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import os from "os";
2+
import process from "process";
23
import yargs from "yargs";
34
import { logUncaughtErrors, loggerWithErrors, assertDefined, FS } from "@definitelytyped/utils";
4-
import { defaultLocalOptions } from "./lib/common";
5+
import { defaultLocalOptions, defaultRemoteOptions } from "./lib/common";
56
import { getTypingInfo } from "@definitelytyped/definitions-parser/dist/lib/definition-parser";
67
import {
78
getDefinitelyTyped,
@@ -16,7 +17,7 @@ if (!module.parent) {
1617
nProcesses: { type: "number" },
1718
}).argv;
1819

19-
const options = defaultLocalOptions;
20+
const options = process.env.GITHUB_ACTIONS ? defaultRemoteOptions : defaultLocalOptions;
2021
logUncaughtErrors(async () => {
2122
const log = loggerWithErrors()[0];
2223
const dt = await getDefinitelyTyped(options, log);

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 { deprecateNotNeededPackage, publishNotNeededPackage, publishTypingsPackage } from "./lib/package-publisher";
67
import { getDefinitelyTyped, AllPackages } from "@definitelytyped/definitions-parser";
78
import {
@@ -20,7 +21,10 @@ if (!module.parent) {
2021
const dry = !!yargs.argv.dry;
2122
const deprecateName = yargs.argv.deprecate as string | undefined;
2223
logUncaughtErrors(async () => {
23-
const dt = await getDefinitelyTyped(defaultLocalOptions, loggerWithErrors()[0]);
24+
const dt = await getDefinitelyTyped(
25+
process.env.GITHUB_ACTIONS ? defaultRemoteOptions : defaultLocalOptions,
26+
loggerWithErrors()[0]
27+
);
2428
if (deprecateName !== undefined) {
2529
// A '--deprecate' command is available in case types-publisher got stuck *while* trying to deprecate a package.
2630
// Normally this should not be needed.
@@ -56,7 +60,7 @@ export default async function publishPackages(
5660
log("=== Publishing packages ===");
5761
}
5862

59-
const client = await NpmPublishClient.create(await getSecret(Secret.NPM_TOKEN), undefined);
63+
const client = await NpmPublishClient.create(dry ? "" : await getSecret(Secret.NPM_TOKEN), undefined);
6064

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

0 commit comments

Comments
 (0)