Skip to content

Commit 59de44c

Browse files
feat: convert to a uv based workflow
1 parent 1339292 commit 59de44c

File tree

16 files changed

+3240
-242
lines changed

16 files changed

+3240
-242
lines changed

.github/workflows/ci.yml

Lines changed: 27 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -31,31 +31,24 @@
3131
"uses": "actions/checkout@v2"
3232
},
3333
{
34-
"name": "Set up Python ${{ matrix.python-version }}",
35-
"uses": "actions/setup-python@v5",
36-
"with": {
37-
"python-version": "${{ matrix.python-version }}"
38-
}
34+
"name": "Set up uv",
35+
"uses": "astral-sh/setup-uv@v5"
3936
},
4037
{
41-
"name": "Set up pip cache",
42-
"uses": "actions/cache@v4",
43-
"with": {
44-
"path": "~/.cache/pip",
45-
"key": "pip-${{ matrix.python-version }}"
46-
}
38+
"name": "Set up Python ${{ matrix.python-version }}",
39+
"run": "uv python install ${{ matrix.python-version }}"
4740
},
4841
{
4942
"name": "Set up packages",
50-
"run": "set -e\n\npip install -U pip setuptools wheel\npip install -U \\\n pre-commit coveralls pyyaml pytest-django\npip install -U -r requirements.txt\n\necho \"PATH=$PATH\" >> $GITHUB_ENV\n"
43+
"run": "uv sync --group ci --locked"
5144
},
5245
{
5346
"name": "Copy secret.py",
5447
"run": "cp intranet/settings/ci_secret.py intranet/settings/secret.py"
5548
},
5649
{
5750
"name": "Run pre-commit",
58-
"run": "pre-commit run --all-files"
51+
"run": "uv run pre-commit run --all-files"
5952
}
6053
]
6154
},
@@ -78,57 +71,47 @@
7871
}
7972
},
8073
{
81-
"name": "Set up Python ${{ matrix.python-version }}",
82-
"uses": "actions/setup-python@v5",
83-
"with": {
84-
"python-version": "${{ matrix.python-version }}"
85-
}
74+
"name": "Set up uv",
75+
"uses": "astral-sh/setup-uv@v5"
8676
},
8777
{
88-
"name": "Set up pip cache",
89-
"uses": "actions/cache@v4",
90-
"with": {
91-
"path": "~/.cache/pip",
92-
"key": "pip-${{ matrix.python-version }}"
93-
}
78+
"name": "Set up Python ${{ matrix.python-version }}",
79+
"run": "uv python install ${{ matrix.python-version }}"
9480
},
9581
{
9682
"name": "Set up packages",
97-
"run": "set -e\n\npip install -U pip setuptools wheel\npip install -U \\\n pre-commit coveralls pyyaml pytest-django\npip install -U -r requirements.txt\n\necho \"PATH=$PATH\" >> $GITHUB_ENV\n"
83+
"run": "uv sync --group ci --locked"
9884
},
9985
{
10086
"name": "Copy secret.py",
10187
"run": "cp intranet/settings/ci_secret.py intranet/settings/secret.py"
10288
},
10389
{
10490
"name": "Regenerate workflow YAML file and check for changes",
105-
"run": "./scripts/build_ensure_no_changes.sh ./ci/regen-workflow.py"
91+
"run": "uv run ./scripts/build_ensure_no_changes.sh ./ci/regen-workflow.py"
10692
},
10793
{
10894
"name": "Check for changes to CI spec",
109-
"run": "./scripts/build_ensure_no_changes.sh ./ci/regen-workflow.py"
95+
"run": "uv run ./scripts/build_ensure_no_changes.sh ./ci/regen-workflow.py"
11096
},
11197
{
11298
"name": "Validate PR commit messages",
11399
"if": "github.event_name == 'pull_request'",
114-
"run": "./scripts/validate-commit-messages.py ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }}"
100+
"run": "uv run ./scripts/validate-commit-messages.py ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }}"
115101
},
116102
{
117103
"name": "Validate push commit messages",
118104
"if": "github.event_name == 'push' && (github.repository_owner != 'tjcsl' || github.ref != 'refs/heads/master' || github.ref != 'refs/heads/dev')",
119105
"run": "git fetch origin ${{ github.event.before }} && ./scripts/validate-commit-messages.py ${{ github.event.before }}..${{ github.event.after }}"
120106
},
121-
{
122-
"name": "Install docs dependencies",
123-
"run": "# sphinxcontrib_django imports our django project, so we need the deps\npip install -U -r requirements.txt\ncd docs\npip install -U -r requirements.txt\n"
124-
},
125107
{
126108
"name": "Check docs build up to date",
127109
"run": "./scripts/build_ensure_no_changes.sh python3 scripts/build_docs.py"
128110
},
129111
{
130112
"name": "Build docs",
131-
"run": "cd docs\nmake html\n"
113+
"workding_dir": "docs",
114+
"run": "uv run make html"
132115
},
133116
{
134117
"name": "Push docs",
@@ -187,23 +170,16 @@
187170
"uses": "actions/checkout@v2"
188171
},
189172
{
190-
"name": "Set up Python ${{ matrix.python-version }}",
191-
"uses": "actions/setup-python@v5",
192-
"with": {
193-
"python-version": "${{ matrix.python-version }}"
194-
}
173+
"name": "Set up uv",
174+
"uses": "astral-sh/setup-uv@v5"
195175
},
196176
{
197-
"name": "Set up pip cache",
198-
"uses": "actions/cache@v4",
199-
"with": {
200-
"path": "~/.cache/pip",
201-
"key": "pip-${{ matrix.python-version }}"
202-
}
177+
"name": "Set up Python ${{ matrix.python-version }}",
178+
"run": "uv python install ${{ matrix.python-version }}"
203179
},
204180
{
205181
"name": "Set up packages",
206-
"run": "set -e\n\npip install -U pip setuptools wheel\npip install -U \\\n pre-commit coveralls pyyaml pytest-django\npip install -U -r requirements.txt\n\necho \"PATH=$PATH\" >> $GITHUB_ENV\n"
182+
"run": "uv sync --group ci --locked"
207183
},
208184
{
209185
"name": "Copy secret.py",
@@ -235,24 +211,24 @@
235211
{
236212
"name": "Run tests (Fork)",
237213
"if": "github.repository_owner != 'tjcsl'",
238-
"run": "coverage run -a ./manage.py test --noinput --parallel 4"
214+
"run": "uv run coverage run -a ./manage.py test --noinput --parallel 4"
239215
},
240216
{
241217
"name": "Run tests (PR/Push)",
242218
"if": "github.repository_owner == 'tjcsl'",
243-
"run": "coverage run -a ./manage.py test --noinput"
219+
"run": "uv run coverage run -a ./manage.py test --noinput"
244220
},
245221
{
246222
"name": "Check for unmigrated changes",
247-
"run": "coverage run -a ./manage.py makemigrations --noinput --check"
223+
"run": "uv run coverage run -a ./manage.py makemigrations --noinput --check"
248224
},
249225
{
250226
"name": "Migrate database",
251-
"run": "coverage run -a ./manage.py migrate"
227+
"run": "uv run coverage run -a ./manage.py migrate"
252228
},
253229
{
254230
"name": "Collect static files",
255-
"run": "coverage run -a ./manage.py collectstatic --noinput -v 0"
231+
"run": "uv run coverage run -a ./manage.py collectstatic --noinput -v 0"
256232
},
257233
{
258234
"name": "Report coverage to Coveralls",
@@ -264,7 +240,7 @@
264240
{
265241
"name": "Build coverage XML file",
266242
"if": "github.repository_owner == 'tjcsl' && github.event_name != 'pull_request'",
267-
"run": "coverage xml"
243+
"run": "uv run coverage xml"
268244
},
269245
{
270246
"name": "Report coverage to Codacy",

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.8

ci/spec.yml

Lines changed: 24 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@ env:
2727
node_versions: &node_versions
2828
- 14.x
2929

30-
python_setup: &python_setup
31-
name: Set up Python ${{ matrix.python-version }}
32-
uses: actions/setup-python@v5
33-
with:
34-
python-version: ${{ matrix.python-version }}
35-
3630
repo_setup: &repo_setup
3731
name: Set up repo
3832
uses: actions/checkout@v2
@@ -43,24 +37,17 @@ env:
4337
with:
4438
fetch-depth: 0
4539

46-
setup_pip_cache: &setup_pip_cache
47-
name: Set up pip cache
48-
uses: actions/cache@v4
49-
with:
50-
path: ~/.cache/pip
51-
key: pip-${{ matrix.python-version }}
40+
setup_uv_cache: &setup_uv_cache
41+
name: Set up uv
42+
uses: astral-sh/setup-uv@v5
43+
44+
python_setup: &python_setup
45+
name: Set up Python ${{ matrix.python-version }}
46+
run: uv python install ${{ matrix.python-version }}
5247

5348
setup_packages: &setup_packages
5449
name: Set up packages
55-
run: |
56-
set -e
57-
58-
pip install -U pip setuptools wheel
59-
pip install -U \
60-
pre-commit coveralls pyyaml pytest-django
61-
pip install -U -r requirements.txt
62-
63-
echo "PATH=$PATH" >> $GITHUB_ENV
50+
run: uv sync --group ci --locked
6451

6552
.copy_secret: &copy_secret
6653
name: Copy secret.py
@@ -77,13 +64,13 @@ jobs:
7764

7865
steps:
7966
- *repo_setup
67+
- *setup_uv_cache
8068
- *python_setup
81-
- *setup_pip_cache
8269
- *setup_packages
8370
- *copy_secret
8471

8572
- name: Run pre-commit
86-
run: 'pre-commit run --all-files'
73+
run: 'uv run pre-commit run --all-files'
8774

8875
build:
8976
runs-on: ubuntu-latest
@@ -96,43 +83,34 @@ jobs:
9683
steps:
9784
# We need the full history so we can validate commit messages.
9885
- *repo_setup_fetch_all
86+
- *setup_uv_cache
9987
- *python_setup
100-
- *setup_pip_cache
10188
- *setup_packages
10289
- *copy_secret
10390

10491
- name: Regenerate workflow YAML file and check for changes
105-
run: ./scripts/build_ensure_no_changes.sh ./ci/regen-workflow.py
92+
run: uv run ./scripts/build_ensure_no_changes.sh ./ci/regen-workflow.py
10693

10794
# Check for changes to CI spec
10895
- name: Check for changes to CI spec
109-
run: ./scripts/build_ensure_no_changes.sh ./ci/regen-workflow.py
96+
run: uv run ./scripts/build_ensure_no_changes.sh ./ci/regen-workflow.py
11097

11198
# Validate commit messages
11299
- name: Validate PR commit messages
113100
# Validate commit messages for PRs
114101
if: "github.event_name == 'pull_request'"
115-
run: ./scripts/validate-commit-messages.py ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }}
102+
run: uv run ./scripts/validate-commit-messages.py ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }}
116103
- name: Validate push commit messages
117104
# Validate commit messages for forks and branches that aren't dev or master
118105
if: "github.event_name == 'push' && (github.repository_owner != 'tjcsl' || github.ref != 'refs/heads/master' || github.ref != 'refs/heads/dev')"
119106
run: 'git fetch origin ${{ github.event.before }} && ./scripts/validate-commit-messages.py ${{ github.event.before }}..${{ github.event.after }}'
120107

