Skip to content

Commit

Permalink
Only run python check style when modified any python file that isn't …
Browse files Browse the repository at this point in the history
…related to parsec-server
  • Loading branch information
FirelightFlagboy committed Sep 12, 2023
1 parent 538aaee commit 9c472ac
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
7 changes: 5 additions & 2 deletions .github/filters/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
25 changes: 22 additions & 3 deletions .github/workflows/ci-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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: |
Expand All @@ -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: |
Expand Down Expand Up @@ -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:
Expand All @@ -113,15 +128,15 @@ 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
timeout-minutes: 5

- 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).
Expand Down Expand Up @@ -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:
Expand All @@ -176,19 +192,22 @@ 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
# timeout-minutes: 20
# 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
17 changes: 14 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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")
Expand All @@ -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":
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 9c472ac

Please sign in to comment.