Skip to content

feat: numeric embedded fields #5691

feat: numeric embedded fields

feat: numeric embedded fields #5691

name: Warn on Deleted Translation Keys
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
detect-deleted-keys:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install jq
run: sudo apt-get install -y jq
- name: Detect deleted nested keys
id: detect
run: |
BASE_SHA=$(jq -r '.pull_request.base.sha' "$GITHUB_EVENT_PATH")
HEAD_SHA=$(jq -r '.pull_request.head.sha' "$GITHUB_EVENT_PATH")
LOCALE_DIR="packages/visual-editor/locales"
declare -A deleted_map
flatten_keys() {
jq -r 'paths(scalars) | map(tostring) | join(".")' "$1" | sort
}
for file in $(git diff --name-only "$BASE_SHA" "$HEAD_SHA" -- "$LOCALE_DIR"); do
[[ "$file" != *.json ]] && continue
LANG=$(basename "$(dirname "$file")")
TMP_BASE=$(mktemp)
TMP_HEAD=$(mktemp)
git show "${BASE_SHA}:${file}" > "$TMP_BASE" 2>/dev/null || continue
git show "${HEAD_SHA}:${file}" > "$TMP_HEAD" 2>/dev/null || echo '{}' > "$TMP_HEAD"
flatten_keys "$TMP_BASE" > base_keys.txt
flatten_keys "$TMP_HEAD" > head_keys.txt
while read -r key; do
[[ -z "$key" ]] && continue
deleted_map["$key"]+="${LANG} "
done < <(comm -23 base_keys.txt head_keys.txt)
done
if [ ${#deleted_map[@]} -gt 0 ]; then
OUTPUT="### 🔤 Deleted Translation Keys\n"
declare -A grouped
for key in "${!deleted_map[@]}"; do
group="${key%%.*}"
grouped["$group"]+="$key"$'\n'
done
for group in $(printf "%s\n" "${!grouped[@]}" | sort); do
OUTPUT+="\n#### \`$group\`\n\n"
OUTPUT+="| Key | Languages Removed |\n| --- | ----------------- |\n"
while read -r key; do
[[ -z "$key" ]] && continue
langs=$(echo "${deleted_map[$key]}" | xargs -n1 | sort | uniq | paste -sd ', ' -)
OUTPUT+="| \`$key\` | $langs |\n"
done < <(printf "%s" "${grouped[$group]}" | sort)
done
echo "comment<<EOF" >> "$GITHUB_OUTPUT"
echo -e "$OUTPUT" >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
echo "has_deleted=true" >> "$GITHUB_OUTPUT"
else
echo "has_deleted=false" >> "$GITHUB_OUTPUT"
fi
- name: Manage PR comment
uses: actions/github-script@v7
with:
script: |
const marker = "<!-- deleted-translations-warning -->";
const { owner, repo, number } = context.issue;
const { data: comments } = await github.rest.issues.listComments({
owner,
repo,
issue_number: number,
});
const existing = comments.find(c => c.body.includes(marker));
const hasDeleted = '${{ steps.detect.outputs.has_deleted }}' === 'true';
if (hasDeleted) {
const commentBody = `## ⚠️ Deleted Translation Keys Detected\n\n${process.env.COMMENT}`;
const fullBody = `${marker}\n${commentBody}`;
if (existing) {
await github.rest.issues.updateComment({
owner,
repo,
comment_id: existing.id,
body: fullBody,
});
} else {
await github.rest.issues.createComment({
owner,
repo,
issue_number: number,
body: fullBody,
});
}
} else {
if (existing) {
await github.rest.issues.deleteComment({
owner,
repo,
comment_id: existing.id,
});
console.log("✅ Removed outdated warning comment.");
} else {
console.log("ℹ️ No deleted keys and no comment found.");
}
}
env:
COMMENT: ${{ steps.detect.outputs.comment }}