Skip to content

Commit 0139276

Browse files
feat(CI): 👷 Create a reusable workflow for UV and make UV lockfile frozen (#94)
Co-authored-by: Lala Sabathil <aiko@aitsys.dev>
1 parent ee374d7 commit 0139276

File tree

6 files changed

+100
-48
lines changed

6 files changed

+100
-48
lines changed

.github/actions/sync-uv/action.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: 'Sync UV Action'
2+
description: 'Install and sync UV with specified groups and extras'
3+
author: 'Pycord Development <admin@pycord.dev>'
4+
inputs:
5+
groups:
6+
description: "Comma-separated list of groups to sync"
7+
required: false
8+
default: ''
9+
extras:
10+
description: "Comma-separated list of extras to sync"
11+
required: false
12+
default: ''
13+
frozen:
14+
description: "Whether to sync with frozen dependencies"
15+
required: false
16+
default: 'true'
17+
no_python_downloads:
18+
description: "Whether to avoid downloading Python versions"
19+
required: false
20+
default: 'true'
21+
22+
runs:
23+
using: "composite"
24+
steps:
25+
- name: "Install uv"
26+
uses: astral-sh/setup-uv@v6
27+
with:
28+
enable-cache: true
29+
30+
- name: "Run UV sync"
31+
shell: bash
32+
run: |
33+
cmd_args=("uv" "sync")
34+
35+
# groups
36+
set +e
37+
if [ -n "${{ inputs.groups }}" ]; then
38+
IFS=',' read -ra PARSED_GROUPS <<< "${{ inputs.groups }}"
39+
for group in "${PARSED_GROUPS[@]}"; do
40+
group=$(echo "$group" | xargs)
41+
if [ -n "$group" ]; then
42+
cmd_args+=("--group" "$group")
43+
fi
44+
done
45+
fi
46+
set -e
47+
echo "Groups: ${PARSED_GROUPS[*]}"
48+
49+
# extras
50+
set +e
51+
if [ -n "${{ inputs.extras }}" ]; then
52+
IFS=',' read -ra PARSED_EXTRAS <<< "${{ inputs.extras }}"
53+
for extra in "${PARSED_EXTRAS[@]}"; do
54+
extra=$(echo "$extra" | xargs)
55+
if [ -n "$extra" ]; then
56+
cmd_args+=("--extra" "$extra")
57+
fi
58+
done
59+
fi
60+
set -e
61+
echo "Extras: ${PARSED_EXTRAS[*]}"
62+
63+
echo "Executing: ${cmd_args[*]}"
64+
"${cmd_args[@]}"
65+
env:
66+
UV_NO_PYTHON_DOWNLOADS: ${{ inputs.no_python_downloads == 'true' && '1' || '' }}
67+
UV_FROZEN: ${{ inputs.frozen == 'true' && '1' || '' }}

.github/workflows/docs-checks.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,11 @@ jobs:
4040
- name: "Setup Python"
4141
uses: actions/setup-python@v6
4242
with:
43-
python-version: "3.14"
44-
- name: "Install uv"
45-
uses: astral-sh/setup-uv@v7
43+
python-version: "3.13"
44+
- name: "Setup UV"
45+
uses: ./.github/actions/sync-uv
4646
with:
47-
enable-cache: true
48-
- name: Sync dependencies
49-
run: uv sync --no-python-downloads --group dev --group docs
47+
groups: 'dev,docs'
5048
- name: "Check Links"
5149
env:
5250
SPHINXBUILD: ${{ github.workspace }}/.venv/bin/sphinx-build

.github/workflows/docs-localization-download.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,12 @@ jobs:
1919
- name: "Setup Python"
2020
uses: actions/setup-python@v6
2121
with:
22-
python-version: "3.14"
23-
- name: "Install uv"
24-
uses: astral-sh/setup-uv@v7
22+
python-version: "3.13"
23+
- name: "Setup UV"
24+
uses: ./.github/actions/sync-uv
2525
with:
26-
enable-cache: true
27-
- name: Sync dependencies
28-
run: uv sync --no-python-downloads --group dev --group docs --extra speed --extra voice
26+
groups: 'dev,docs'
27+
extras: 'speed,voice'
2928
- name: "Get locales"
3029
env:
3130
SPHINXBUILD: ${{ github.workspace }}/.venv/bin/sphinx-build

.github/workflows/docs-localization-upload.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,12 @@ jobs:
2424
- name: "Setup Python"
2525
uses: actions/setup-python@v6
2626
with:
27-
python-version: "3.14"
28-
- name: "Install uv"
29-
uses: astral-sh/setup-uv@v7
27+
python-version: "3.13"
28+
- name: "Setup UV"
29+
uses: ./.github/actions/sync-uv
3030
with:
31-
enable-cache: true
32-
- name: Sync dependencies
33-
run: uv sync --no-python-downloads --group dev --group docs --extra speed --extra voice
31+
groups: 'dev,docs'
32+
extras: 'speed,voice'
3433
- name: "Get locales"
3534
env:
3635
SPHINXBUILD: ${{ github.workspace }}/.venv/bin/sphinx-build

.github/workflows/lib-checks.yml

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,11 @@ jobs:
4040
- name: "Setup Python"
4141
uses: actions/setup-python@v6
4242
with:
43-
python-version: "3.14"
44-
- name: "Install uv"
45-
uses: astral-sh/setup-uv@v7
43+
python-version: "3.13"
44+
- name: "Setup UV"
45+
uses: ./.github/actions/sync-uv
4646
with:
47-
enable-cache: true
48-
- name: Sync dependencies
49-
run: uv sync --no-python-downloads --group dev
47+
groups: 'dev'
5048
- name: "Run codespell"
5149
run:
5250
uv run codespell --ignore-words-list="groupt,nd,ot,ro,falsy,BU" \
@@ -60,13 +58,11 @@ jobs:
6058
- name: "Setup Python"
6159
uses: actions/setup-python@v6
6260
with:
63-
python-version: "3.14"
64-
- name: "Install uv"
65-
uses: astral-sh/setup-uv@v7
61+
python-version: "3.13"
62+
- name: "Setup UV"
63+
uses: ./.github/actions/sync-uv
6664
with:
67-
enable-cache: true
68-
- name: Sync dependencies
69-
run: uv sync --no-python-downloads --group dev
65+
groups: 'dev'
7066
- name: "Run ruff linter check"
7167
run: uv run ruff check .
7268
- name: "Run ruff formatter check"
@@ -80,13 +76,11 @@ jobs:
8076
- name: "Setup Python"
8177
uses: actions/setup-python@v6
8278
with:
83-
python-version: "3.14"
84-
- name: "Install uv"
85-
uses: astral-sh/setup-uv@v7
79+
python-version: "3.13"
80+
- name: "Setup UV"
81+
uses: ./.github/actions/sync-uv
8682
with:
87-
enable-cache: true
88-
- name: Sync dependencies
89-
run: uv sync --no-python-downloads --group dev
83+
groups: 'dev'
9084
- name: "Setup cache"
9185
id: cache-mypy
9286
uses: actions/cache@v4
@@ -114,13 +108,10 @@ jobs:
114108
with:
115109
python-version: ${{ matrix.python-version }}
116110

117-
- name: "Install uv"
118-
uses: astral-sh/setup-uv@v7
111+
- name: "Setup UV"
112+
uses: ./.github/actions/sync-uv
119113
with:
120-
enable-cache: true
121-
122-
- name: Sync dependencies
123-
run: uv sync --no-python-downloads --group dev
114+
groups: 'dev'
124115

125116
- name: "Run tests"
126117
run: uv run tox

.github/workflows/sync-guild-features.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,11 @@ jobs:
2323
- name: "Setup Python"
2424
uses: actions/setup-python@v6
2525
with:
26-
python-version: "3.14"
27-
- name: "Install uv"
28-
uses: astral-sh/setup-uv@v7
26+
python-version: "3.13"
27+
- name: "Setup UV"
28+
uses: ./.github/actions/sync-uv
2929
with:
30-
enable-cache: true
31-
- name: Sync dependencies
32-
run: uv sync --no-python-downloads --group dev --group ci
30+
groups: 'dev,ci'
3331
- name: "Run guild features sync"
3432
run: uv run python -m scripts.sync_guild_features
3533
env:

0 commit comments

Comments
 (0)