From 8a4d8901cae41a75cab22d226f71c47ddc3a279d Mon Sep 17 00:00:00 2001 From: Sander Verweij Date: Wed, 13 Dec 2023 13:49:13 +0100 Subject: [PATCH] feat(labeler.yml)!: changes --emitLabeler to emit labeler@v5 format labeler.yml - BREAKING (#163) ## Description - changes the --emitLabeler output so it supports the labeler v5 format ## Motivation and Context actions/labeler [changed their configuration format in a breaking fashion](https://github.com/actions/labeler/issues/712) ## How Has This Been Tested? - [x] green ci - [x] updated non-regression tests - [x] generating a labeler.yml and running it against the new version of actions/labeler - see [action run 7194463872](https://github.com/sverweij/virtual-code-owners/actions/runs/7194463872/job/19595044485?pr=163) ## Types of changes - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] Documentation only change - [ ] Refactor (non-breaking change which fixes an issue without changing functionality) - [x] New feature (non-breaking change which adds functionality) - [x] Breaking change (fix or feature that would cause existing functionality to change) --- .github/labeler.yml | 20 +++++++++++------ .github/workflows/labeler.yml | 2 +- README.md | 9 ++++++++ dist/labeler-yml/generate.js | 9 ++++++-- src/labeler-yml/__fixtures__/labeler.yml | 28 ++++++++++++++---------- src/labeler-yml/generate.test.ts | 12 ++++++---- src/labeler-yml/generate.ts | 9 ++++++-- 7 files changed, 62 insertions(+), 27 deletions(-) diff --git a/.github/labeler.yml b/.github/labeler.yml index d12e1e8..cf0e584 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -9,18 +9,24 @@ # vco: - - "**" - - README.md + - changed-files: + - any-glob-to-any-file: "**" + - any-glob-to-any-file: README.md vco-admins: - - .github/** - - tools/** + - changed-files: + - any-glob-to-any-file: .github/** + - any-glob-to-any-file: tools/** tools: - - tools/** + - changed-files: + - any-glob-to-any-file: tools/** admin: - - .github/** + - changed-files: + - any-glob-to-any-file: .github/** documentation: - - README.md + - changed-files: + - any-glob-to-any-file: README.md + diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml index c260bbe..e3417cd 100644 --- a/.github/workflows/labeler.yml +++ b/.github/workflows/labeler.yml @@ -10,7 +10,7 @@ jobs: pull-requests: write runs-on: ubuntu-latest steps: - - uses: actions/labeler@v4 + - uses: actions/labeler@v5 with: sync-labels: true dot: true diff --git a/README.md b/README.md index 9fcc07d..e11f3fc 100644 --- a/README.md +++ b/README.md @@ -202,6 +202,15 @@ npx virtual-code-owners --emitLabeler If you have an alternate file location for the `labeler.yml` you can specify that with virtual-code-owner's `--labelerLocation` parameter. +> [!NOTE] +> actions/labeler changed the labeler.yml format from v4 to v5. +> +> - virtual-code-owners < 8.0.0 generates labeler.yml v4 format, +> - virtual-code-owners >= 8.0.0 generates labeler.yml v5 format. +> +> see [actions/labeler#v5](https://github.com/actions/labeler/blob/8558fd74291d67161a8a78ce36a881fa63b766a9/README.md) +> for details on the v5 format. + ### What validations does virtual-code-owners perform? virtual-code-owners checks for basic CODEOWNERS format errors and invalid diff --git a/dist/labeler-yml/generate.js b/dist/labeler-yml/generate.js index 52a6639..a1e46d2 100644 --- a/dist/labeler-yml/generate.js +++ b/dist/labeler-yml/generate.js @@ -17,10 +17,15 @@ export default function generateLabelerYml( let lReturnValue = pGeneratedWarning; for (const lTeamName in pTeamMap) { const lPatternsForTeam = getPatternsForTeam(pCodeOwners, lTeamName) - .map((pPattern) => ` - ${transformForYamlAndMinimatch(pPattern)}${EOL}`) + .map( + (pPattern) => + ` - any-glob-to-any-file: ${transformForYamlAndMinimatch( + pPattern, + )}${EOL}`, + ) .join(""); if (lPatternsForTeam) { - lReturnValue += `${lTeamName}:${EOL}${lPatternsForTeam}${EOL}`; + lReturnValue += `${lTeamName}:${EOL} - changed-files:${EOL}${lPatternsForTeam}${EOL}`; } } return lReturnValue; diff --git a/src/labeler-yml/__fixtures__/labeler.yml b/src/labeler-yml/__fixtures__/labeler.yml index 8dd9d39..4c1120a 100644 --- a/src/labeler-yml/__fixtures__/labeler.yml +++ b/src/labeler-yml/__fixtures__/labeler.yml @@ -1,22 +1,28 @@ ch/after-sales: - - libs/ubc-after-sales/** - - libs/ubc-refund/** + - changed-files: + - any-glob-to-any-file: libs/ubc-after-sales/** + - any-glob-to-any-file: libs/ubc-refund/** ch/sales: - - libs/ubc-sales/** - - libs/ubc-refund/** + - changed-files: + - any-glob-to-any-file: libs/ubc-sales/** + - any-glob-to-any-file: libs/ubc-refund/** ch/pre-sales: - - libs/ubc-pre-sales/** + - changed-files: + - any-glob-to-any-file: libs/ubc-pre-sales/** ch/ux: - - apps/ux-portal/** - - libs/components/** + - changed-files: + - any-glob-to-any-file: apps/ux-portal/** + - any-glob-to-any-file: libs/components/** ch/transversal: - - .github/** - - apps/framework/** - - apps/ux-portal/** + - changed-files: + - any-glob-to-any-file: .github/** + - any-glob-to-any-file: apps/framework/** + - any-glob-to-any-file: apps/ux-portal/** ch/mannen-met-baarden: - - libs/ubc-baarden/** + - changed-files: + - any-glob-to-any-file: libs/ubc-baarden/** diff --git a/src/labeler-yml/generate.test.ts b/src/labeler-yml/generate.test.ts index 2b62518..cde902a 100644 --- a/src/labeler-yml/generate.test.ts +++ b/src/labeler-yml/generate.test.ts @@ -82,7 +82,8 @@ describe("generate-labeler-yml generates a labeler.yml", () => { }, ]; const lExpected = `the-a-team: - - knakkerdeknak/** + - changed-files: + - any-glob-to-any-file: knakkerdeknak/** `; equal(generateLabelerYml(lVirtualCodeOwners, TEAMS, ""), lExpected); @@ -108,7 +109,8 @@ describe("generate-labeler-yml generates a labeler.yml", () => { }, ]; const lExpected = `baarden: - - "**" + - changed-files: + - any-glob-to-any-file: "**" `; equal(generateLabelerYml(lVirtualCodeOwners, TEAMS, ""), lExpected); @@ -134,7 +136,8 @@ describe("generate-labeler-yml generates a labeler.yml", () => { }, ]; const lExpected = `baarden: - - "*/src/vlaai/*" + - changed-files: + - any-glob-to-any-file: "*/src/vlaai/*" `; equal(generateLabelerYml(lVirtualCodeOwners, TEAMS, ""), lExpected); @@ -160,7 +163,8 @@ describe("generate-labeler-yml generates a labeler.yml", () => { }, ]; const lExpected = `# some header or other${EOL}baarden: - - src/vlaai/** + - changed-files: + - any-glob-to-any-file: src/vlaai/** `; equal( diff --git a/src/labeler-yml/generate.ts b/src/labeler-yml/generate.ts index 0d6d6d0..9fbed17 100644 --- a/src/labeler-yml/generate.ts +++ b/src/labeler-yml/generate.ts @@ -24,11 +24,16 @@ export default function generateLabelerYml( let lReturnValue = pGeneratedWarning; for (const lTeamName in pTeamMap) { const lPatternsForTeam = getPatternsForTeam(pCodeOwners, lTeamName) - .map((pPattern) => ` - ${transformForYamlAndMinimatch(pPattern)}${EOL}`) + .map( + (pPattern) => + ` - any-glob-to-any-file: ${transformForYamlAndMinimatch( + pPattern, + )}${EOL}`, + ) .join(""); if (lPatternsForTeam) { - lReturnValue += `${lTeamName}:${EOL}${lPatternsForTeam}${EOL}`; + lReturnValue += `${lTeamName}:${EOL} - changed-files:${EOL}${lPatternsForTeam}${EOL}`; } } return lReturnValue;