121-
# Build/push docs
122-
- name: Install docs dependencies
123-
run: |
124-
# sphinxcontrib_django imports our django project, so we need the deps
125-
pip install -U -r requirements.txt
126-
cd docs
127-
pip install -U -r requirements.txt
128-
129108
- name: Check docs build up to date
130109
run: ./scripts/build_ensure_no_changes.sh python3 scripts/build_docs.py
131110

132111
- name: Build docs
133-
run: |
134-
cd docs
135-
make html
112+
workding_dir: docs
113+
run: uv run make html
136114

137115
- name: Push docs
138116
# Only run for pushes to the main Ion repo
@@ -177,8 +155,8 @@ jobs:
177155

178156
steps:
179157
- *repo_setup
158+
- *setup_uv_cache
180159
- *python_setup
181-
- *setup_pip_cache
182160
- *setup_packages
183161
- *copy_secret
184162

@@ -210,20 +188,21 @@ jobs:
210188
sudo apt update
211189
sudo apt install -y krb5-user
212190
191+
213192
# Tests
214193
- name: Run tests (Fork)
215194
if: github.repository_owner != 'tjcsl'
216-
run: coverage run -a ./manage.py test --noinput --parallel 4
195+
run: uv run coverage run -a ./manage.py test --noinput --parallel 4
217196
- name: Run tests (PR/Push)
218197
if: github.repository_owner == 'tjcsl' # Run single-threaded for accurate coverage reporting on Ion GitHub
219-
run: coverage run -a ./manage.py test --noinput
198+
run: uv run coverage run -a ./manage.py test --noinput
220199
# Check for unmigrated changes
221200
- name: Check for unmigrated changes
222-
run: coverage run -a ./manage.py makemigrations --noinput --check
201+
run: uv run coverage run -a ./manage.py makemigrations --noinput --check
223202
- name: Migrate database
224-
run: coverage run -a ./manage.py migrate
203+
run: uv run coverage run -a ./manage.py migrate
225204
- name: Collect static files
226-
run: coverage run -a ./manage.py collectstatic --noinput -v 0
205+
run: uv run coverage run -a ./manage.py collectstatic --noinput -v 0
227206

