Skip to content

Commit ab7eb13

Browse files
Merge branch 'main' into changesets
2 parents 9138482 + 3cc59be commit ab7eb13

File tree

4 files changed

+188
-48
lines changed

4 files changed

+188
-48
lines changed

.github/labeler.yml

Lines changed: 0 additions & 46 deletions
This file was deleted.

.github/workflows/labeler.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@ name: Labeler
33
on:
44
- pull_request_target
55

6+
permissions:
7+
contents: read
8+
pull-requests: write
9+
610
jobs:
7-
triage:
11+
labeler:
812
runs-on: ubuntu-latest
913
steps:
10-
- uses: actions/labeler@v4.3.0
14+
- uses: actions/labeler@v5.0.0
1115
with:
1216
repo-token: ${{ secrets.GITHUB_TOKEN }}
17+
configuration-path: labeler-config.yml

labeler-config.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
'package: angular-query-devtools-experimental':
2+
- changed-files:
3+
- any-glob-to-any-file: 'packages/angular-query-devtools-experimental/**/*'
4+
'package: angular-query-experimental':
5+
- changed-files:
6+
- any-glob-to-any-file: 'packages/angular-query-experimental/**/*'
7+
'package: angular-query-persist-client':
8+
- changed-files:
9+
- any-glob-to-any-file: 'packages/angular-query-persist-client/**/*'
10+
'package: eslint-plugin-query':
11+
- changed-files:
12+
- any-glob-to-any-file: 'packages/eslint-plugin-query/**/*'
13+
'package: query-async-storage-persister':
14+
- changed-files:
15+
- any-glob-to-any-file: 'packages/query-async-storage-persister/**/*'
16+
'package: query-broadcast-client-experimental':
17+
- changed-files:
18+
- any-glob-to-any-file: 'packages/query-broadcast-client-experimental/**/*'
19+
'package: query-codemods':
20+
- changed-files:
21+
- any-glob-to-any-file: 'packages/query-codemods/**/*'
22+
'package: query-core':
23+
- changed-files:
24+
- any-glob-to-any-file: 'packages/query-core/**/*'
25+
'package: query-devtools':
26+
- changed-files:
27+
- any-glob-to-any-file: 'packages/query-devtools/**/*'
28+
'package: query-persist-client-core':
29+
- changed-files:
30+
- any-glob-to-any-file: 'packages/query-persist-client-core/**/*'
31+
'package: query-sync-storage-persister':
32+
- changed-files:
33+
- any-glob-to-any-file: 'packages/query-sync-storage-persister/**/*'
34+
'package: query-test-utils':
35+
- changed-files:
36+
- any-glob-to-any-file: 'packages/query-test-utils/**/*'
37+
'package: react-query':
38+
- changed-files:
39+
- any-glob-to-any-file: 'packages/react-query/**/*'
40+
'package: react-query-devtools':
41+
- changed-files:
42+
- any-glob-to-any-file: 'packages/react-query-devtools/**/*'
43+
'package: react-query-next-experimental':
44+
- changed-files:
45+
- any-glob-to-any-file: 'packages/react-query-next-experimental/**/*'
46+
'package: react-query-persist-client':
47+
- changed-files:
48+
- any-glob-to-any-file: 'packages/react-query-persist-client/**/*'
49+
'package: solid-query':
50+
- changed-files:
51+
- any-glob-to-any-file: 'packages/solid-query/**/*'
52+
'package: solid-query-devtools':
53+
- changed-files:
54+
- any-glob-to-any-file: 'packages/solid-query-devtools/**/*'
55+
'package: solid-query-persist-client':
56+
- changed-files:
57+
- any-glob-to-any-file: 'packages/solid-query-persist-client/**/*'
58+
'package: svelte-query':
59+
- changed-files:
60+
- any-glob-to-any-file: 'packages/svelte-query/**/*'
61+
'package: svelte-query-devtools':
62+
- changed-files:
63+
- any-glob-to-any-file: 'packages/svelte-query-devtools/**/*'
64+
'package: svelte-query-persist-client':
65+
- changed-files:
66+
- any-glob-to-any-file: 'packages/svelte-query-persist-client/**/*'
67+
'package: vue-query':
68+
- changed-files:
69+
- any-glob-to-any-file: 'packages/vue-query/**/*'
70+
'package: vue-query-devtools':
71+
- changed-files:
72+
- any-glob-to-any-file: 'packages/vue-query-devtools/**/*'
73+
'documentation':
74+
- changed-files:
75+
- any-glob-to-any-file: 'docs/**/*'

