Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ jobs:
- name: Sync Python tools
env:
UV_PYTHON: ${{ steps.setup-python.outputs.python-path }}
run: uv sync --locked
run: uv sync --locked --only-group test-python

- name: Test with pytest
id: test
run: uv run --locked pytest
run: uv run --locked --only-group test-python pytest

- name: Upload test coverage
# any except canceled or skipped
Expand Down
140 changes: 140 additions & 0 deletions .github/workflows/localize.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
---
name: localize
permissions: {}

on:
workflow_call:
secrets:
github_token:
required: true

env:
PYTHON_VERSION: '3.14'

jobs:
localize:
name: Update Localization
permissions:
contents: read
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3

- name: Resolve shared workflow checkout
id: shared-workflow
env:
JOB_CONTEXT: ${{ toJSON(job) }}
run: |
repository="$(jq -r '.workflow_repository // empty' <<< "${JOB_CONTEXT}")"
sha="$(jq -r '.workflow_sha // empty' <<< "${JOB_CONTEXT}")"

if [ -z "${repository}" ] || [ -z "${sha}" ]; then
echo "Unable to resolve shared workflow repository and sha from job context." >&2
exit 1
fi

echo "repository=${repository}" >> "${GITHUB_OUTPUT}"
echo "sha=${sha}" >> "${GITHUB_OUTPUT}"

- name: Checkout lizardbyte-common
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
repository: ${{ steps.shared-workflow.outputs.repository }}
ref: ${{ steps.shared-workflow.outputs.sha }}
path: .lizardbyte-common

- name: Install Python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Setup uv
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
with:
enable-cache: true

- name: Sync Python tools
run: |
uv sync --project .lizardbyte-common --frozen --only-group locale \
--python "${PYTHON_VERSION}" \
--no-python-downloads \
--no-install-project

- name: Set up xgettext
run: |
sudo apt-get update -y &&
sudo apt-get --reinstall install -y \
gettext

- name: Resolve gettext template
id: template
run: |
repository_name="${GITHUB_REPOSITORY##*/}"
file="locale/${repository_name,,}.po"
echo "file=${file}" >> "${GITHUB_OUTPUT}"

- name: Update Strings
env:
FILE: ${{ steps.template.outputs.file }}
run: |
new_file=true

if [ -f "${FILE}" ]; then
rm "${FILE}"
new_file=false
fi
echo "NEW_FILE=${new_file}" >> "${GITHUB_ENV}"

uv run --project .lizardbyte-common --frozen --only-group locale --no-sync \
python .lizardbyte-common/scripts/localize.py --root-dir "${GITHUB_WORKSPACE}" --extract

- name: git diff
if: env.NEW_FILE == 'false'
env:
FILE: ${{ steps.template.outputs.file }}
run: |
git config --global pager.diff false
git diff -- "${FILE}"

output="$(git diff --numstat -- "${FILE}" | sed -e $'s#\t# #g')"
echo "GIT_DIFF=${output}" >> "${GITHUB_ENV}"

- name: git restore
if: env.NEW_FILE == 'false'
env:
FILE: ${{ steps.template.outputs.file }}
run: |
expected="1 1 ${FILE}"
if [ "${GIT_DIFF}" = "${expected}" ]; then
git restore -- "${FILE}"
fi

- name: Clean shared tools checkout
if: always()
run: rm -rf .lizardbyte-common

- name: Get current date
id: date
run: echo "date=$(date +'%Y-%m-%d')" >> "${GITHUB_OUTPUT}"

- name: Create/Update Pull Request
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
with:
add-paths: |
locale/*.po
token: ${{ secrets.github_token }}
commit-message: "chore(l10n): new babel updates"
branch: localize/update
delete-branch: true
base: master
title: "chore(l10n): new babel updates"
body: |
Update report
- Updated ${{ steps.date.outputs.date }}
- Auto-generated by [create-pull-request][1]

[1]: https://github.com/peter-evans/create-pull-request
labels: |
babel
l10n
46 changes: 42 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,66 @@

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

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

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

## Python Tooling

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

```bash
uv sync
uv sync --locked
```

Run the clang-format helper:

```bash
uv run python scripts/update_clang_format.py
uv run --locked python scripts/update_clang_format.py
```

Run gettext extraction:

```bash
uv run --locked --only-group locale python scripts/localize.py --extract
```

## Workflows

Reusable GitHub workflows live under `.github/workflows/`.

- `localize.yml` extracts gettext strings with the shared locale helper and can open a localization update pull request.

```yaml
name: localize
permissions: {}

on:
push:
branches:
- master
paths:
- '.github/workflows/localize.yml'
- 'src/**'
- 'locale/sunshine.po'
workflow_dispatch:

jobs:
localize:
name: Update Localization
permissions:
contents: read
uses: LizardByte/lizardbyte-common/.github/workflows/localize.yml@master
secrets:
github_token: ${{ secrets.GH_BOT_TOKEN }}
```

## Tests

Run the pytest suite:

```bash
uv run pytest
uv run --locked --only-group test-python pytest
```
26 changes: 21 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,29 @@ dependencies = []

[dependency-groups]
dev = [
{include-group = "lint"},
{include-group = "test"},
{include-group = "c"},
{include-group = "lint-python"},
{include-group = "test-python"},
]
lint = [
"clang-format==21.*",
c = [
{include-group = "lint-c"},
{include-group = "locale"},
{include-group = "test-c"},
]
test = [
lint-c = [
"clang-format==21.1.8",
"cmakelang==0.6.13",
]
lint-python = [
"flake8==7.3.0",
]
locale = [
"babel==2.18.0",
]
test-c = [
"gcovr==8.6",
]
test-python = [
"pytest==9.0.3",
"pytest-cov==7.1.0",
]
Expand Down
Loading
Loading