228207
# Coveralls
229208
- name: Report coverage to Coveralls
@@ -234,7 +213,7 @@ jobs:
234213
# Codacy
235214
- name: Build coverage XML file
236215
if: github.repository_owner == 'tjcsl' && github.event_name != 'pull_request'
237-
run: coverage xml
216+
run: uv run coverage xml
238217
- name: Report coverage to Codacy
239218
uses: codacy/codacy-coverage-reporter-action@master
240219
if: github.repository_owner == 'tjcsl' && github.event_name != 'pull_request'

config/docker/Dockerfile

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
FROM python:3.8.19-alpine3.18
22

3-
ENV TZ America/New_York
4-
ENV C_FORCE_ROOT true
3+
ENV TZ=America/New_York
4+
ENV C_FORCE_ROOT=true
5+
ENV UV_LINK_MODE=copy \
6+
UV_COMPILE_BYTECODE=1 \
7+
UV_PYTHON_DOWNLOADS=never \
8+
UV_PROJECT_ENVIRONMENT=/venv
59

610
COPY config/krb5.conf /etc/krb5.conf
7-
COPY requirements.txt .
8-
COPY requirements-dev.txt .
11+
COPY pyproject.toml .
12+
COPY uv.lock .
13+
14+
COPY --from=ghcr.io/astral-sh/uv:0.6 /uv /bin/uv
915

