-
Notifications
You must be signed in to change notification settings - Fork 11
123 lines (106 loc) · 3.83 KB
/
reusable-spellcheck.yml
File metadata and controls
123 lines (106 loc) · 3.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
name: Check Spelling
on:
workflow_call:
inputs:
runner:
required: false
type: string
default: '"ubuntu-latest"'
jobs:
spellcheck:
runs-on: ${{ fromJSON(vars['UCI_SPELLCHECK_RUNNER'] || inputs['runner']) }}
steps:
- uses: actions/checkout@v5
- name: Extend the GitHub context
id: github
env:
BASE_SHA: ${{ github.event.pull_request.base.sha || github.event.merge_group.base_sha }}
run: |
if [[ -n "$BASE_SHA" ]]; then
echo "base_sha=$BASE_SHA" | tee -a $GITHUB_OUTPUT
git fetch origin "$BASE_SHA"
git diff --name-only "$BASE_SHA" |
jq -Rnc '[inputs]' |
xargs -I {} -0 echo "changed_files={}" |
tee -a $GITHUB_OUTPUT
fi
- id: config
uses: actions/github-script@v8
with:
script: |
const fs = require("fs");
const jsonConfigPaths = [
".cspell.json",
"cspell.json",
"cspell.config.json",
];
const yamlConfigPaths = [
".cspell.yaml",
".cspell.yml",
"cspell.yaml",
"cspell.yml",
"cspell.config.yaml",
"cspell.config.yml",
];
for (const configPath of jsonConfigPaths) {
if (fs.existsSync(configPath)) {
console.log(`Found config file at ${configPath}`);
core.setOutput("path", configPath);
core.setOutput("type", "json");
return;
}
}
for (const configPath of yamlConfigPaths) {
if (fs.existsSync(configPath)) {
console.log(`Found config file at ${configPath}`);
core.setOutput("path", configPath);
core.setOutput("type", "yaml");
return;
}
}
- if: steps.config.outputs.path == ''
run: echo '{}' > '.cspell.json'
- if: steps.config.outputs.type == 'json' && steps.config.outputs.path != '.cspell.json'
env:
CONFIG_PATH: ${{ steps.config.outputs.path }}
run: mv "$CONFIG_PATH" '.cspell.json'
- if: steps.config.outputs.type == 'yaml'
env:
CONFIG_PATH: ${{ steps.config.outputs.path }}
run: |
yq -o=json '.' "$CONFIG_PATH" > '.cspell.json'
rm "$CONFIG_PATH"
- uses: actions/github-script@v8
env:
IGNORE_WORDS: |
Adin
IGNORE_PATHS: |
**/*.mod
**/*.sum
with:
script: |
const fs = require("fs");
const config = JSON.parse(fs.readFileSync(".cspell.json"));
config.ignoreWords = config.ignoreWords ?? [];
for (const word of process.env.IGNORE_WORDS.trim().split("\n")) {
config.ignoreWords.push(word);
}
config.ignorePaths = config.ignorePaths ?? [];
for (const path of process.env.IGNORE_PATHS.trim().split("\n")) {
config.ignorePaths.push(path);
}
fs.writeFileSync(".cspell.json", JSON.stringify(config, null, 2));
- run: jq . .cspell.json
- uses: streetsidesoftware/cspell-action@d5d910b521ad408f1e7383c24609079f5a88bdca # v8.2.0
with:
incremental_files_only: ${{
steps.github.outputs.base_sha && !(
contains(fromJSON(steps.github.outputs.changed_files), '.github/workflows/spellcheck.yml') ||
(
steps.config.outputs.path != '' &&
contains(fromJSON(steps.github.outputs.changed_files), steps.config.outputs.path)
)
) && 'true' || 'false'
}}
config: '.cspell.json'
report: typos