Skip to content

Commit 8845a42

Browse files
authored
Update CI versions and add requirements.txt check (#16)
## Describe your changes Update CI versions and add `requirements.txt` checks for feature branch vs. `main`.
1 parent 60e8457 commit 8845a42

File tree

6 files changed

+261
-28
lines changed

6 files changed

+261
-28
lines changed

.github/workflows/format-and-fail.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
pre-commit:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v3
12+
- uses: actions/checkout@v4
1313
- uses: actions/setup-python@v4
1414
with:
1515
python-version: "3.11"
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Validate requirements.txt
2+
on:
3+
push:
4+
branches: [ main ]
5+
pull_request:
6+
branches: [ main ]
7+
8+
jobs:
9+
validate-dependencies:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: checkout code
13+
uses: actions/checkout@v4
14+
with:
15+
fetch-depth: 0
16+
17+
- name: fetch all history
18+
run: git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/*
19+
20+
- name: check for changes in pyproject.toml and poetry.lock
21+
id: check-deps
22+
run: |
23+
echo "Checking pyproject.toml and poetry.lock for changes..."
24+
BASE_BRANCH=${{ github.event.pull_request.base.ref }}
25+
HEAD_BRANCH=${{ github.event.pull_request.head.ref }}
26+
CHANGES=$(git diff --name-only origin/$BASE_BRANCH -- origin/$HEAD_BRANCH | grep -E "^(pyproject.toml|poetry.lock)$" || true)
27+
echo "Changed files: $CHANGES"
28+
if [ ! -z "$CHANGES" ]; then
29+
echo "Checking if requirements.txt has also been updated..."
30+
if ! git diff --name-only origin/$BASE_BRANCH -- origin/$HEAD_BRANCH | grep -q "requirements.txt"; then
31+
echo "ERROR: pyproject.toml or poetry.lock has changed, but requirements.txt has not been updated."
32+
echo "Please update requirements.txt by running 'make create-requirements'."
33+
exit 1
34+
fi
35+
fi
36+
37+
- name: validate requirements.txt update
38+
if: steps.check-deps.outputs.poetry_updated == 'true'
39+
run: |
40+
BASE_BRANCH=${{ github.event.pull_request.base.ref }}
41+
HEAD_BRANCH=${{ github.event.pull_request.head.ref }}
42+
REQUIREMENTS_CHANGE=$(git diff --name-only origin/$BASE_BRANCH -- origin/$HEAD_BRANCH | grep -q "requirements.txt")
43+
echo "requirements.txt changed: $REQUIREMENTS_CHANGE"
44+
if [ ! -z "$REQUIREMENTS_CHANGE" ]; then
45+
echo "requirements.txt updated correctly."
46+
else
47+
echo "ERROR: pyproject.toml or poetry.lock has changed, but requirements.txt has not been updated."
48+
echo "Please update requirements.txt by running 'make create-requirements'."
49+
exit 1
50+
fi

.github/workflows/run-tests.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ on:
88
jobs:
99
Test:
1010
runs-on: ubuntu-latest
11+
strategy:
12+
matrix:
13+
python-version: [ '3.11', '3.12' ]
1114
steps:
12-
- uses: actions/checkout@v2
13-
- uses: actions/setup-python@v2
15+
- uses: actions/checkout@v4
16+
- uses: actions/setup-python@v4
1417
with:
15-
python-version: 3.11
18+
python-version: ${{ matrix.python-version }}
1619
- name: Cache Poetry install
1720
uses: actions/cache@v2
1821
with:

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ repos:
6060
- --line-length=80
6161

6262
- repo: https://github.com/astral-sh/ruff-pre-commit
63-
rev: v0.4.3
63+
rev: v0.4.5
6464
hooks:
6565
- id: ruff
6666
types_or: [python, pyi, jupyter]

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ lint:
88

99
.PHONY: create-requirements
1010
create-requirements:
11-
poetry export --without-hashes --format=requirements.txt > requirements.txt
11+
poetry export --format=requirements.txt > requirements.txt
1212

1313
.PHONY: test
1414
test:

0 commit comments

Comments
 (0)