Skip to content

Commit 8e67d84

Browse files
authored
Merge branch 'main' into mysql-version-uniform
2 parents 1e112b7 + d87c0a3 commit 8e67d84

File tree

873 files changed

+141297
-81461
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

873 files changed

+141297
-81461
lines changed

.github/shared/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
"./array": "./src/array.js",
77
"./changed-files": "./src/changed-files.js",
88
"./equality": "./src/equality.js",
9+
"./error-reporting": "./src/error-reporting.js",
910
"./exec": "./src/exec.js",
1011
"./logger": "./src/logger.js",
12+
"./path": "./src/path.js",
1113
"./readme": "./src/readme.js",
1214
"./sdk-types": "./src/sdk-types.js",
1315
"./sleep": "./src/sleep.js",

.github/shared/src/error-reporting.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// @ts-check
2+
import * as fs from "fs";
3+
4+
/**
5+
* Set the summary of the github step summary for a job. This feature is intended for formatted markdown,
6+
* which can be used to display the results of a job in a more readable format.
7+
*
8+
* Format your results as a markdown table and go to town!
9+
* @param {string} content
10+
* @returns {void}
11+
*/
12+
export function setSummary(content) {
13+
if (!process.env.GITHUB_STEP_SUMMARY) {
14+
console.log("GITHUB_STEP_SUMMARY is not set. Skipping summary update.");
15+
return;
16+
}
17+
const summaryFile = process.env.GITHUB_STEP_SUMMARY;
18+
19+
fs.writeFileSync(summaryFile, content);
20+
}
21+
22+
/**
23+
* This function is used to ask the github agent to annotate a file in a github PR with an error message.
24+
* @param {string} repoPath
25+
* @param {string} message
26+
* @param {number} line
27+
* @param {number} col
28+
* @returns {void}
29+
*/
30+
export function annotateFileError(repoPath, message, line, col) {
31+
const errorLine = `::error file=${repoPath},line=${line},col=${col}::${message}`;
32+
console.log(errorLine);
33+
}

.github/shared/src/path.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// @ts-check
2+
3+
import { resolve, sep } from "path";
4+
5+
/**
6+
*
7+
* @param {string} path
8+
* @param {string} folder
9+
* @returns {boolean} True if path contains the named folder
10+
*/
11+
export function includesFolder(path, folder) {
12+
return resolve(path).includes(sep + folder + sep);
13+
}

.github/shared/src/swagger.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import $RefParser, { ResolverError } from "@apidevtools/json-schema-ref-parser";
44
import { readFile } from "fs/promises";
55
import { dirname, relative, resolve } from "path";
66
import { mapAsync } from "./array.js";
7+
import { includesFolder } from "./path.js";
78
import { SpecModelError } from "./spec-model-error.js";
89

