Skip to content

Commit

Permalink
Add dry runs to CI
Browse files Browse the repository at this point in the history
  • Loading branch information
jablko committed May 22, 2022
1 parent d673219 commit bf27c30
Show file tree
Hide file tree
Showing 13 changed files with 173 additions and 53 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@ jobs:
run: yarn lint
- name: test
run: yarn test
publish-packages-dry:
needs: build_and_test
uses: ./.github/workflows/publish-packages.yml
with:
dry: true
publish-registry-dry:
needs: build_and_test
uses: ./.github/workflows/publish-registry.yml
with:
dry: true
retag-dry:
needs: build_and_test
uses: ./.github/workflows/retag.yml
with:
dry: true
publish_alpha:
name: publish alpha release
runs-on: ubuntu-latest
Expand Down
43 changes: 43 additions & 0 deletions .github/workflows/publish-packages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Publish packages
on:
workflow_call:
inputs:
dry:
description: Dry run
type: boolean
workflow_dispatch:
inputs:
dry:
description: Dry run
type: boolean
jobs:
publish-packages:
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
- uses: actions/cache@v3
with:
path: packages/utils/cache/
key: cache-${{ github.run_id }}
restore-keys: cache-
- name: Calculate versions
run: yarn workspace @definitelytyped/publisher calculate-versions
- name: Generate packages
run: yarn workspace @definitelytyped/publisher generate
- name: Publish packages${{ (inputs || github.event.inputs).dry && ' dry run' || '' }}
run: yarn workspace @definitelytyped/publisher publish-packages${{ (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/
40 changes: 40 additions & 0 deletions .github/workflows/publish-registry.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Publish registry
on:
workflow_call:
inputs:
dry:
description: Dry run
type: boolean
workflow_dispatch:
inputs:
dry:
description: Dry run
type: boolean
jobs:
publish-registry:
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
- uses: actions/cache@v3
with:
path: packages/utils/cache/
key: cache-${{ github.run_id }}
restore-keys: cache-
- name: Calculate versions
run: yarn workspace @definitelytyped/publisher calculate-versions
- name: Publish registry${{ (inputs || github.event.inputs).dry && ' dry run' || '' }}
run: yarn workspace @definitelytyped/publisher publish-registry${{ (inputs || github.event.inputs).dry && ' --dry' || '' }}
env:
NPM_TOKEN: ${{ secrets.NPM_RETAG_TOKEN }}
- if: always()
uses: actions/upload-artifact@v3
with:
name: ${{ github.job }}
path: packages/definitions-parser/data/
40 changes: 40 additions & 0 deletions .github/workflows/retag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Update npm tags
on:
schedule:
# https://crontab.guru/#0_0_*_*_0
- cron: 0 0 * * 0
workflow_call:
inputs:
dry:
description: Dry run
type: boolean
workflow_dispatch:
inputs:
dry:
description: Dry run
type: boolean
jobs:
retag:
if: github.event_name != 'schedule' || github.repository == 'microsoft/DefinitelyTyped-tools'
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
- uses: actions/cache@v3
with:
path: packages/utils/cache/
key: cache-${{ github.run_id }}
restore-keys: cache-
- name: Update npm tags${{ (inputs || github.event.inputs).dry && ' dry run' || '' }}
run: yarn retag${{ (inputs || github.event.inputs).dry && ' --dry' || '' }}
env:
NPM_TOKEN: ${{ secrets.NPM_RETAG_TOKEN }}
- if: always()
uses: actions/upload-artifact@v3
with:
name: ${{ github.job }}
path: packages/definitions-parser/data/
35 changes: 0 additions & 35 deletions .github/workflows/update-ts-version-tags.yml

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"format": "prettier --write 'packages/**/*.ts'",
"test": "jest",
"build": "tsc -b .",
"retag": "node packages/retag/dist/retag.js"
"retag": "node --require source-map-support/register packages/retag/"
},
"devDependencies": {
"@types/jest": "^25.1.3",
Expand Down
10 changes: 8 additions & 2 deletions packages/publisher/src/calculate-versions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { defaultLocalOptions } from "./lib/common";
import process from "process";
import { defaultLocalOptions, defaultRemoteOptions } from "./lib/common";
import { ChangedPackages, ChangedPackagesJson, ChangedTypingJson, versionsFilename } from "./lib/versions";
import { getDefinitelyTyped, AllPackages, NotNeededPackage, writeDataFile } from "@definitelytyped/definitions-parser";
import { logUncaughtErrors, loggerWithErrors, FS, LoggerWithErrors, defaultCacheDir } from "@definitelytyped/utils";
Expand All @@ -7,7 +8,12 @@ import * as pacote from "pacote";

if (!module.parent) {
const log = loggerWithErrors()[0];
logUncaughtErrors(async () => calculateVersions(await getDefinitelyTyped(defaultLocalOptions, log), log));
logUncaughtErrors(async () =>
calculateVersions(
await getDefinitelyTyped(process.env.GITHUB_ACTIONS ? defaultRemoteOptions : defaultLocalOptions, log),
log
)
);
}

export default async function calculateVersions(dt: FS, log: LoggerWithErrors): Promise<ChangedPackages> {
Expand Down
5 changes: 3 additions & 2 deletions packages/publisher/src/generate-packages.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { makeTypesVersionsForPackageJson } from "@definitelytyped/header-parser";
import { emptyDir, mkdir, mkdirp, readFileSync } from "fs-extra";
import path = require("path");
import process from "process";
import yargs = require("yargs");

import { defaultLocalOptions } from "./lib/common";
import { defaultLocalOptions, defaultRemoteOptions } from "./lib/common";
import { outputDirPath, sourceBranch } from "./lib/settings";
import {
assertNever,
Expand Down Expand Up @@ -42,7 +43,7 @@ if (!module.parent) {
const tgz = !!yargs.argv.tgz;
logUncaughtErrors(async () => {
const log = loggerWithErrors()[0];
const dt = await getDefinitelyTyped(defaultLocalOptions, log);
const dt = await getDefinitelyTyped(process.env.GITHUB_ACTIONS ? defaultRemoteOptions : defaultLocalOptions, log);
const allPackages = await AllPackages.read(dt);
await generatePackages(dt, allPackages, await readChangedPackages(allPackages), tgz);
});
Expand Down
5 changes: 3 additions & 2 deletions packages/publisher/src/parse-definitions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import os from "os";
import process from "process";
import yargs from "yargs";
import { logUncaughtErrors, loggerWithErrors, assertDefined, FS } from "@definitelytyped/utils";
import { defaultLocalOptions } from "./lib/common";
import { defaultLocalOptions, defaultRemoteOptions } from "./lib/common";
import { getTypingInfo } from "@definitelytyped/definitions-parser/dist/lib/definition-parser";
import {
getDefinitelyTyped,
Expand All @@ -16,7 +17,7 @@ if (!module.parent) {
nProcesses: { type: "number" },
}).argv;

const options = defaultLocalOptions;
const options = process.env.GITHUB_ACTIONS ? defaultRemoteOptions : defaultLocalOptions;
logUncaughtErrors(async () => {
const log = loggerWithErrors()[0];
const dt = await getDefinitelyTyped(options, log);
Expand Down
10 changes: 7 additions & 3 deletions packages/publisher/src/publish-packages.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import process from "process";
import applicationinsights = require("applicationinsights");
import * as yargs from "yargs";

import { defaultLocalOptions } from "./lib/common";
import { defaultLocalOptions, defaultRemoteOptions } from "./lib/common";
import { deprecateNotNeededPackage, publishNotNeededPackage, publishTypingsPackage } from "./lib/package-publisher";
import { getDefinitelyTyped, AllPackages } from "@definitelytyped/definitions-parser";
import {
Expand All @@ -20,7 +21,10 @@ if (!module.parent) {
const dry = !!yargs.argv.dry;
const deprecateName = yargs.argv.deprecate as string | undefined;
logUncaughtErrors(async () => {
const dt = await getDefinitelyTyped(defaultLocalOptions, loggerWithErrors()[0]);
const dt = await getDefinitelyTyped(
process.env.GITHUB_ACTIONS ? defaultRemoteOptions : defaultLocalOptions,
loggerWithErrors()[0]
);
if (deprecateName !== undefined) {
// A '--deprecate' command is available in case types-publisher got stuck *while* trying to deprecate a package.
// Normally this should not be needed.
Expand Down Expand Up @@ -56,7 +60,7 @@ export default async function publishPackages(
log("=== Publishing packages ===");
}

const client = await NpmPublishClient.create(await getSecret(Secret.NPM_TOKEN), undefined);
const client = await NpmPublishClient.create(dry ? "" : await getSecret(Secret.NPM_TOKEN), undefined);

for (const cp of changedPackages.changedTypings) {
log(`Publishing ${cp.pkg.desc}...`);
Expand Down
10 changes: 7 additions & 3 deletions packages/publisher/src/publish-registry.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import assert = require("assert");
import process from "process";
import { emptyDir } from "fs-extra";
import * as yargs from "yargs";

import { defaultLocalOptions } from "./lib/common";
import { defaultLocalOptions, defaultRemoteOptions } from "./lib/common";
import { outputDirPath, validateOutputPath } from "./lib/settings";
import {
getDefinitelyTyped,
Expand Down Expand Up @@ -44,7 +45,10 @@ Generated by [types-publisher](${pkg.homepage}).`;
if (!module.parent) {
const dry = !!yargs.argv.dry;
logUncaughtErrors(async () => {
const dt = await getDefinitelyTyped(defaultLocalOptions, loggerWithErrors()[0]);
const dt = await getDefinitelyTyped(
process.env.GITHUB_ACTIONS ? defaultRemoteOptions : defaultLocalOptions,
loggerWithErrors()[0]
);
await publishRegistry(dt, await AllPackages.read(dt), dry);
});
}
Expand Down Expand Up @@ -72,7 +76,7 @@ export default async function publishRegistry(dt: FS, allPackages: AllPackages,
const packageJson = generatePackageJson(typesRegistry, newVersion, newContentHash);
await generate(registry, packageJson);

const token = await getSecret(Secret.NPM_TOKEN);
const token = dry ? "" : await getSecret(Secret.NPM_TOKEN);

const publishClient = () => NpmPublishClient.create(token, { defaultTag: "next" });
if (highestSemverVersion !== npmVersion) {
Expand Down
3 changes: 0 additions & 3 deletions packages/retag/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
"@types/yargs": "^15.0.5"
},
"main": "dist/index.js",
"bin": {
"retag": "./dist/retag.js"
},
"publishConfig": {
"access": "public"
}
Expand Down
8 changes: 6 additions & 2 deletions packages/retag/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,14 @@ async function main() {
*/
async function tag(dry: boolean, nProcesses: number, name?: string) {
const log = loggerWithErrors()[0];
const options = { definitelyTypedPath: "../DefinitelyTyped", progress: true, parseInParallel: true };
const options = process.env.GITHUB_ACTIONS
? { definitelyTypedPath: undefined, progress: false, parseInParallel: false }
: { definitelyTypedPath: "../DefinitelyTyped", progress: true, parseInParallel: true };
await parseDefinitions(
await getDefinitelyTyped(options, log),
{ nProcesses: nProcesses || os.cpus().length, definitelyTypedPath: "../DefinitelyTyped" },
options.parseInParallel
? { nProcesses: nProcesses || os.cpus().length, definitelyTypedPath: "../DefinitelyTyped" }
: undefined,
log
);

Expand Down

0 comments on commit bf27c30

Please sign in to comment.