From 9c472acd02518f83799f449a4985ea1514950fe1 Mon Sep 17 00:00:00 2001 From: firelight flagboy Date: Tue, 12 Sep 2023 12:10:09 +0200 Subject: [PATCH] Only run python check style when modified any python file that isn't related to parsec-server --- .github/filters/ci.yml | 7 +++++-- .github/workflows/ci-python.yml | 25 ++++++++++++++++++++++--- .github/workflows/ci.yml | 17 ++++++++++++++--- 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/.github/filters/ci.yml b/.github/filters/ci.yml index e702e160c90..3cad029cca7 100644 --- a/.github/filters/ci.yml +++ b/.github/filters/ci.yml @@ -34,7 +34,10 @@ rust-jobs: # PYTHON # ########## -python: &python +any-python-files: &any-python-files + - "**.py" + +python-server: &python-server - server/parsec/** - server/tests/** - make.py @@ -47,7 +50,7 @@ python-dependencies-project: &python-dependencies-project python-changes: &python-changes - *python-dependencies-project - - *python + - *python-server # The python jobs need to be run when: # - The ci workflow has changed diff --git a/.github/workflows/ci-python.yml b/.github/workflows/ci-python.yml index 6f972a9c4dc..455396f2922 100644 --- a/.github/workflows/ci-python.yml +++ b/.github/workflows/ci-python.yml @@ -2,7 +2,19 @@ name: CI Python on: workflow_call: + inputs: + style-only: + description: Only check the python code style (don't run test) + required: true + default: false + type: boolean workflow_dispatch: + inputs: + style-only: + description: Only check the python code style (don't run test) + required: true + default: false + type: boolean # We set `concurrency` to prevent having this workflow being run on code that is not up-to-date on a PR (a user make multiple push in a quick manner). # But on the main branch, we don't want that behavior. @@ -42,6 +54,7 @@ jobs: timeout-minutes: 5 - name: Set apt mirror + if: !inputs.style-only # GitHub Actions apt proxy is super unstable # see https://github.com/actions/runner-images/issues/7048 run: | @@ -54,6 +67,7 @@ jobs: sudo sed -i 's/http:\/\/azure.archive.ubuntu.com\/ubuntu\//mirror+file:\/etc\/apt\/mirrors.txt/' /etc/apt/sources.list - name: Configure PostgreSQL APT repository + if: !inputs.style-only env: POSTGRES_APT_KEY_SHA_512: df557805862cd279f40819834af14e1723b18044df9dc22bea710b6980c98cc8ed39e75ed5c9adaa1932992710f1180f0491dc9437bfd485b4aa2b75776407d4 /usr/share/keyrings/postgresql-keyring.gpg run: | @@ -102,6 +116,7 @@ jobs: shell: bash - name: Restore libparsec if Rust hasn't been modified + if: !inputs.style-only id: cache-libparsec uses: actions/cache/restore@704facf57e6136b1bc63b828d79edcd491f0ee84 # pin v3.3.2 with: @@ -113,7 +128,7 @@ jobs: - name: Setup Rust toolchain uses: actions-rust-lang/setup-rust-toolchain@f3c84ee10bf5a86e7a5d607d487bf17d57670965 # pin v1.5.0 - if: steps.cache-libparsec.outputs.cache-hit != 'true' + if: !inputs.style-only && steps.cache-libparsec.outputs.cache-hit != 'true' with: # We setup the cache by hand, see below cache: false @@ -121,7 +136,7 @@ jobs: - name: Retrieve Rust cache uses: Swatinem/rust-cache@e207df5d269b42b69c8bc5101da26f7d31feddb4 # pin v2.6.2 - if: steps.cache-libparsec.outputs.cache-hit != 'true' + if: !inputs.style-only && steps.cache-libparsec.outputs.cache-hit != 'true' with: # Cache is limited to 10Go (and cache is ~700mo per platform !). On top of that. # cache is only shared between master and the PRs (and not across PRs). @@ -165,7 +180,8 @@ jobs: # - We haven't already cached it. - name: Save cached libparsec to be reused on later call if: >- - steps.cache-libparsec.outputs.cache-hit != 'true' + !inputs.style-only + && steps.cache-libparsec.outputs.cache-hit != 'true' && !contains(github.ref, 'gh-readonly-queue') uses: actions/cache/save@704facf57e6136b1bc63b828d79edcd491f0ee84 # pin v3.3.2 with: @@ -176,12 +192,14 @@ jobs: timeout-minutes: 2 - name: Basic tests + if: !inputs.style-only run: poetry run pytest ${{ env.pytest-base-args }} tests -n auto timeout-minutes: 10 working-directory: server # TODO: Postgresql implementation is currently broken # - name: PostgreSQL tests + # if: !inputs.style-only # env: # PGINSTALLATION: /usr/lib/postgresql/${{ env.postgresql-version }}/bin # run: poetry run pytest ${{ env.pytest-base-args }} tests/backend tests/test_cli.py -k 'not test_shuffle_roles' --postgresql --runslow @@ -189,6 +207,7 @@ jobs: # working-directory: server - name: Hypothesis tests + if: !inputs.style-only run: poetry run pytest ${{ env.pytest-base-args }} tests --runslow -m slow --numprocesses auto timeout-minutes: 50 working-directory: server diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 24ecfa41f68..fafadf6cbc1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,6 +29,7 @@ jobs: outputs: rust: ${{ steps.need-check.outputs.rust }} python: ${{ steps.need-check.outputs.python }} + python-style-only: ${{ steps.need-check.outputs.python_style_only }} web: ${{ steps.need-check.outputs.web }} steps: - uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # pin v4.0.0 @@ -44,15 +45,19 @@ jobs: - name: Determine which workflows need to be run id: need-check run: | + env | grep NEED_CHECK_ set -eux -o pipefail - for check in $(env | grep -o 'NEED_CHECK_\w*' ); do - env_value=$(eval "echo \$$check") + for check in $(env | grep -o 'NEED_CHECK_[a-z_]\+' ); do + env_value=$(eval "echo \${$check}") echo "${check#NEED_CHECK_}=$env_value" done | tee -a $GITHUB_OUTPUT env: NEED_CHECK_rust: ${{ github.ref == 'refs/heads/master' || steps.changes.outputs.rust-jobs == 'true' }} NEED_CHECK_web: ${{ github.ref == 'refs/heads/master' || steps.changes.outputs.web-jobs == 'true' }} NEED_CHECK_python: ${{ github.ref == 'refs/heads/master' || steps.changes.outputs.python-jobs == 'true' }} + # Basically we want to only check the python code style when we modify a file that ins't related to the parsec server (e.g.: bindings/generator/generate.py) + # Thus don't require to run the python test. + NEED_CHECK_python_style_only: ${{ steps.changes.outputs.python-jobs == 'false' || steps.changes.outputs.any-python-files == 'true' }} # Github PR merging is configured to only require this job to pass ci-is-happy: @@ -75,6 +80,8 @@ jobs: import os import json + NOT_A_JOB = ('python-style-only',) + data = json.loads(os.environ["NEEDS"]) print("NEEDS:", json.dumps(data, indent=4), sep="\n") @@ -86,6 +93,8 @@ jobs: # Check required jobs, here we just need to check that the state is `success` and not `skipped`. for job_name, required in data["dispatch"]["outputs"].items(): + if job_name in NOT_A_JOB: + continue assert required in ("true", "false") job_result = data[job_name]["result"] if required == "true" and job_result != "success": @@ -167,8 +176,10 @@ jobs: python: needs: - dispatch - if: needs.dispatch.outputs.python == 'true' + if: needs.dispatch.outputs.python == 'true' || needs.dispatch.outputs.python-style-only == 'true' uses: ./.github/workflows/ci-python.yml + with: + style-only: ${{ needs.dispatch.outputs.python-style-only == 'true' }} rust: needs: