Skip to content

remove the code chunk #9

remove the code chunk

remove the code chunk #9

Workflow file for this run

name: Create and Update Translation Branches and PRs
# This will run when there is a push to any English language branch
# With the format listed below.
on:
push:
branches:
- 'handbook_v*_en'
jobs:
create_and_update_translation_branches:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Git
run: |
git config --global user.name 'ntluong95'
git config --global user.email '[email protected]'
- name: Install GitHub CLI
run: |
sudo apt update
sudo apt install -y gh
- name: Create and update language branches and PRs
run: |
LANGS=("fr" "es" "vn" "jp" "tr" "pt" "ru")
EN_BRANCH="${{ github.ref }}"
VERSION_SUFFIX="${EN_BRANCH#refs/heads/handbook_}"
for lang in "${LANGS[@]}"; do
TRANSLATION_BRANCH="handbook_${VERSION_SUFFIX/_en/_$lang}"
# Check if the translation branch exists
if git ls-remote --exit-code --heads origin "${TRANSLATION_BRANCH}"; then
echo "Branch ${TRANSLATION_BRANCH} exists. Checking out and rebasing with ${EN_BRANCH}"
git checkout "${TRANSLATION_BRANCH}"
git pull origin "${TRANSLATION_BRANCH}"
# git pull origin "${EN_BRANCH}" --rebase
git rebase "origin/${EN_BRANCH#refs/heads/}"
else
echo "Branch ${TRANSLATION_BRANCH} does not exist. Creating new branch from ${EN_BRANCH}."
git checkout -b "${TRANSLATION_BRANCH}" "origin/${EN_BRANCH#refs/heads/}"
git push origin "${TRANSLATION_BRANCH}" --force
fi
# Ensure there are commits to be included in the PR
latest_commit_date=$(git show -s --format=%ci ${TRANSLATION_BRANCH})
commits=$(gh api repos/${{ github.repository }}/commits --paginate --jq ".[] | select(.commit.author.date > \"$latest_commit_date\") | .sha")
if [ -n "$commits" ]; then
# Check if a PR already exists for this branch
PR_EXISTS=$(gh pr list --head "${TRANSLATION_BRANCH}" --state open --json number --jq length)
if [ "$PR_EXISTS" -eq 0 ]; then
echo "Creating new PR for ${TRANSLATION_BRANCH}"
PR_URL=$(gh pr create --base main --head "$TRANSLATION_BRANCH" --title "Handbook ${VERSION_SUFFIX/_en/} $lang" --body "Automated pull request for $lang handbook version ${VERSION_SUFFIX/_en/}")
PR_NUMBER=$(echo "$PR_URL" | grep -oE '[0-9]+$')
else
# Get the PR number for the translation branch
echo "PR already exists for ${TRANSLATION_BRANCH}"
PR_NUMBER=$(gh pr list --head "${TRANSLATION_BRANCH}" --state open --json number --jq ".[0].number")
fi
echo "Pull Request Number: $PR_NUMBER"
# Add new commits as checkboxes to the PR description
checkboxes=""
for commit in $commits; do
checkboxes="$checkboxes\n- [ ] [$commit](https://github.com/${{ github.repository }}/commit/$commit)"
done
# Mention a user in the PR description
if [ "$lang" == "es" ]; then
checkboxes="$checkboxes @robcrystalornelas, please review."
fi
gh api repos/${{ github.repository }}/issues/$PR_NUMBER --method PATCH --field body="$checkboxes"
else
echo "No new commits to create a PR for ${TRANSLATION_BRANCH}"
fi
done
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}