mirror of
https://github.com/langgenius/dify.git
synced 2026-04-04 21:00:18 -04:00
82 lines
2.9 KiB
YAML
82 lines
2.9 KiB
YAML
name: Trigger i18n Sync on Push
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
paths:
|
|
- 'web/i18n/en-US/*.json'
|
|
|
|
permissions:
|
|
contents: write
|
|
|
|
concurrency:
|
|
group: trigger-i18n-sync-${{ github.ref }}
|
|
cancel-in-progress: true
|
|
|
|
jobs:
|
|
trigger:
|
|
if: github.repository == 'langgenius/dify'
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 5
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Detect changed files and generate full diff
|
|
id: detect
|
|
shell: bash
|
|
run: |
|
|
BASE_SHA="${{ github.event.before }}"
|
|
if [ -z "$BASE_SHA" ] || [ "$BASE_SHA" = "0000000000000000000000000000000000000000" ]; then
|
|
BASE_SHA=$(git rev-parse HEAD~1 2>/dev/null || true)
|
|
fi
|
|
HEAD_SHA="${{ github.sha }}"
|
|
|
|
if [ -n "$BASE_SHA" ]; then
|
|
CHANGED_FILES=$(git diff --name-only "$BASE_SHA" "$HEAD_SHA" -- 'web/i18n/en-US/*.json' 2>/dev/null | sed -n 's@^.*/@@p' | sed 's/\.json$//' | tr '\n' ' ' | sed 's/[[:space:]]*$//')
|
|
git diff "$BASE_SHA" "$HEAD_SHA" -- 'web/i18n/en-US/*.json' > /tmp/i18n-diff.txt 2>/dev/null || : > /tmp/i18n-diff.txt
|
|
else
|
|
CHANGED_FILES=$(find web/i18n/en-US -maxdepth 1 -type f -name '*.json' -print | sed -n 's@^.*/@@p' | sed 's/\.json$//' | sort | tr '\n' ' ' | sed 's/[[:space:]]*$//')
|
|
: > /tmp/i18n-diff.txt
|
|
fi
|
|
|
|
if [ -n "$CHANGED_FILES" ]; then
|
|
echo "has_changes=true" >> "$GITHUB_OUTPUT"
|
|
else
|
|
echo "has_changes=false" >> "$GITHUB_OUTPUT"
|
|
fi
|
|
|
|
echo "base_sha=$BASE_SHA" >> "$GITHUB_OUTPUT"
|
|
echo "head_sha=$HEAD_SHA" >> "$GITHUB_OUTPUT"
|
|
echo "changed_files=$CHANGED_FILES" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Trigger i18n sync workflow
|
|
if: steps.detect.outputs.has_changes == 'true'
|
|
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
|
|
env:
|
|
BASE_SHA: ${{ steps.detect.outputs.base_sha }}
|
|
HEAD_SHA: ${{ steps.detect.outputs.head_sha }}
|
|
CHANGED_FILES: ${{ steps.detect.outputs.changed_files }}
|
|
with:
|
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
script: |
|
|
const fs = require('fs')
|
|
|
|
const diffBase64 = fs.readFileSync('/tmp/i18n-diff.txt').toString('base64')
|
|
|
|
await github.rest.repos.createDispatchEvent({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
event_type: 'i18n-sync',
|
|
client_payload: {
|
|
changed_files: process.env.CHANGED_FILES,
|
|
diff_base64: diffBase64,
|
|
sync_mode: 'incremental',
|
|
base_sha: process.env.BASE_SHA,
|
|
head_sha: process.env.HEAD_SHA,
|
|
},
|
|
})
|