Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 3 additions & 21 deletions pr-checks/changelog/validate.test.mts
Original file line number Diff line number Diff line change
@@ -1,34 +1,16 @@
import assert from "node:assert/strict";
import * as fs from "node:fs";
import * as os from "node:os";
import * as path from "node:path";
import { describe, it } from "node:test";

import { withTmpFile } from "../../src/util.js";
Comment thread
mario-campos marked this conversation as resolved.
Outdated

import {
hasValidChangenoteCategory,
isValidChangenoteContent,
isValidChangenoteFile,
isValidChangenoteFilename,
hasValidChangenoteCategory,
VALID_CHANGE_NOTE_CATEGORIES,
} from "./validate.mjs";

async function withTmpFile<T>(
baseFileName: string,
contents: string,
body: (filePath: string) => Promise<T> | T,
): Promise<T> {
const tmpDir = fs.mkdtempSync(
path.join(os.tmpdir(), "changetool-validate-test-"),
);
try {
const filePath = path.join(tmpDir, baseFileName);
fs.writeFileSync(filePath, contents);
return await body(filePath);
} finally {
fs.rmSync(tmpDir, { recursive: true, force: true });
}
}

await describe("isValidChangenoteContent", async () => {
await it("recognizes an unordered Markdown list", () => {
const inputs = [
Expand Down
11 changes: 9 additions & 2 deletions pr-checks/sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@ set -e
cd "$(dirname "$0")"

# Run `npm ci` in CI or `npm install` otherwise.
#
# `pr-checks` is an npm workspace of the repository root and the two share a single hoisted
# `node_modules` directory. Running npm from this directory puts it in workspace mode, where it
# ignores the root project's own dependencies by default. `npm ci` would then rebuild the shared
# `node_modules` with only this workspace's dependencies, removing the root's ones, which breaks
# anything that imports from `src` (such as `sync.ts` itself). `--include-workspace-root` keeps the
# root project's dependencies in the installed tree.
Comment thread
mario-campos marked this conversation as resolved.
if [ "$GITHUB_ACTIONS" = "true" ]; then
echo "In Actions, running 'npm ci' for 'sync.ts'..."
npm ci
npm ci --include-workspace-root
else
echo "Running 'npm install' for 'sync.ts'..."
npm install --no-audit --no-fund
npm install --no-audit --no-fund --include-workspace-root
fi

npx tsx sync.ts
13 changes: 13 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,19 @@ export async function withTmpDir<T>(
return result;
}

// Creates a random temporary file, runs the given body, and then deletes the file.
Comment thread
mario-campos marked this conversation as resolved.
Outdated
export async function withTmpFile<T>(
Comment thread
mario-campos marked this conversation as resolved.
baseFileName: string,
contents: string,
body: (filePath: string) => Promise<T> | T,
): Promise<T> {
return withTmpDir(async (tmpDir) => {
Comment thread
mario-campos marked this conversation as resolved.
Comment thread
mario-campos marked this conversation as resolved.
const filePath = path.join(tmpDir, baseFileName);
fs.writeFileSync(filePath, contents);
return body(filePath);
});
}

/**
* Gets an OS-specific amount of memory (in MB) to reserve for OS processes
* when the user doesn't explicitly specify a memory setting.
Expand Down
Loading