Only run python check style when modified any python file that isn't … #3
Workflow file for this run
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: 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. | ||
# Having the workflow run on each merge commit is something we would like, that could help us where a regression was made and missed by previous checks. | ||
# | ||
# For that we use `head_ref` that is only defined on `pull-request` and fallback to `run_id` (this is a counter, so it's value is unique between workflow call). | ||
concurrency: | ||
group: ci-python-${{ github.workflow }}-${{ github.head_ref || github.run_id }} | ||
cancel-in-progress: true | ||
env: | ||
poetry-version: 1.5.1 | ||
pytest-base-args: >- | ||
--log-level=DEBUG | ||
--durations=10 | ||
--side-effects-timeout=10 | ||
-vv | ||
-x | ||
# TODO: We stick to PostgreSQL 12 for the moment given later versions are | ||
# much slower (postgresql tests runs in ~9mn on 12 vs ~36mn on 14 !) | ||
postgresql-version: 12 | ||
permissions: | ||
contents: read | ||
jobs: | ||
test-python-server: | ||
# Only the server is in Python, and it is only meant to be run on Linux | ||
name: "(🐧 Linux only): 🐍 Python server tests" | ||
# Just a fail-safe timeout, see the fine grain per-task timeout instead | ||
timeout-minutes: 60 | ||
# All linux jobs must run the same ubuntu version to avoid Rust caching issues ! | ||
# 20.04 is required to install PostgreSQL 12 | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # pin v4.0.0 | ||
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: | | ||
set -e -o pipefail | ||
( | ||
# make sure there is a `\t` between URL and `priority:*` attributes | ||
printf 'http://azure.archive.ubuntu.com/ubuntu priority:1\n'; | ||
curl http://mirrors.ubuntu.com/mirrors.txt | grep https | ||
) | sudo tee /etc/apt/mirrors.txt | ||
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: | | ||
set -x -o pipefail | ||
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc \ | ||
| sudo gpg --dearmor --output /usr/share/keyrings/postgresql-keyring.gpg | ||
printenv POSTGRES_APT_KEY_SHA_512 | sha512sum --strict -c - | ||
echo "deb [signed-by=/usr/share/keyrings/postgresql-keyring.gpg] http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" \ | ||
| sudo tee /etc/apt/sources.list.d/postgresql.list | ||
sudo apt-get update | ||
timeout-minutes: 5 | ||
# TODO: Postgresql implementation is currently broken | ||
# - name: Install PostgreSQL-${{ env.postgresql-version }} | ||
# run: | | ||
# # Retry the command until it succeed. | ||
# # We retry because sometime the APT repo configured | ||
# # by the runner seems drop the connection causing the command to fail. | ||
# until sudo apt-get -y install ${{ env.PACKAGE_TO_INSTALL }}; do | ||
# echo "Fail to install APT package retrying ..."; | ||
# done | ||
# env: | ||
# PACKAGE_TO_INSTALL: >- | ||
# postgresql-${{ env.postgresql-version }} | ||
# timeout-minutes: 5 | ||
- uses: ./.github/actions/setup-python-poetry | ||
id: setup-python | ||
with: | ||
poetry-version: ${{ env.poetry-version }} | ||
project-path: ./server | ||
timeout-minutes: 10 | ||
# libparsec is slow to compile, so we save it in cache and skip the | ||
# compilation entirely if the Rust code hasn't changed ! | ||
# Key cache contains a hash of all the files that are used to produce _parsec.so | ||
# Hence if we have a cache hit we know that there is no need for a rebuild ! | ||
- name: Setup cache-key | ||
id: cache-key | ||
run: echo "key=ubuntu-20.04-${{ hashFiles('server/src/**', 'server/Cargo.toml', 'libparsec/**', 'rust-toolchain.toml', 'Cargo.toml', 'Cargo.lock') }}-libparsec-python-${{ env.python-version }}" >> $GITHUB_OUTPUT | ||
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: | ||
key: ${{ steps.cache-key.outputs.key }} | ||
path: | | ||
server/parsec/_parsec.*.pyd | ||
server/parsec/_parsec.*.so | ||
timeout-minutes: 2 | ||
- name: Setup Rust toolchain | ||
uses: actions-rust-lang/setup-rust-toolchain@f3c84ee10bf5a86e7a5d607d487bf17d57670965 # pin v1.5.0 | ||
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: !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). | ||
# So we only save the cache on master build given it's the ones that are the | ||
# most likely to be reused. | ||
save-if: ${{ github.ref == 'refs/heads/master' }} | ||
timeout-minutes: 5 | ||
- name: Install python deps | ||
shell: bash | ||
run: | | ||
set -ex | ||
poetry --directory ./server env info | ||
if ${{ steps.cache-libparsec.outputs.cache-hit == 'true' }}; then export POETRY_LIBPARSEC_BUILD_STRATEGY=no_build; fi | ||
python make.py python-ci-install | ||
timeout-minutes: 20 | ||
- name: Install pre-commit | ||
id: pre-commit | ||
uses: ./.github/actions/use-pre-commit | ||
with: | ||
install-only: true | ||
- name: Check python code style | ||
run: | | ||
set -eux | ||
for step in mypy black ruff; do | ||
python \ | ||
${{ steps.pre-commit.outputs.install-path }} \ | ||
run \ | ||
$step \ | ||
--show-diff-on-failure \ | ||
--verbose \ | ||
--color=always \ | ||
${{ steps.pre-commit.outputs.suggested-args }} | ||
done | ||
timeout-minutes: 10 | ||
# We only save the libparsec lib when: | ||
# - We are not in a github queue branch (they're a one time use so caching won't help) | ||
# - We haven't already cached it. | ||
- name: Save cached libparsec to be reused on later call | ||
if: >- | ||
!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: | ||
key: ${{ steps.cache-key.outputs.key }} | ||
path: | | ||
server/parsec/_parsec.*.pyd | ||
server/parsec/_parsec.*.so | ||
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 |