Skip to content

Update en_US.lang and Website en.json #123

Update en_US.lang and Website en.json

Update en_US.lang and Website en.json #123

Workflow file for this run

name: Update en_US.lang and Website en.json
on:
schedule:
- cron: "0 0 * * *" # Every UTC midnight
workflow_dispatch: # Allow manual trigger
push:
paths:
- '.github/workflows/update-en-US.yml'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true # Cancel old runs to prevent queueing
jobs:
update-en-us-lang:
runs-on: ubuntu-latest
outputs:
has_changes: ${{ steps.check-changes.outputs.has_changes || 'false' }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Fetch latest en_US.lang file
env:
GITHUB_TOKEN: ${{ secrets.PRIVATE_REPO_PAT }}
run: |
# Create temp directory
mkdir -p temp_euphoria
# Clone the private Euphoria-Patches repository
git clone --depth 1 https://[email protected]/EuphoriaPatches/Euphoria-Patches.git temp_euphoria
# Copy the en_US.lang file from shaders/lang/ to root directory
if [ -f temp_euphoria/shaders/lang/en_US.lang ]; then
cp -v temp_euphoria/shaders/lang/en_US.lang ./en_US.lang
echo "Successfully copied en_US.lang file"
else
echo "Error: en_US.lang file not found in temp_euphoria/shaders/lang/"
exit 1
fi
# Clean up
rm -rf temp_euphoria
# Check if there were changes to en_US.lang
- name: Check for en_US.lang changes
id: check-changes
run: |
if [ "$(git status --porcelain en_US.lang | wc -l)" -gt "0" ]; then
echo "has_changes=true" >> $GITHUB_OUTPUT
echo "en_US.lang file changes detected"
git diff en_US.lang || true
else
echo "has_changes=false" >> $GITHUB_OUTPUT
echo "No changes detected in en_US.lang file"
fi
# Upload en_US.lang as an artifact if changed
- name: Upload en_US.lang artifact
if: steps.check-changes.outputs.has_changes == 'true'
uses: actions/upload-artifact@v4
with:
name: en-us-lang-file
path: en_US.lang
retention-days: 1
update-website-en-json:
runs-on: ubuntu-latest
outputs:
has_changes: ${{ steps.check-changes.outputs.has_changes || 'false' }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Fetch website en.json translation
run: |
# Create temp directory
mkdir -p temp_website
# Clone the EuphoriaPatches.github.io repository
git clone --depth 1 https://github.com/EuphoriaPatches/EuphoriaPatches.github.io.git temp_website
# Copy the en.json file to website/ directory
mkdir -p website
if [ -f temp_website/how-to-install/translations/en.json ]; then
cp -v temp_website/how-to-install/translations/en.json website/en.json
echo "Successfully copied en.json file"
else
echo "Error: en.json file not found in temp_website/how-to-install/translations/"
exit 1
fi
# Clean up
rm -rf temp_website
# Check if there were changes to website/en.json
- name: Check for website/en.json changes
id: check-changes
run: |
if [ "$(git status --porcelain website/en.json | wc -l)" -gt "0" ]; then
echo "has_changes=true" >> $GITHUB_OUTPUT
echo "website/en.json file changes detected"
git diff website/en.json || true
else
echo "has_changes=false" >> $GITHUB_OUTPUT
echo "No changes detected in website/en.json file"
fi
# Upload website/en.json as an artifact if changed
- name: Upload website/en.json artifact
if: steps.check-changes.outputs.has_changes == 'true'
uses: actions/upload-artifact@v4
with:
name: website-en-json
path: website/en.json
retention-days: 1
commit-and-push:
runs-on: ubuntu-latest
needs: [update-en-us-lang, update-website-en-json]
if: |
always() &&
(needs.update-en-us-lang.outputs.has_changes == 'true' ||
needs.update-website-en-json.outputs.has_changes == 'true')
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download en_US.lang file
if: needs.update-en-us-lang.outputs.has_changes == 'true'
uses: actions/download-artifact@v4
with:
name: en-us-lang-file
path: ./
- name: Download website/en.json file
if: needs.update-website-en-json.outputs.has_changes == 'true'
uses: actions/download-artifact@v4
with:
name: website-en-json
path: website
- name: Configure Git
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
- name: Stage files if changed
run: |
git add en_US.lang || true
git add website/en.json || true
- name: Debug Git Status
run: |
git status
git diff
git diff --staged
- name: Commit and push changes
run: |
# Determine which files are staged
MSG=""
if git diff --cached --name-only | grep -q "^en_US.lang$"; then
MSG="Update en_US.lang"
fi
if git diff --cached --name-only | grep -q "^website/en.json$"; then
if [ -n "$MSG" ]; then
MSG="$MSG and website/en.json"
else
MSG="Update website/en.json"
fi
fi
if [ -z "$MSG" ]; then
MSG="Update language files"
fi
MSG="$MSG [skip ci]"
# Only commit if there are staged changes
git diff --quiet --staged || {
git commit -m "$MSG"
MAX_RETRIES=5
RETRY_COUNT=0
until git push || [ $RETRY_COUNT -ge $MAX_RETRIES ]; do
RETRY_COUNT=$((RETRY_COUNT + 1))
echo "Push failed, retrying (Attempt $RETRY_COUNT/$MAX_RETRIES)..."
git pull --rebase
done
}