|
| 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 |
0 commit comments