-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yaml
127 lines (116 loc) · 3.76 KB
/
action.yaml
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
124
125
126
127
---
name: Word Warden
author: Simon Bengtsson
description: Spellcheck your text files
inputs:
files:
description: "Files to spellcheck, (glob expressions accepted)."
required: false
default: "**/*.md"
language:
description: |
"Language of your text files, specified as a locale code
(in format accepted by aspell, such as en_US)."
required: false
default: "en_US"
dictionary:
description: "Path to your personal dictionary in aspell format."
required: false
preprocessing_script:
description: |
Path to a sed script that you want run on all files before they are
spellchecked.
required: false
word_warden_ref:
description: "Version of Word Warden to checkout (only for development)."
default: "v1.0.0"
required: false
runs:
using: composite
steps:
- name: Checkout repository to spellcheck
uses: actions/checkout@v4
with:
path: evaluated-repository
- name: Checkout Word Warden
uses: actions/checkout@v4
with:
repository: gevhaz/word-warden
ref: ${{ inputs.word_warden_ref }}
path: word-warden
- name: Extract spelling language code
run: |
# Extract spelling language code
INPUT_LOCALE=${{ inputs.language }}
echo "SPELLLANG=${INPUT_LOCALE:0:2}" >> $GITHUB_ENV
shell: bash
- name: Install apt prerequisites
run: |
echo "::group::Install apt prerequisites"
sudo apt update
sudo apt install -y -qq aspell pandoc python3-pip aspell-$SPELLLANG
echo "::endgroup::"
shell: bash
- name: Install Python prerequisites
run: |
echo "::group::Install Python prerequisites"
pip install -r requirements.txt
echo "::endgroup::"
shell: bash
working-directory: word-warden
- name: Create empty dictionary if none is provided
run: |
# Create empty dictionary if none is provided
if [ -z "${{ inputs.dictionary }}" ]; then
DEFAULT_DICTIONARY=.github/data/project-dictionary.txt
if [ ! -f "$DEFAULT_DICTIONARY" ]; then
mkdir -p .github/data
echo "personal_ws-1.1 en 12 utf-8" > "$DEFAULT_DICTIONARY"
fi
echo "DICTIONARY_PATH=$DEFAULT_DICTIONARY" >> $GITHUB_ENV
else
echo "DICTIONARY_PATH=${{ inputs.dictionary }}" >> $GITHUB_ENV
fi
shell: bash
working-directory: evaluated-repository
- name: Preprocess files if configured
run: |
# PREPROCESS FILES IF CONFIGURED
# Continue to next step if no preprocessing script
if [ -z "${{ inputs.preprocessing_script }}" ]; then
exit 0
fi
# Expand globbing expression
shopt -s globstar extglob
IFS=$'\n'
FILES=()
for file in ${{ inputs.files }}; do
FILES+=("$file")
done
unset IFS
# Print what it will look like so the user can see it
echo "::group::Print preprocessing result"
sed -s -f "${{ inputs.preprocessing_script }}" "${FILES[@]}"
echo "::endgroup::"
# Modify the files
sed -i -f "${{ inputs.preprocessing_script }}" "${FILES[@]}"
shell: bash
working-directory: evaluated-repository
- name: Spellcheck files
run: |
# SPELLCHECK FILES
# Expand globbing expression
shopt -s globstar extglob
IFS=$'\n'
FILES=()
for file in ${{ inputs.files }}; do
FILES+=("$file")
done
unset IFS
# Do the spellchecking
python3 ../word-warden/spellcheck.py \
--dictionary="$DICTIONARY_PATH" \
--language="${{ inputs.language }}" \
"${FILES[@]}"
shell: bash
working-directory: evaluated-repository