-
-
Notifications
You must be signed in to change notification settings - Fork 655
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix 17050actions warning message #17098
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
name: Rebuild English User Documentation for Translation | ||
|
||
on: | ||
push: | ||
branches: | ||
- beta | ||
paths: | ||
- 'user_docs/en/*.md' | ||
|
||
jobs: | ||
rebuild-translation-source: | ||
runs-on: windows-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.11' | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install lxml requests | ||
|
||
- name: update xliff files | ||
shell: pwsh | ||
run: | | ||
# for any English markdown files changed within the commits of this push, | ||
# update the corresponding xliff file (if one exists) to reflect the current markdown file, | ||
# keeping existing translation IDs in tact. | ||
$ErrorActionPreference = 'Stop' | ||
$changedFiles = git diff --name-only ${{github.event.before}}.. -- user_docs/en/*.md | ||
foreach ($file in $changedFiles) { | ||
Write-Host "$file has changed" | ||
$baseName = [System.IO.Path]::GetFileNameWithoutExtension($file) | ||
$xliff = "user_docs/en/$baseName.xliff" | ||
$tempXliff = "user_docs/en/$baseName.xliff.temp" | ||
$markdown = $file | ||
if (Test-Path $xliff) { | ||
Write-Host "Updating $xliff with changes from $markdown" | ||
python user_docs/markdownTranslate.py updateXliff -x $xliff -m $file -o $tempXliff | ||
Write-Host "Renaming $tempXliff to $xliff" | ||
move-item -Path $tempXliff -Destination $xliff -Force | ||
} else { | ||
Write-Host "Ignoring $markdown as it does not have a corresponding xliff file" | ||
} | ||
} | ||
if: success() | ||
|
||
- name: Commit and Push changes | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
$ErrorActionPreference = 'Stop' | ||
git config --local user.name "GitHub Actions" | ||
git config --local user.email "[email protected]" | ||
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }}.git | ||
$filesChanged = git diff --name-only -- *.xliff | ||
if ($filesChanged) { | ||
Write-Host "xliff files were changed. Committing and pushing changes." | ||
foreach ($file in $filesChanged) { | ||
git add $file | ||
git commit -m "Update $file" | ||
} | ||
git push origin HEAD | ||
} else { | ||
Write-Host "No xliff files were changed. Skipping commit and push." | ||
} | ||
if: success() | ||
Comment on lines
+55
to
+74
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Commit and push process is well-implemented, but could be more efficient. The process correctly commits and pushes changes for modified XLIFF files. However, there's an opportunity to optimize the git operations. Consider the following optimizations:
-foreach ($file in $filesChanged) {
- git add $file
- git commit -m "Update $file"
-}
+git add *.xliff
+git commit -m "Update XLIFF files"
-$filesChanged = git diff --name-only -- *.xliff
-if ($filesChanged) {
+if (-not (git diff --quiet -- *.xliff)) { |
||
|
||
- name: Crowdin upload | ||
# This step must only be run after successfully pushing changes to the repository. | ||
# Otherwise if the push fails, subsequent runs may cause new translation IDs to be created, | ||
# which will cause needless retranslation of existing strings. | ||
env: | ||
crowdinProjectID: ${{ vars.CROWDIN_PROJECT_ID }} | ||
crowdinAuthToken: ${{ secrets.CROWDIN_AUTH_TOKEN }} | ||
run: | | ||
# Check if we changed userGuide.xliff in this action. | ||
# If we did, upload it to Crowdin. | ||
$ErrorActionPreference = 'Stop' | ||
$changed = git diff --name-only ${{GITHUB.SHA}}.. -- user_docs/en/userGuide.xliff | ||
if ($changed) { | ||
Write-Host "Uploading userGuide.xliff to Crowdin" | ||
# 18 is the file ID for userGuide.xliff in Crowdin. | ||
python appVeyor/crowdinSync.py uploadSourceFile 18 user_docs/en/userguide.xliff | ||
} else { | ||
Write-Host "Not uploading userGuide.xliff to Crowdin as it has not changed" | ||
} | ||
Comment on lines
+76
to
+94
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Crowdin upload process is correctly implemented, but could be improved. The process checks for changes in userGuide.xliff and uploads it to Crowdin if changed. However, there are a few points to consider:
Consider the following improvements:
env:
crowdinProjectID: ${{ vars.CROWDIN_PROJECT_ID }}
crowdinAuthToken: ${{ secrets.CROWDIN_AUTH_TOKEN }}
+ crowdinUserGuideFileID: 18
-$changed = git diff --name-only ${{GITHUB.SHA}}.. -- user_docs/en/userGuide.xliff
+$changed = git diff --quiet ${{GITHUB.SHA}} HEAD -- user_docs/en/userGuide.xliff
+if ($LASTEXITCODE -eq 1) {
python appVeyor/crowdinSync.py uploadSourceFile 18 user_docs/en/userguide.xliff
+if ($LASTEXITCODE -ne 0) {
+ Write-Error "Failed to upload userGuide.xliff to Crowdin"
+ exit 1
+} |
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
XLIFF update process is well-implemented, but could be optimized.
The script efficiently updates XLIFF files for changed markdown files. However, there's room for improvement:
Consider the following optimizations: