Skip to content

Commit

Permalink
ci: Lint textdomain in block.json files (#37057)
Browse files Browse the repository at this point in the history
The textdomain field should match the domain of the containing plugin or
package, or else we run into issues like #37013.

Also fix the existing issue in two packages.
  • Loading branch information
anomiex authored Apr 24, 2024
1 parent eac1086 commit 9708630
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 4 deletions.
30 changes: 30 additions & 0 deletions .github/files/lint-project-structure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,36 @@ for FILE in $(git -c core.quotepath=off ls-files 'projects/packages/**/.eslintrc
fi
done

# - Text domains in block.json should match composer.json.
debug "Checking textdomain usage in block.json"
for FILE in $(git -c core.quotepath=off ls-files 'projects/packages/**/block.json' 'projects/plugins/**/block.json'); do
[[ "$FILE" == projects/packages/blocks/tests/php/fixtures/* ]] && continue # Ignore test fixtures

DOM="$(jq -r '.textdomain' "$FILE")"
DIR="$FILE"
while ! [[ "$DIR" =~ ^projects/[^/]*/[^/]*$ ]]; do
DIR="${DIR%/*}"
done
SLUG="${DIR#projects/}"
if [[ "$SLUG" == plugins/* ]]; then
DOM2="$(jq -r '.extra["wp-plugin-slug"] // .extra["wp-theme-slug"] // ""' "$DIR/composer.json")"
else
DOM2="$(jq -r '.extra.textdomain // ""' "$DIR/composer.json")"
fi
if [[ "$DOM" != "$DOM2" ]]; then
EXIT=1
LINE=$(jq --stream 'if length == 1 then .[0][:-1] else .[0] end | if . == ["textdomain"] then input_line_number - 1 else empty end' package.json)
if [[ -n "$LINE" ]]; then
LINE=",line=${LINE%%:*}"
fi
if [[ -z "$DOM2" ]]; then
echo "::error file=$FILE$LINE::block.json sets textdomain \"$DOM\", but $SLUG's composer.json does not set \`.extra.textdomain\`."
else
echo "::error file=$FILE$LINE::block.json sets textdomain \"$DOM\", but $SLUG's composer.json sets domain \"$DOM2\"."
fi
fi
done

# - .nvmrc should match .github/versions.sh.
debug "Checking .nvmrc vs versions.sh"
if [[ "$(<.nvmrc)" != "$NODE_VERSION" ]]; then
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Set correct `textdomain` in `block.json`.
2 changes: 1 addition & 1 deletion projects/packages/forms/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@automattic/jetpack-forms",
"version": "0.30.16",
"version": "0.30.17-alpha",
"description": "Jetpack Forms",
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/packages/forms/#readme",
"bugs": {
Expand Down
2 changes: 1 addition & 1 deletion projects/packages/forms/src/blocks/contact-form/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"description": "Create forms to collect data from site visitors and manage their responses.",
"keywords": [ "email", "feedback", "contact form" ],
"version": "12.5.0",
"textdomain": "jetpack",
"textdomain": "jetpack-forms",
"category": "contact-form",
"icon": "<svg viewBox='0 0 24 24' width='24' height='24' xmlns='http://www.w3.org/2000/svg'><path d='m13 7.5 h 5 v 1.5 h -5 v -1.5z'/><path d='m13 15 h 5 v 1.5 h -5 v -1.5z'/><path d='m19.01,3H4.99c-1.1,0-1.99.89-1.99,1.99v14.02c0,1.1.89,1.99,1.99,1.99h14.02c1.1,0,1.99-.89,1.99-1.99V4.99c0-1.1-.89-1.99-1.99-1.99Zm.49,15.99c0,.28-.23.51-.51.51H5.01c-.28,0-.51-.23-.51-.51V5.01c0-.28.23-.51.51-.51h13.98c.28,0,.51.23.51.51v13.98Z'/><path d='m9.46,13h-1.92c-.85,0-1.54.69-1.54,1.54v1.92c0,.85.69,1.54,1.54,1.54h1.92c.85,0,1.54-.69,1.54-1.54v-1.92c0-.85-.69-1.54-1.54-1.54Zm.04,3.5h-2v-2h2v2Z'/><path d='m9.46,6h-1.92c-.85,0-1.54.69-1.54,1.54v1.92c0,.85.69,1.54,1.54,1.54h1.92c.85,0,1.54-.69,1.54-1.54v-1.92c0-.85-.69-1.54-1.54-1.54Zm.04,3.5h-2v-2h2v2Z'/></svg>",
"supports": {
Expand Down
2 changes: 1 addition & 1 deletion projects/packages/forms/src/class-jetpack-forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
class Jetpack_Forms {

const PACKAGE_VERSION = '0.30.16';
const PACKAGE_VERSION = '0.30.17-alpha';

/**
* Load the contact form module.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Set correct `textdomain` in `block.json`.
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
"type": "number"
}
},
"textdomain": "jetpack-videopress",
"textdomain": "jetpack-videopress-pkg",
"editorScript": "file:./index.js",
"editorStyle": "file:./index.css",
"style": "file:./style.css",
Expand Down

0 comments on commit 9708630

Please sign in to comment.