|
| 1 | +--- |
| 2 | +name: localize |
| 3 | +permissions: {} |
| 4 | + |
| 5 | +on: |
| 6 | + workflow_call: |
| 7 | + secrets: |
| 8 | + github_token: |
| 9 | + required: true |
| 10 | + |
| 11 | +env: |
| 12 | + PYTHON_VERSION: '3.14' |
| 13 | + |
| 14 | +jobs: |
| 15 | + localize: |
| 16 | + name: Update Localization |
| 17 | + permissions: |
| 18 | + contents: read |
| 19 | + runs-on: ubuntu-latest |
| 20 | + steps: |
| 21 | + - name: Checkout |
| 22 | + uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 |
| 23 | + |
| 24 | + - name: Resolve shared workflow checkout |
| 25 | + id: shared-workflow |
| 26 | + env: |
| 27 | + JOB_CONTEXT: ${{ toJSON(job) }} |
| 28 | + run: | |
| 29 | + repository="$(jq -r '.workflow_repository // empty' <<< "${JOB_CONTEXT}")" |
| 30 | + sha="$(jq -r '.workflow_sha // empty' <<< "${JOB_CONTEXT}")" |
| 31 | +
|
| 32 | + if [ -z "${repository}" ] || [ -z "${sha}" ]; then |
| 33 | + echo "Unable to resolve shared workflow repository and sha from job context." >&2 |
| 34 | + exit 1 |
| 35 | + fi |
| 36 | +
|
| 37 | + echo "repository=${repository}" >> "${GITHUB_OUTPUT}" |
| 38 | + echo "sha=${sha}" >> "${GITHUB_OUTPUT}" |
| 39 | +
|
| 40 | + - name: Checkout lizardbyte-common |
| 41 | + uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 |
| 42 | + with: |
| 43 | + repository: ${{ steps.shared-workflow.outputs.repository }} |
| 44 | + ref: ${{ steps.shared-workflow.outputs.sha }} |
| 45 | + path: .lizardbyte-common |
| 46 | + |
| 47 | + - name: Install Python |
| 48 | + uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 |
| 49 | + with: |
| 50 | + python-version: ${{ env.PYTHON_VERSION }} |
| 51 | + |
| 52 | + - name: Setup uv |
| 53 | + uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0 |
| 54 | + with: |
| 55 | + enable-cache: true |
| 56 | + |
| 57 | + - name: Sync Python tools |
| 58 | + run: | |
| 59 | + uv sync --project .lizardbyte-common --frozen --only-group locale \ |
| 60 | + --python "${PYTHON_VERSION}" \ |
| 61 | + --no-python-downloads \ |
| 62 | + --no-install-project |
| 63 | +
|
| 64 | + - name: Set up xgettext |
| 65 | + run: | |
| 66 | + sudo apt-get update -y && |
| 67 | + sudo apt-get --reinstall install -y \ |
| 68 | + gettext |
| 69 | +
|
| 70 | + - name: Resolve gettext template |
| 71 | + id: template |
| 72 | + run: | |
| 73 | + repository_name="${GITHUB_REPOSITORY##*/}" |
| 74 | + file="locale/${repository_name,,}.po" |
| 75 | + echo "file=${file}" >> "${GITHUB_OUTPUT}" |
| 76 | +
|
| 77 | + - name: Update Strings |
| 78 | + env: |
| 79 | + FILE: ${{ steps.template.outputs.file }} |
| 80 | + run: | |
| 81 | + new_file=true |
| 82 | +
|
| 83 | + if [ -f "${FILE}" ]; then |
| 84 | + rm "${FILE}" |
| 85 | + new_file=false |
| 86 | + fi |
| 87 | + echo "NEW_FILE=${new_file}" >> "${GITHUB_ENV}" |
| 88 | +
|
| 89 | + uv run --project .lizardbyte-common --frozen --only-group locale --no-sync \ |
| 90 | + python .lizardbyte-common/scripts/localize.py --root-dir "${GITHUB_WORKSPACE}" --extract |
| 91 | +
|
| 92 | + - name: git diff |
| 93 | + if: env.NEW_FILE == 'false' |
| 94 | + env: |
| 95 | + FILE: ${{ steps.template.outputs.file }} |
| 96 | + run: | |
| 97 | + git config --global pager.diff false |
| 98 | + git diff -- "${FILE}" |
| 99 | +
|
| 100 | + output="$(git diff --numstat -- "${FILE}" | sed -e $'s#\t# #g')" |
| 101 | + echo "GIT_DIFF=${output}" >> "${GITHUB_ENV}" |
| 102 | +
|
| 103 | + - name: git restore |
| 104 | + if: env.NEW_FILE == 'false' |
| 105 | + env: |
| 106 | + FILE: ${{ steps.template.outputs.file }} |
| 107 | + run: | |
| 108 | + expected="1 1 ${FILE}" |
| 109 | + if [ "${GIT_DIFF}" = "${expected}" ]; then |
| 110 | + git restore -- "${FILE}" |
| 111 | + fi |
| 112 | +
|
| 113 | + - name: Clean shared tools checkout |
| 114 | + if: always() |
| 115 | + run: rm -rf .lizardbyte-common |
| 116 | + |
| 117 | + - name: Get current date |
| 118 | + id: date |
| 119 | + run: echo "date=$(date +'%Y-%m-%d')" >> "${GITHUB_OUTPUT}" |
| 120 | + |
| 121 | + - name: Create/Update Pull Request |
| 122 | + uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1 |
| 123 | + with: |
| 124 | + add-paths: | |
| 125 | + locale/*.po |
| 126 | + token: ${{ secrets.github_token }} |
| 127 | + commit-message: "chore(l10n): new babel updates" |
| 128 | + branch: localize/update |
| 129 | + delete-branch: true |
| 130 | + base: master |
| 131 | + title: "chore(l10n): new babel updates" |
| 132 | + body: | |
| 133 | + Update report |
| 134 | + - Updated ${{ steps.date.outputs.date }} |
| 135 | + - Auto-generated by [create-pull-request][1] |
| 136 | +
|
| 137 | + [1]: https://github.com/peter-evans/create-pull-request |
| 138 | + labels: | |
| 139 | + babel |
| 140 | + l10n |
0 commit comments