Skip to content

Commit

Permalink
add test-requirements.sh and ci file
Browse files Browse the repository at this point in the history
  • Loading branch information
mahdikhashan committed Jan 14, 2025
1 parent bef7c34 commit 02fc4c7
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .github/resources/scripts/test-requirements.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bash

check_requirements() {
local req_in="$1"
local req_txt="$2"

temp_file=$(mktemp)

pip-compile --output-file=- "$req_in" > "$temp_file"

# Compare the generated file with the existing requirements.txt
if diff -q "$temp_file" "$req_txt" >/dev/null; then
echo "Success: $req_txt matches the output of pip-compile for $req_in."
rm "$temp_file"
exit 0
else
echo "Error: $req_txt does not match the output of pip-compile for $req_in."
echo "Differences:"
diff "$temp_file" "$req_txt"
rm "$temp_file"
exit 1
fi
}

for req_in_file in $(find . -name "requirements.in"); do

echo $req_in_file
req_txt="${req_in_file/requirements.in/requirements.txt}"

# Check if the corresponding requirements.txt exists
if [[ -f "$req_txt" ]]; then
echo "Checking $req_in_file against $req_txt..."
check_requirements "$req_in_file" "$req_txt"
else
echo "Error: $req_txt not found for $req_in_file."
exit 1
fi
done

echo "All checks completed successfully."
32 changes: 32 additions & 0 deletions .github/workflows/requirements-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Requirements generated tests

on:
push:
branches: [master]

pull_request:
paths:
- 'test/**'
- 'backend/**'
- 'sdk/**'

jobs:
requirements-generated-tests:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.9

- name: Install pip-tools
run: |
pip3 install pip-tools
- name: Run Tests
run: |
./.github/resources/scripts/test-requirements.sh

0 comments on commit 02fc4c7

Please sign in to comment.