.github/workflows/updateLocalizations.yml #72
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
on: | |
workflow_dispatch | |
jobs: | |
update_en_localization: | |
environment: update localizations | |
runs-on: ubuntu-latest | |
env: | |
LOC_BOT_NAME: ${{secrets.LOC_BOT_NAME}} | |
LOC_BOT_EMAIL: ${{secrets.LOC_BOT_EMAIL}} | |
GH_TOKEN: ${{secrets.LOC_TOKEN}} | |
APPROVE_BOT_NAME: ${{secrets.APPROVE_BOT_NAME}} | |
APPROVE_BOT_EMAIL: ${{secrets.APPROVE_BOT_EMAIL}} | |
outputs: | |
branch-name: ${{steps.info.outputs.branch-name}} | |
pr-name: ${{steps.info.outputs.pr-name}} | |
steps: | |
- name: Prepare info | |
id: info | |
run: | | |
echo "branch-name=$(date +"${{ env.BRANCH_PATTERN }}_%F_%H-%M-%S")" >> $GITHUB_OUTPUT | |
echo "pr-name=$(date +'New translations (%F %T %Z)')" >> $GITHUB_OUTPUT | |
- uses: actions/checkout@v3 | |
with: | |
token: ${{secrets.LOC_TOKEN}} | |
submodules: recursive | |
persist-credentials: true | |
- name: Set Loc bot config details | |
run: | | |
git config --global user.name $LOC_BOT_NAME | |
git config --global user.email $LOC_BOT_EMAIL | |
git config --global core.autocrlf false | |
git config core.longpaths true | |
- uses: crazy-max/ghaction-import-gpg@v5 | |
with: | |
gpg_private_key: ${{secrets.GPG_TOKEN}} | |
passphrase: ${{secrets.PASS_PHRASE}} | |
git_config_global: true | |
git_user_signingkey: true | |
git_commit_gpgsign: true | |
- name: Update submodules | |
run: | | |
git checkout -b $BRANCH | |
git submodule init | |
git submodule update --remote --recursive | |
for folder in visuals/*; do | |
git -C $folder config remote.origin.fetch +refs/heads/*:refs/remotes/origin/* | |
done; | |
echo "::group::Fetch dev branch" | |
git submodule foreach --recursive 'git fetch; git checkout dev || echo "No dev branch in $name"' | |
echo "::endgroup::" | |
env: | |
BRANCH: ${{steps.info.outputs.branch-name}} | |
- name: Copy EN translation | |
run: | | |
for file in ./visuals/*/stringResources/en-US/resources.resjson; do | |
substring="visuals/" | |
location="${file/$substring/localizations/}" | |
substring="/stringresources" | |
newLocation="${location/$substring//stringResources}" | |
test -f $newLocation || mkdir -p ${newLocation%resources.resjson*} | |
cp $file $newLocation; | |
done; | |
- name: Commit and push changes | |
run: | | |
changes="$(git diff)" | |
if [[ $changes != "" ]]; then | |
defaultBranchName=$(git remote show origin | sed -n '/HEAD branch/s/.*: //p') | |
git add . && \ | |
git commit -S -m "New translations" && \ | |
git push --set-upstream origin $BRANCH && \ | |
gh pr create -B $defaultBranchName -b "Auto created Pull Request with new translations" -t "$PR_NAME" || \ | |
echo "New pull request to $repoName wasn't created" | |
else | |
echo "No changes" | |
fi | |
env: | |
PR_NAME: ${{steps.info.outputs.pr-name}} | |
BRANCH: ${{steps.info.outputs.branch-name}} | |
- name: Set Loc bot config details | |
run: | | |
git config --global user.name $APPROVE_BOT_NAME | |
git config --global user.email $APPROVE_BOT_EMAIL | |
- name: Approve pull request | |
run: | | |
pullRequestNumber=$(gh pr list --state=open --head=$BRANCH --json number) | |
if [[ $pullRequestNumber != "[]" ]]; then | |
defaultBranchName=$(git remote show origin | sed -n '/HEAD branch/s/.*: //p') | |
changes="$(git diff origin/$defaultBranchName)" | |
if [[ $changes != "" ]]; then | |
gh pr review $BRANCH --approve | |
echo "Pull request was approved" | |
gh pr merge $BRANCH -s --auto -t "New translations" | |
echo "Pull request was merged" | |
else | |
gh pr close -d $BRANCH | |
echo "No changes" | |
fi | |
else | |
echo "No pull request" | |
fi | |
env: | |
GH_TOKEN: ${{secrets.APPROVE_TOKEN}} | |
BRANCH: ${{steps.info.outputs.branch-name}} | |
update_other_localizations: | |
environment: update localizations | |
runs-on: ubuntu-latest | |
needs: update_en_localization | |
env: | |
LOC_BOT_NAME: ${{secrets.LOC_BOT_NAME}} | |
LOC_BOT_EMAIL: ${{secrets.LOC_BOT_EMAIL}} | |
GH_TOKEN: ${{secrets.LOC_TOKEN}} | |
APPROVE_BOT_NAME: ${{secrets.APPROVE_BOT_NAME}} | |
APPROVE_BOT_EMAIL: ${{secrets.APPROVE_BOT_EMAIL}} | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
token: ${{secrets.LOC_TOKEN}} | |
submodules: recursive | |
persist-credentials: true | |
- name: Set Loc bot config details | |
run: | | |
git config --global user.name $LOC_BOT_NAME | |
git config --global user.email $LOC_BOT_EMAIL | |
git config --global core.autocrlf false | |
- uses: crazy-max/ghaction-import-gpg@v5 | |
with: | |
gpg_private_key: ${{secrets.GPG_TOKEN}} | |
passphrase: ${{secrets.PASS_PHRASE}} | |
git_config_global: true | |
git_user_signingkey: true | |
git_commit_gpgsign: true | |
- name: Update submodules | |
run: | | |
git pull --recurse-submodules | |
git submodule update --remote --recursive | |
for folder in visuals/*; do | |
git -C $folder config remote.origin.fetch +refs/heads/*:refs/remotes/origin/* | |
done; | |
echo "::group::Fetch dev branch" | |
git submodule foreach --recursive '\ | |
git fetch; \ | |
git checkout dev || echo "No dev branch in $name"; \ | |
git checkout -b $BRANCH' | |
echo "::endgroup::" | |
env: | |
BRANCH: ${{needs.update_en_localization.outputs.branch-name}} | |
- name: Copy translations to submodules | |
run: | | |
for visualPath in ./localizations/*; do | |
repoName=$(echo $visualPath| cut -d'/' -f 3) | |
echo "::group::Copy to $repoName" | |
for filePath in $visualPath/stringResources/*/resources.resjson; do | |
if [[ $filePath == *"/en-US/"* ]]; then | |
continue | |
fi | |
substring="localizations/" | |
newLocation="${filePath/$substring/visuals/}" | |
dirToCreate=${newLocation%resources.resjson*} | |
if [ ! -d "$dirToCreate" ]; then | |
echo "Creating directory: $dirToCreate" | |
mkdir -p "$dirToCreate" | |
fi | |
echo "Copying $filePath to $newLocation" | |
cp $filePath $newLocation; | |
done; | |
echo "::endgroup::" | |
done; | |
- name: Delete old Pull Requests | |
run: | | |
for folder in visuals/*; do | |
repoName=$(echo $folder| cut -d'/' -f 2) | |
echo "::group::Delete old PRs in $repoName" | |
# List open pull requests and filter by branch pattern | |
matching_prs=$(gh pr list --repo "$REPO_OWNER/$repoName" -A "@me" --state open --json number,headRefName \ | |
--jq ".[] | select(.headRefName | test(\"$BRANCH_PATTERN\")) | .number") | |
if [ -z "$matching_prs" ]; then | |
echo "No open pull requests matching the branch pattern \"$BRANCH_PATTERN\"." | |
else | |
for pr in $matching_prs; do | |
# Close the pull request | |
gh pr close "$pr" --repo "$REPO_OWNER/$repoName" --delete-branch || | |
echo "Can't close Pull Request to $repoName, check an access" | |
done | |
fi | |
echo "::endgroup::" | |
done | |
env: | |
BRANCH_PATTERN: '${{ env.BRANCH_PATTERN }}_.*' | |
REPO_OWNER: 'microsoft' | |
- name: Commit and push new changes to submodules | |
run: | | |
mainFolder=$PWD | |
for folder in visuals/*; do | |
repoName=$(echo $folder| cut -d'/' -f 2) | |
echo "::group::Commit to $repoName" | |
cd "$mainFolder/$folder" | |
changes="$(git diff)" | |
if [[ $changes == "" ]]; then | |
echo "No changes for $repoName" | |
continue | |
fi | |
originalBranchName=$(git remote show origin | sed -n '/HEAD branch/s/.*: //p') | |
if git show-ref --quiet refs/heads/dev; then | |
originalBranchName=dev | |
fi | |
git add . && | |
git commit -S -m "New translations" && | |
git push --set-upstream origin $BRANCH && | |
gh pr create -B $originalBranchName -b "Auto created Pull Request with new translations" -t "$PR_NAME" || | |
echo "New pull request to $repoName wasn't created" | |
echo "::endgroup::" | |
done; | |
env: | |
BRANCH: ${{needs.update_en_localization.outputs.branch-name}} | |
PR_NAME: ${{needs.update_en_localization.outputs.pr-name}} | |
- name: Set Loc bot config details | |
run: | | |
git config --global user.name $APPROVE_BOT_NAME | |
git config --global user.email $APPROVE_BOT_EMAIL | |
- name: Approve pull requests | |
continue-on-error: true | |
run: | | |
mainFolder=$PWD | |
for folder in visuals/*; do | |
repoName=$(echo $folder| cut -d'/' -f 2) | |
echo "::group::Approve and merge to $repoName" | |
cd "$mainFolder/$folder" | |
pullRequestNumber=$(gh pr list --state=open --head=$BRANCH --json number) | |
if [[ $pullRequestNumber == "[]" ]]; then | |
echo "No pull request for $repoName" | |
continue | |
fi | |
originalBranchName=$(git remote show origin | sed -n '/HEAD branch/s/.*: //p') | |
if git show-ref --quiet refs/heads/dev; then | |
originalBranchName=dev | |
fi | |
changes="$(git diff origin/$originalBranchName)" | |
if [[ $changes == "" ]]; then | |
gh pr close -d $BRANCH | |
echo "No changes for $repoName" | |
continue | |
fi | |
gh pr review $BRANCH --approve || echo "Can't approve Pull Request to $repoName" | |
gh pr merge $BRANCH -s --auto -t "New translations" && | |
echo "Pull request to $repoName was merged" || echo "Cann't merge Pull Request to $repoName" | |
echo "::endgroup::" | |
done; | |
env: | |
GH_TOKEN: ${{secrets.APPROVE_TOKEN}} | |
BRANCH: ${{needs.update_en_localization.outputs.branch-name}} |