1016
RUN apk update && \
1117
apk add bash git curl build-base libpq-dev freetype-dev libffi-dev ruby-full libmagic krb5 kinit rsync nodejs npm tzdata libxml2-dev libxslt-dev && \
1218
npm install -g sass && \
1319
ln -s /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && \
14-
pip3 install -Ir requirements.txt && \
15-
pip3 install -Ir requirements-dev.txt && \
16-
rm requirements.txt requirements-dev.txt
20+
uv sync
1721

1822
WORKDIR /ion

config/docker/docker-compose.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
version: '3.9'
2-
31
services:
42
redis:
53
container_name: intranet_redis
@@ -56,7 +54,7 @@ services:
5654
"/bin/sh",
5755
"-c",
5856
"git config --global --add safe.directory /ion && \
59-
celery --app intranet worker -l info --without-gossip --without-mingle --without-heartbeat -Ofair"
57+
uv run celery --app intranet worker -l info --without-gossip --without-mingle --without-heartbeat -Ofair"
6058
]
6159
depends_on:
6260
- django
@@ -73,7 +71,7 @@ services:
7371
"/bin/sh",
7472
"-c",
7573
"git config --global --add safe.directory /ion && \
76-
celery --app intranet beat -l info"
74+
uv run celery --app intranet beat -l info"
7775
]
7876
depends_on:
7977
- django

config/docker/entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ export PYTHONUNBUFFERED=1 # Don't buffer Django output
1212
# Wrap the run command in a loop so that it restarts if it crashes, e.g. due to a syntax error
1313
while true
1414
do
15-
python3 manage.py run 0.0.0.0:8080 # Custom run command that skips system checks for performance
15+
uv run manage.py run 0.0.0.0:8080 # Custom run command that skips system checks for performance
1616
sleep 1
1717
done

0 commit comments

Comments
 (0)