From 88dd3ded20e2fd009070aa848ca3bc9623381975 Mon Sep 17 00:00:00 2001 From: Muhammad Yasirroni Date: Wed, 26 Jun 2024 07:20:13 +0700 Subject: [PATCH] merge build and update into single file --- .github/scripts/update_requirements.sh | 4 +- .github/workflows/build.yml | 29 ++++++++++++ .github/workflows/publish.yml | 4 +- .github/workflows/update.yml | 61 -------------------------- 4 files changed, 34 insertions(+), 64 deletions(-) delete mode 100644 .github/workflows/update.yml diff --git a/.github/scripts/update_requirements.sh b/.github/scripts/update_requirements.sh index d5e33f0..0b9e5c5 100644 --- a/.github/scripts/update_requirements.sh +++ b/.github/scripts/update_requirements.sh @@ -45,8 +45,10 @@ for version in "${PYTHON_VERSIONS[@]}"; do # Install pru into the virtual environment pip install pru - # Calculate checksums before running pru + # Get minor version minor_version=$(python${version} -c "import sys; print(f'{sys.version_info.minor}')") + + # Calculate checksums before running pru checksum_before_single=$(md5sum "pytests/requirements/3_${minor_version}/requirements_single_updated.txt" | cut -d ' ' -f 1) checksum_before_mix=$(md5sum "pytests/requirements/3_${minor_version}/requirements_mix_updated.txt" | cut -d ' ' -f 1) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 180e051..e9abad7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -78,3 +78,32 @@ jobs: - 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 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index c5c82a7..e8ba0d7 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -31,13 +31,13 @@ jobs: - name: Install package run: pip install -e ."[dev]" - - name: Test package + - name: Run tests id: pytest run: | python3 -m pytest . -c pyproject.toml continue-on-error: true - - name: Test package 2 + - name: Run tests with last failed id: pytest2 if: steps.pytest.outcome != 'success' run: | diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml deleted file mode 100644 index be93f66..0000000 --- a/.github/workflows/update.yml +++ /dev/null @@ -1,61 +0,0 @@ -name: update - -on: - pull_request: - -jobs: - update: - runs-on: ubuntu-latest - steps: - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: 3.8 - - - name: Check out repository - uses: actions/checkout@v4 - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install pru - - - name: Determine current branch - id: current_branch - run: echo "CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)" >> $GITHUB_ENV - - - name: Run requirements updater script - id: run_pru - run: | - bash .github/scripts/update_requirements.sh - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Configure git - 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]" - - - name: Create new branch - if: steps.run_pru.outputs.updated == 'true' - run: | - BRANCH_NAME="update-requirements-${GITHUB_RUN_ID}" - git checkout -b $BRANCH_NAME - echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV - echo "DATE=${{ steps.run_pru.outputs.update_date }}" >> $GITHUB_ENV - - - name: Commit changes - if: steps.run_pru.outputs.updated == 'true' - run: | - git add . - git commit -m "Update requirements based on failed tests at $DATE" - env: - DATE: ${{ steps.run_pru.outputs.update_date }} - - - name: Push changes - if: steps.run_pru.outputs.updated == 'true' - run: | - git push origin $BRANCH_NAME - env: - BRANCH_NAME: ${{ env.BRANCH_NAME }}