-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
name: Clean up orphaned translation files | ||
on: | ||
workflow_dispatch: | ||
jobs: | ||
clean_orphaned_files: | ||
name: Clean up orphaned files | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 2 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: "14" | ||
|
||
- name: Cache Node.js modules | ||
uses: actions/cache@v3 | ||
with: | ||
path: ~/.npm | ||
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | ||
restore-keys: | | ||
${{ runner.os }}-node- | ||
- name: Install dependencies | ||
run: npm install --no-package-lock | ||
|
||
- name: Cache jq | ||
id: cache-jq | ||
uses: actions/cache@v3 | ||
with: | ||
path: /usr/local/bin/jq | ||
key: ${{ runner.os }}-jq | ||
restore-keys: | | ||
${{ runner.os }}-jq | ||
- name: Install jq (JSON processor) | ||
if: steps.cache-jq.outputs.cache-hit != 'true' | ||
uses: dcarbone/install-jq-action@main | ||
|
||
- name: Clean orphaned JSON files from other languages | ||
run: | | ||
for lang_dir in $(find . -mindepth 1 -maxdepth 1 -type d -name "*-*" | grep -E '[a-z]{2}-[A-Z]{2}'); do | ||
lang=$(basename "$lang_dir") | ||
find "$lang_dir" -type f -name "*.json" | while read file; do | ||
en_us_file="${file/$lang/en-US}" | ||
if [ ! -f "$en_us_file" ]; then | ||
rm "$file" | ||
echo "Deleted orphaned file $file in $lang" | ||
fi | ||
done | ||
done | ||
- name: Commit changes | ||
run: | | ||
git config --global user.name "GitHub Actions" | ||
git config --global user.email "actions@github.com" | ||
rm -f package-lock.json | ||
git add . | ||
git diff-index --quiet HEAD || git commit -m "Clean up orphaned translation files" | ||
- name: Create a pull request | ||
uses: peter-evans/create-pull-request@v5 | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
commit-message: "Clean up orphaned translation files" | ||
branch: "auto/clean-orphaned-files-${{ github.ref_name }}" | ||
title: "Clean up orphaned translation files in ${{ github.ref_name }}" | ||
body: "This PR cleans up orphaned translation files for the branch **${{ github.ref_name }}**." | ||
assignees: ilxlodev | ||
reviewers: ilxlodev | ||
labels: cleanup, blocked | ||
base: ${{ github.ref_name }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
name: Sync translations to other languages | ||
on: | ||
push: | ||
paths: | ||
- "en-US/**.json" | ||
branches: | ||
- "**/stable" | ||
workflow_dispatch: | ||
jobs: | ||
sync_translations: | ||
name: Sync translations | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
- name: Set up Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: "14" | ||
- name: Cache Node.js modules | ||
uses: actions/cache@v3 | ||
with: | ||
path: ~/.npm | ||
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | ||
restore-keys: | | ||
${{ runner.os }}-node- | ||
- name: Install dependencies | ||
run: npm install | ||
- name: Install jq (JSON processor) | ||
uses: dcarbone/install-jq-action@main | ||
- name: Copy new JSON files to other languages | ||
run: | | ||
for lang_dir in $(find . -mindepth 1 -maxdepth 1 -type d -name "*-*" | grep -E '[a-z]{2}-[A-Z]{2}'); do | ||
lang=$(basename "$lang_dir") | ||
find en-US -type f -name "*.json" | while read file; do | ||
new_file="${file/en-US/$lang}" | ||
if [ ! -f "$new_file" ]; then | ||
mkdir -p "$(dirname "$new_file")" | ||
cp "$file" "$new_file" | ||
echo "Created $new_file in $lang" | ||
fi | ||
done | ||
done | ||
- name: Commit changes | ||
run: | | ||
git config --global user.name "GitHub Actions" | ||
git config --global user.email "actions@github.com" | ||
rm -f package-lock.json | ||
git add . | ||
if ! git diff-index --quiet HEAD; then | ||
git commit -m "Add new translation files for other languages" | ||
else | ||
echo "No changes to commit" | ||
exit 0 | ||
fi | ||
- name: Create a pull request | ||
uses: peter-evans/create-pull-request@v5 | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
commit-message: "Add new translation files for other languages" | ||
branch: "auto/sync-translations-${{ github.ref_name }}" | ||
title: "Sync translations in ${{ github.ref_name }}" | ||
body: "This PR adds new translation files for the branch **${{ github.ref_name }}**." | ||
assignees: ilxlodev | ||
reviewers: ilxlodev | ||
labels: syncronization, blocked | ||
base: ${{ github.ref_name }} |