scripts/generate-labeler-config.ts

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import * as fs from 'node:fs'
2+
import * as path from 'node:path'
3+
import * as prettier from 'prettier'
4+
5+
/** Pairs of package labels and their corresponding paths */
6+
type LabelerPair = [string, string]
7+
8+
function readPairsFromFs(): Array<LabelerPair> {
9+
const ignored = new Set(['.DS_Store'])
10+
11+
const pairs: Array<LabelerPair> = []
12+
13+
// Add subfolders in the packages folder, i.e. packages/**
14+
fs.readdirSync(path.resolve('packages'))
15+
.filter((folder) => !ignored.has(folder))
16+
.forEach((folder) => {
17+
// Check if package.json exists for the folder before adding it
18+
if (
19+
fs.existsSync(
20+
path.resolve(path.join('packages', folder, 'package.json')),
21+
)
22+
) {
23+
pairs.push([`package: ${folder}`, `packages/${folder}/**/*`])
24+
} else {
25+
console.info(
26+
`Skipping \`${folder}\` as it does not have a \`package.json\` file.`,
27+
)
28+
}
29+
})
30+
31+
// Sort by package name in alphabetical order
32+
pairs.sort((a, b) => a[0].localeCompare(b[0]))
33+
34+
return pairs
35+
}
36+
37+
async function generateLabelerYaml(pairs: Array<LabelerPair>): Promise<string> {
38+
function s(n = 1) {
39+
return ' '.repeat(n)
40+
}
41+
42+
// Convert the pairs into valid yaml
43+
const formattedPairs = pairs
44+
.map(([packageLabel, packagePath]) => {
45+
const result = [
46+
`'${packageLabel}':`,
47+
`${s(2)}-${s(1)}changed-files:`,
48+
`${s(4)}-${s(1)}any-glob-to-any-file:${s(1)}'${packagePath}'`,
49+
].join('\n')
50+
51+
return result
52+
})
53+
.join('\n')
54+
55+
// Get the location of the Prettier config file
56+
const prettierConfigPath = await prettier.resolveConfigFile()
57+
if (!prettierConfigPath) {
58+
throw new Error(
59+
'No Prettier config file found. Please ensure you have a Prettier config file in your project.',
60+
)
61+
}
62+
console.info('using prettier config file at:', prettierConfigPath)
63+
64+
// Resolve the Prettier config
65+
const prettierConfig = await prettier.resolveConfig(prettierConfigPath)
66+
console.info('using resolved prettier config:', prettierConfig)
67+
68+
// Format the YAML string using Prettier
69+
const formattedStr = await prettier.format(formattedPairs, {
70+
parser: 'yaml',
71+
...prettierConfig,
72+
})
73+
74+
return formattedStr
75+
}
76+
77+
async function run() {
78+
console.info('Generating labeler config...')
79+
80+
// Generate the pairs of package labels and their corresponding paths
81+
const pairs = readPairsFromFs()
82+
83+
// Always add the docs folder
84+
pairs.push(['documentation', 'docs/**/*'])
85+
86+
// Convert the pairs into valid yaml
87+
const yamlStr = await generateLabelerYaml(pairs)
88+
89+
// Write to 'labeler-config.yml'
90+
const configPath = path.resolve('labeler-config.yml')
91+
fs.writeFileSync(configPath, yamlStr, {
92+
encoding: 'utf-8',
93+
})
94+
95+
console.info(`Generated labeler config at \`${configPath}\`!`)
96+
return
97+
}
98+
99+
try {
100+
run().then(() => {
101+
process.exit(0)
102+
})
103+
} catch (error) {
104+
console.error('Error generating labeler config:', error)
105+
process.exit(1)
106+
}

0 commit comments

Comments
 (0)