Skip to content

Commit fd6c6b4

Browse files
feat(python): add locale script and more c deps (#4)
1 parent ad923ba commit fd6c6b4

9 files changed

Lines changed: 1635 additions & 18 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ jobs:
7171
- name: Sync Python tools
7272
env:
7373
UV_PYTHON: ${{ steps.setup-python.outputs.python-path }}
74-
run: uv sync --locked
74+
run: uv sync --locked --only-group test-python
7575

7676
- name: Test with pytest
7777
id: test
78-
run: uv run --locked pytest
78+
run: uv run --locked --only-group test-python pytest
7979

8080
- name: Upload test coverage
8181
# any except canceled or skipped

.github/workflows/localize.yml

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
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

README.md

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,66 @@
1212

1313
This repository contains shared helper scripts and repository-level tooling used across LizardByte projects.
1414

15-
The current tooling is focused on Python-managed C/C++ formatting helpers:
15+
The current tooling includes Python-managed helpers and reusable GitHub workflows:
1616

1717
- `scripts/update_clang_format.py` runs `clang-format` across supported source directories.
18+
- `scripts/localize.py` updates gettext and Babel locale files.
19+
- `.github/workflows/localize.yml` runs the locale helper from GitHub Actions and opens localization update pull requests.
1820

1921
## Python Tooling
2022

2123
Install [uv](https://docs.astral.sh/uv/) and sync the locked tool environment:
2224

2325
```bash
24-
uv sync
26+
uv sync --locked
2527
```
2628

2729
Run the clang-format helper:
2830

2931
```bash
30-
uv run python scripts/update_clang_format.py
32+
uv run --locked python scripts/update_clang_format.py
33+
```
34+
35+
Run gettext extraction:
36+
37+
```bash
38+
uv run --locked --only-group locale python scripts/localize.py --extract
39+
```
40+
41+
## Workflows
42+
43+
Reusable GitHub workflows live under `.github/workflows/`.
44+
45+
- `localize.yml` extracts gettext strings with the shared locale helper and can open a localization update pull request.
46+
47+
```yaml
48+
name: localize
49+
permissions: {}
50+
51+
on:
52+
push:
53+
branches:
54+
- master
55+
paths:
56+
- '.github/workflows/localize.yml'
57+
- 'src/**'
58+
- 'locale/sunshine.po'
59+
workflow_dispatch:
60+
61+
jobs:
62+
localize:
63+
name: Update Localization
64+
permissions:
65+
contents: read
66+
uses: LizardByte/lizardbyte-common/.github/workflows/localize.yml@master
67+
secrets:
68+
github_token: ${{ secrets.GH_BOT_TOKEN }}
3169
```
3270
3371
## Tests
3472
3573
Run the pytest suite:
3674
3775
```bash
38-
uv run pytest
76+
uv run --locked --only-group test-python pytest
3977
```

pyproject.toml

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,29 @@ dependencies = []
1515

1616
[dependency-groups]
1717
dev = [
18-
{include-group = "lint"},
19-
{include-group = "test"},
18+
{include-group = "c"},
19+
{include-group = "lint-python"},
20+
{include-group = "test-python"},
2021
]
21-
lint = [
22-
"clang-format==21.*",
22+
c = [
23+
{include-group = "lint-c"},
24+
{include-group = "locale"},
25+
{include-group = "test-c"},
2326
]
24-
test = [
27+
lint-c = [
28+
"clang-format==21.1.8",
29+
"cmakelang==0.6.13",
30+
]
31+
lint-python = [
32+
"flake8==7.3.0",
33+
]
34+
locale = [
35+
"babel==2.18.0",
36+
]
37+
test-c = [
38+
"gcovr==8.6",
39+
]
40+
test-python = [
2541
"pytest==9.0.3",
2642
"pytest-cov==7.1.0",
2743
]

0 commit comments

Comments
 (0)