Merge pull request #21 from yasirroni/auto_updater_on_fail #62
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: build | |
on: | |
pull_request: | |
push: | |
branches: | |
- main | |
jobs: | |
linters: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-python@v4 | |
with: | |
python-version: "3.12" | |
cache: 'pip' | |
cache-dependency-path: 'requirements.txt' | |
- name: Install Ruff | |
run: | | |
python -m pip install --upgrade pip | |
pip install ruff | |
- name: Run Ruff | |
run: ruff check . | |
build: | |
strategy: | |
fail-fast: false | |
matrix: | |
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Clone this repository | |
uses: actions/checkout@v4 | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v4 | |
with: | |
python-version: ${{ matrix.python-version }} | |
cache: 'pip' | |
cache-dependency-path: 'requirements.txt' | |
- name: Upgrade pip and install dependencies | |
run: python -m pip install --upgrade pip | |
- name: Install package | |
run: | | |
pip install -e ."[dev]" | |
pru | |
- name: Run tests | |
id: pytest | |
run: | | |
python3 -m pytest . -c pyproject.toml --cov-report term-missing --cov=src/pru | |
continue-on-error: true | |
- name: Run tests with last failed | |
id: pytest2 | |
if: steps.pytest.outcome != 'success' | |
run: | | |
python3 -m pytest . --lf -c pyproject.toml --cov-report term-missing --cov=src/pru | |
continue-on-error: true | |
- name: Run pru if tests fail | |
id: run_pru | |
if: steps.pytest.outcome != 'success' && steps.pytest2.outcome != 'success' | |
run: | | |
python_version_minor=$(python -c "import sys; print(f'{sys.version_info.minor}')") | |
pru -r pytests/requirements/3_${python_version_minor}/requirements_single.txt | |
pru -r pytests/requirements/3_${python_version_minor}/requirements_mix.txt | |
echo "Contents of pytests/requirements/3_${python_version_minor}/requirements_single.txt:" | |
cat pytests/requirements/3_${python_version_minor}/requirements_single.txt | |
echo "Contents of pytests/requirements/3_${python_version_minor}/requirements_mix.txt:" | |
cat pytests/requirements/3_${python_version_minor}/requirements_mix.txt | |
- name: Fail the job if tests fail | |
if: steps.pytest.outcome != 'success' && steps.pytest2.outcome != 'success' | |
run: exit 1 | |
update: | |
needs: build | |
if: needs.build.result != 'success' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: 3.12 | |
- name: Check out repository | |
uses: actions/checkout@v4 | |
- name: Run requirements updater script | |
id: run_pru | |
run: | | |
bash .github/scripts/update_requirements.sh | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Commit and push changes | |
if: steps.run_pru.outputs.updated == 'true' | |
run: | | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git config --global user.name "github-actions[bot]" | |
git add . | |
git commit -m "Update requirements based on failed tests at $(date)" | |
git push origin HEAD |