-
Notifications
You must be signed in to change notification settings - Fork 178
140 lines (115 loc) · 3.95 KB
/
lint-i18n.yml
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
128
129
130
131
132
133
134
135
136
137
138
139
140
name: Lint I18N
on:
push:
paths:
- '**.js'
- '**.cjs'
- '**.ts'
- '**.tsx'
- '**/package.json'
- 'package-lock.json'
- 'web-stories.php'
- 'includes/**.php'
- '.github/workflows/lint-i18n.yml'
branches:
- main
pull_request:
paths:
- '**.js'
- '**.cjs'
- '**.ts'
- '**.tsx'
- '**/package.json'
- 'package-lock.json'
- 'web-stories.php'
- 'includes/**.php'
- '.github/workflows/lint-i18n.yml'
permissions:
contents: read
# Cancels all previous workflow runs for pull requests that have not completed.
concurrency:
# The concurrency group contains the workflow name and the (target) branch name.
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Harden Runner
uses: step-security/harden-runner@1b05615854632b887b69ae1be8cbefe72d3ae423
with:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- name: Install WP-CLI
run: |
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
mkdir -p bin
mv wp-cli.phar bin/wp
echo "${PWD}/bin" >> $GITHUB_PATH
- name: WP-CLI Info
run: wp cli info
- name: Install latest version of i18n-command
run: wp package install wp-cli/i18n-command:dev-main
- name: List packages
run: wp package list
- name: Setup Node
uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65
with:
node-version-file: '.nvmrc'
cache: npm
- name: Setup PHP
uses: shivammathur/setup-php@a36e1e52ff4a1c9e9c9be31551ee4712a6cb6bd0
with:
php-version: '8.0'
coverage: none
tools: composer
- name: Install dependencies
run: |
npm ci
env:
PUPPETEER_SKIP_DOWNLOAD: true
- name: Install PHP dependencies
uses: ramsey/composer-install@83af392bf5f031813d25e6fe4cd626cdba9a2df6
with:
composer-options: '--prefer-dist --no-progress --no-interaction'
- name: Setup Bun
uses: oven-sh/setup-bun@830e319e28724678162e88b9145a9b43f22f1a8e
with:
bun-version: '0.5.9'
- name: Build plugin
run: bun run build:js
- name: Bundle regular version
run: bun run workflow:build-plugin
# Check if as many strings as expected were found.
# Fail job if `wp i18n make-pot` returns any warnings.
# Some false positive warnings are removed due to a bug in the string extraction.
# That's why this step is unfortunately a bit more complex.
# See https://github.com/wp-cli/i18n-command/issues/154
- name: Generate POT file
run: |
OUTPUT=$((wp i18n make-pot build/web-stories build/web-stories.pot) 2>&1 >/dev/null)
HAS_ERROR=false
EXPECTED_NUMBER_OF_STRINGS=1000
NUMBER_OF_FOUND_STRINGS=$(grep -o msgstr build/web-stories.pot | wc -l | xargs)
if (( "$NUMBER_OF_FOUND_STRINGS" < "$EXPECTED_NUMBER_OF_STRINGS" )); then
HAS_ERROR=true
echo "String extraction found only $NUMBER_OF_FOUND_STRINGS translatable strings. Expected at least $EXPECTED_NUMBER_OF_STRINGS."
fi
IFS=$'\n'
declare -a WARNINGS=($OUTPUT)
unset IFS
for WARNING in "${WARNINGS[@]}"; do
# Filter false positives.
if [[ $WARNING == *"translator comment"* ]] && [[ $WARNING != *"%s"* ]]; then
continue
fi
HAS_ERROR=true
echo $WARNING
done
if [[ "$HAS_ERROR" = true ]]; then
exit 1
fi