Skip to content

Commit

Permalink
Validate typescript eng scripts & use patterns for pr label triage (#…
Browse files Browse the repository at this point in the history
…3381)

`includesModifedFiles` doesn't seem to be working with path so trying to
use the regex pattern
  • Loading branch information
timotheeguerin authored May 17, 2024
1 parent 7223624 commit 940015c
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 76 deletions.
94 changes: 35 additions & 59 deletions .github/policies/prs.triage.generated.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,126 +7,102 @@ disabled: false
configuration:
resourceManagementConfiguration:
eventResponderTasks:
- description: Assign area labels to PRs based on modified files
if:
- if:
- payloadType: Pull_Request
- isOpen
then:
- if:
- includesModifiedFiles:
files:
- packages/compiler/
- filesMatchPattern:
pattern: packages/compiler/.*
then:
- addLabel:
label: compiler:core
- if:
- includesModifiedFiles:
files: []
- filesMatchPattern:
pattern: packages/typespec-vscode/.*
then:
- addLabel:
label: compiler:emitter-framework
label: ide
- if:
- includesModifiedFiles:
files:
- packages/typespec-vscode
- packages/typespec-vs/
- filesMatchPattern:
pattern: packages/typespec-vs/.*
then:
- addLabel:
label: ide
- if:
- includesModifiedFiles:
files:
- packages/http/
- filesMatchPattern:
pattern: packages/http/.*
then:
- addLabel:
label: lib:http
- if:
- includesModifiedFiles:
files:
- packages/openapi/
- filesMatchPattern:
pattern: packages/openapi/.*
then:
- addLabel:
label: lib:openapi
- if:
- includesModifiedFiles:
files:
- packages/rest/
- filesMatchPattern:
pattern: packages/rest/.*
then:
- addLabel:
label: lib:rest
- if:
- includesModifiedFiles:
files:
- packages/versioning/
- filesMatchPattern:
pattern: packages/versioning/.*
then:
- addLabel:
label: lib:versioning
- if:
- includesModifiedFiles:
files:
- blog/
- filesMatchPattern:
pattern: blog/.*
then:
- addLabel:
label: meta:blog
- if:
- includesModifiedFiles:
files:
- website/
- filesMatchPattern:
pattern: website/.*
then:
- addLabel:
label: meta:website
- if:
- includesModifiedFiles:
files:
- packages/tspd/
- filesMatchPattern:
pattern: packages/tspd/.*
then:
- addLabel:
label: tspd
- if:
- includesModifiedFiles:
files:
- packages/http-client-csharp/
- filesMatchPattern:
pattern: packages/http-client-csharp/.*
then:
- addLabel:
label: emitter:client:csharp
- if:
- includesModifiedFiles:
files:
- packages/json-schema/
- filesMatchPattern:
pattern: packages/json-schema/.*
then:
- addLabel:
label: emitter:json-schema
- if:
- includesModifiedFiles:
files:
- packages/protobuf/
- filesMatchPattern:
pattern: packages/protobuf/.*
then:
- addLabel:
label: emitter:protobuf
- if:
- includesModifiedFiles:
files:
- packages/openapi3/
- filesMatchPattern:
pattern: packages/openapi3/.*
then:
- addLabel:
label: emitter:openapi3
- if:
- includesModifiedFiles:
files: []
- filesMatchPattern:
pattern: eng/.*
then:
- addLabel:
label: emitter:service:csharp
- if:
- includesModifiedFiles:
files: []
then:
- addLabel:
label: emitter:service:js
label: eng
- if:
- includesModifiedFiles:
files:
- eng/
- .github/
- filesMatchPattern:
pattern: .github/.*
then:
- addLabel:
label: eng
2 changes: 1 addition & 1 deletion eng/common/config/areas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { type AreaLabels } from "./labels.js";
export const AreaPaths: Record<keyof typeof AreaLabels, string[]> = {
"compiler:core": ["packages/compiler/"],
"compiler:emitter-framework": [],
ide: ["packages/typespec-vscode", "packages/typespec-vs/"],
ide: ["packages/typespec-vscode/", "packages/typespec-vs/"],
"lib:http": ["packages/http/"],
"lib:openapi": ["packages/openapi/"],
"lib:rest": ["packages/rest/"],
Expand Down
27 changes: 14 additions & 13 deletions eng/common/scripts/labels/automation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
PolicyServiceConfig,
and,
eventResponderTask,
filesMatchPattern,
hasLabel,
includesModifiedFiles,
isAction,
labelAdded,
labelRemoved,
Expand Down Expand Up @@ -101,19 +101,20 @@ const prTriageConfig: PolicyServiceConfig = {
resourceManagementConfiguration: {
eventResponderTasks: [
eventResponderTask({
description: "Assign area labels to PRs based on modified files",
if: [payloadType("Pull_Request"), "isOpen"],
then: Object.entries(AreaPaths).map(([label, files]) => {
return {
if: [includesModifiedFiles(files)],
then: [
{
addLabel: {
label,
if: [payloadType("Pull_Request")],
then: Object.entries(AreaPaths).flatMap(([label, files]) => {
return files.map((file) => {
return {
if: [filesMatchPattern(`${file}.*`)],
then: [
{
addLabel: {
label,
},
},
},
],
};
],
};
});
}),
}),
],
Expand Down
18 changes: 17 additions & 1 deletion eng/common/scripts/labels/policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ export type Not = {
export type IncludesModifiedFiles = {
includesModifiedFiles: { files: string[] };
};
export type FilesMatchPattern = {
filesMatchPattern: { pattern: string };
};

export type Condition =
| PayloadType
Expand Down Expand Up @@ -106,12 +109,25 @@ export function labelRemoved(label: string): LabelRemoved {
};
}

/**
* Exact path to files that should be modified.
* DOES NOT support glob patterns or paths.
*/
export function includesModifiedFiles(files: string[]): IncludesModifiedFiles {
return {
includesModifiedFiles: { files },
};
}

/**
* Check if the pattern of files modified match the given regex(s).
*/
export function filesMatchPattern(pattern: string): FilesMatchPattern {
return {
filesMatchPattern: { pattern },
};
}

export function hasLabel(label: string): HasLabel {
return {
hasLabel: { label },
Expand All @@ -129,7 +145,7 @@ export function and(conditions: Condition[]): And {
}

export type EventResponderTask = {
description: string;
description?: string;
if: Condition[];
then: any;
};
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
"packageManager": "[email protected]",
"type": "module",
"scripts": {
"build": "pnpm build:all && pnpm gen-compiler-extern-signature",
"build:all": "pnpm -r --workspace-concurrency=Infinity --aggregate-output --reporter=append-only build && pnpm gen-compiler-extern-signature",
"build": "pnpm build:all && pnpm check:eng && pnpm gen-compiler-extern-signature",
"build:all": "pnpm -r --workspace-concurrency=Infinity --aggregate-output --reporter=append-only build",
"check:eng": "tsc -p ./tsconfig.eng.json --noEmit",
"setup:min": "pnpm install && pnpm --filter \"@typespec/prettier-plugin-typespec...\" run build",
"check-version-mismatch": "syncpack list-mismatches",
"change": "chronus",
Expand Down
4 changes: 4 additions & 0 deletions tsconfig.eng.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "./tsconfig.base.json",
"include": ["eng"]
}

0 comments on commit 940015c

Please sign in to comment.