910
/**
@@ -58,6 +59,15 @@ export class Swagger {
5859
* @returns {Promise<Map<string, Swagger>>}
5960
*/
6061
async getRefs() {
62+
const allRefs = await this.#getRefs();
63+
64+
// filter out any paths that are examples
65+
const filtered = new Map([...allRefs].filter(([path]) => !example(path)));
66+
67+
return filtered;
68+
}
69+
70+
async #getRefs() {
6171
if (!this.#refs) {
6272
let schema;
6373
try {
@@ -82,8 +92,6 @@ export class Swagger {
8292

8393
const refPaths = schema
8494
.paths("file")
85-
// Exclude examples
86-
.filter((p) => !example(p))
8795
// Exclude ourself
8896
.filter((p) => resolve(p) !== resolve(this.#path));
8997

@@ -101,6 +109,18 @@ export class Swagger {
101109
return this.#refs;
102110
}
103111

112+
/**
113+
* @returns {Promise<Map<string, Swagger>>}
114+
*/
115+
async getExamples() {
116+
const allRefs = await this.#getRefs();
117+
118+
// filter out any paths that are examples
119+
const filtered = new Map([...allRefs].filter(([path]) => example(path)));
120+
121+
return filtered;
122+
}
123+
104124
/**
105125
* @returns {string} absolute path
106126
*/
@@ -151,7 +171,9 @@ export class Swagger {
151171
*/
152172
function example(file) {
153173
// Folder name "examples" should match case for consistency across specs
154-
return typeof file === "string" && json(file) && file.includes("/examples/");
174+
return (
175+
typeof file === "string" && json(file) && includesFolder(file, "examples")
176+
);
155177
}
156178

157179
/**
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// @ts-check
2+
3+
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
4+
import { setSummary, annotateFileError } from "../src/error-reporting.js";
5+
import fs from "fs/promises";
6+
7+
describe("ErrorReporting", () => {
8+
let logSpy;
9+
10+
beforeEach(() => {
11+
logSpy = vi.spyOn(console, "log").mockImplementation(() => {});
12+
// ensure that on test runs GITHUB_STEP_SUMMARY is not set in my current env by default
13+
// this gives us a clean slate for each test
14+
delete process.env.GITHUB_STEP_SUMMARY;
15+
});
16+
17+
afterEach(() => {
18+
logSpy.mockRestore();
19+
});
20+
21+
it("should warn when GITHUB_STEP_SUMMARY is unset", () => {
22+
setSummary("hello");
23+
expect(logSpy).toHaveBeenCalledWith(
24+
"GITHUB_STEP_SUMMARY is not set. Skipping summary update.",
25+
);
26+
});
27+
28+
it("should write to the summary file when GITHUB_STEP_SUMMARY is set", async () => {
29+
process.env.GITHUB_STEP_SUMMARY = `${__dirname}/tmp-summary.md`;
30+
31+
await fs.rm(process.env.GITHUB_STEP_SUMMARY, { force: true });
32+
33+
setSummary("# Title");
34+
35+
expect(logSpy).not.toHaveBeenCalledWith(
36+
"GITHUB_STEP_SUMMARY is not set. Skipping summary update.",
37+
);
38+
39+
const content = await fs.readFile(process.env.GITHUB_STEP_SUMMARY, "utf-8");
40+
41+
// cleanup after the test so nothing is left behi
42+
await fs.rm(process.env.GITHUB_STEP_SUMMARY, { force: true });
43+
44+
expect(content).toBe("# Title");
45+
});
46+
47+
it("should emit a GitHub-style error annotation", () => {
48+
annotateFileError("src/foo.js", "Something broke", 42, 7);
49+
expect(logSpy).toHaveBeenCalledWith(
50+
"::error file=src/foo.js,line=42,col=7::Something broke",
51+
);
52+
});
53+
});
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: OAV Runner - Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
paths:
9+
- package-lock.json
10+
- package.json
11+
- tsconfig.json
12+
- .github/shared
13+
- .github/workflows/_reusable-eng-tools-test.yaml
14+
- .github/workflows/oav-runner-test.yaml
15+
- eng/tools/package.json
16+
- eng/tools/tsconfig.json
17+
- eng/tools/oav-runner/**
18+
workflow_dispatch:
19+
20+
permissions:
21+
contents: read
22+
23+
jobs:
24+
oavrunnertests:
25+
name: Check OAV Runner
26+
uses: ./.github/workflows/_reusable-eng-tools-test.yaml
27+
with:
28+
package: oav-runner
29+
lint: false
30+
prettier: false
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: "[TEST-IGNORE] Swagger ModelValidation"
2+
3+
on: pull_request
4+
5+
permissions:
6+
contents: read
7+
8+
jobs:
9+
oav:
10+
name: "[TEST-IGNORE] Swagger ModelValidation"
11+
runs-on: ubuntu-24.04
12+
13+
steps:
14+
- name: Checkout repo
15+
uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 2
18+
19+
- name: Setup Node and install deps
20+
uses: ./.github/actions/setup-node-install-deps
21+
22+
- name: Swagger Model Validation
23+
run: |
24+
npm exec --no -- oav-runner examples
25+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: "[TEST-IGNORE] Swagger ModelValidation - Set Status"
2+
3+
on:
4+
# Must run on pull_request_target instead of pull_request, since the latter cannot trigger on
5+
# labels from bot accounts in fork PRs. pull_request_target is also more similar to the other
6+
# trigger "workflow_run" -- they are both privileged and run in the target branch and repo --
7+
# which simplifies implementation.
8+
pull_request_target:
9+
types:
10+
# Run workflow on default types, to update status as quickly as possible.
11+
- opened
12+
- synchronize
13+
- reopened
14+
# Depends on labels, so must re-evaluate whenever a relevant label is manually added or removed.
15+
- labeled
16+
- unlabeled
17+
workflow_run:
18+
workflows: ["\\[TEST-IGNORE\\] Swagger ModelValidation"]
19+
types: [completed]
20+
21+
permissions:
22+
actions: read
23+
contents: read
24+
issues: read
25+
pull-requests: read
26+
statuses: write
27+
28+
jobs:
29+
model-validation-status:
30+
name: Set ModelValidation Status
31+
uses: ./.github/workflows/_reusable-set-check-status.yml
32+
with:
33+
monitored_workflow_name: "[TEST-IGNORE] Swagger ModelValidation"
34+
required_check_name: "[TEST-IGNORE] Swagger ModelValidation"
35+
overriding_label: "Approved-ModelValidation"
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: "[TEST-IGNORE] Swagger SemanticValidation"
2+
3+
on: pull_request
4+
5+
permissions:
6+
contents: read
7+
8+
jobs:
9+
oav:
10+
name: "[TEST-IGNORE] Swagger SemanticValidation"
11+
runs-on: ubuntu-24.04
12+
13+
steps:
14+
- name: Checkout repo
15+
uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 2
18+
19+
- name: Setup Node and install deps
20+
uses: ./.github/actions/setup-node-install-deps
21+
22+
- name: Swagger Semantic Validation
23+
run: |
24+
npm exec --no -- oav-runner specs
25+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: "[TEST-IGNORE] Swagger ModelValidation - Set Status"
2+
3+
on:
4+
# Must run on pull_request_target instead of pull_request, since the latter cannot trigger on
5+
# labels from bot accounts in fork PRs. pull_request_target is also more similar to the other
6+
# trigger "workflow_run" -- they are both privileged and run in the target branch and repo --
7+
# which simplifies implementation.
8+
pull_request_target:
9+
types:
10+
# Run workflow on default types, to update status as quickly as possible.
11+
- opened
12+
- synchronize
13+
- reopened
14+
# Depends on labels, so must re-evaluate whenever a relevant label is manually added or removed.
15+
- labeled
16+
- unlabeled
17+
workflow_run:
18+
workflows: ["\\[TEST-IGNORE\\] Swagger SemanticValidation"]
19+
types: [completed]
20+
21+
permissions:
22+
actions: read
23+
contents: read
24+
issues: read
25+
pull-requests: read
26+
statuses: write
27+
28+
jobs:
29+
spec-validation-status:
30+
name: Set SemanticValidation Status
31+
uses: ./.github/workflows/_reusable-set-check-status.yml
32+
with:
33+
monitored_workflow_name: "[TEST-IGNORE] Swagger SemanticValidation"
34+
required_check_name: "[TEST-IGNORE] Swagger SemanticValidation"
35+
overriding_label: "Approved-SemanticValidation"

.vscode/launch.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@
44
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
55
"version": "0.2.0",
66
"configurations": [
7+
{
8+
"name": "Split Deployments",
9+
"type": "node",
10+
"request": "launch",
11+
"runtimeExecutable": "npm",
12+
"args": [
13+
"start"
14+
],
15+
"cwd": "${workspaceFolder}/dev/deployments/convert"
16+
},
717
{
818
"type": "node",
919
"request": "launch",

dev/deployments/convert/.tsconfig

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"compilerOptions": {
3+
"skipLibCheck": true,
4+
"module": "commonjs",
5+
"noEmitOnError": true,
6+
"noImplicitReturns": true,
7+
"sourceMap": true,
8+
"declarationMap": true,
9+
"strict": true,
10+
"declaration": true,
11+
"stripInternal": true,
12+
"noEmitHelpers": false,
13+
"target": "es2019",
14+
"types": ["node"],
15+
"esModuleInterop": true,
16+
"lib": ["es2020"],
17+
"newLine": "LF",
18+
"outDir": "dist",
19+
"rootDir": "."
20+
},
21+
"exclude": ["dist", "node_modules"]
22+
}

0 commit comments

Comments
 (0)