diff --git a/.github/workflows/tests.yml b/.github/workflows/ci-build.yml similarity index 79% rename from .github/workflows/tests.yml rename to .github/workflows/ci-build.yml index ac34e26fd..7e9e4e28d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/ci-build.yml @@ -1,5 +1,4 @@ -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions -name: Test +name: Python CI on: push: @@ -10,27 +9,44 @@ on: - cron: "0 0 * * *" workflow_dispatch: +env: + LATEST_SUPPORTED_PY: "3.14" + jobs: + lint: + name: Lint + runs-on: ubuntu-latest + timeout-minutes: 5 + permissions: + contents: read + steps: + - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 + with: + persist-credentials: false + - name: Set up Python ${{ env.LATEST_SUPPORTED_PY }} + uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0 + with: + python-version: ${{ env.LATEST_SUPPORTED_PY }} + - name: Run lint verification + run: ./scripts/lint.sh + typecheck: - name: Typechecks + name: Typecheck runs-on: ubuntu-latest timeout-minutes: 5 - strategy: - matrix: - python-version: ["3.14"] permissions: contents: read steps: - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 with: persist-credentials: false - - name: Set up Python ${{ matrix.python-version }} + - name: Set up Python ${{ env.LATEST_SUPPORTED_PY }} uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0 with: - python-version: ${{ matrix.python-version }} + python-version: ${{ env.LATEST_SUPPORTED_PY }} - name: Run mypy verification - run: | - ./scripts/run_mypy.sh + run: ./scripts/run_mypy.sh + unittest: name: Unit tests runs-on: ubuntu-22.04 @@ -48,6 +64,7 @@ jobs: - "3.8" - "3.7" - "pypy3.10" + - "pypy3.11" permissions: contents: read env: @@ -67,10 +84,8 @@ jobs: pip install -U pip pip install -r requirements/testing.txt pip install -r requirements/optional.txt - - name: Run validation (black/flake8/pytest) + - name: Run tests run: | - black --check slack/ slack_sdk/ tests/ integration_tests/ - flake8 slack/ slack_sdk/ PYTHONPATH=$PWD:$PYTHONPATH pytest --cov-report=xml --cov=slack_sdk/ --junitxml=reports/test_report.xml tests/ - name: Run tests for SQLAlchemy v1.4 (backward-compatibility) run: | @@ -89,7 +104,7 @@ jobs: token: ${{ secrets.CODECOV_TOKEN }} verbose: true - name: Upload test coverage to Codecov (only with latest supported version) - if: startsWith(matrix.python-version, '3.14') + if: startsWith(matrix.python-version, env.LATEST_SUPPORTED_PY) uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7 # v5.5.1 with: fail_ci_if_error: true @@ -98,10 +113,12 @@ jobs: report_type: coverage token: ${{ secrets.CODECOV_TOKEN }} verbose: true + notifications: name: Regression notifications runs-on: ubuntu-latest needs: + - lint - typecheck - unittest if: ${{ !success() && github.ref == 'refs/heads/main' && github.event_name != 'workflow_dispatch' }} diff --git a/requirements/testing.txt b/requirements/testing.txt index 9b702718c..9e1a3fd67 100644 --- a/requirements/testing.txt +++ b/requirements/testing.txt @@ -12,4 +12,3 @@ moto>=4.0.13,<6 # For AsyncSQLAlchemy tests greenlet<=4 aiosqlite<=1 --r tools.txt diff --git a/requirements/tools.txt b/requirements/tools.txt index dd09cd46f..4c0751dbd 100644 --- a/requirements/tools.txt +++ b/requirements/tools.txt @@ -1,6 +1,4 @@ -# We only need to install mypy with CPython runtimes -# Typechecking using the PyPy runtime is not planned -mypy<=1.19.0; platform_python_implementation == "CPython" +mypy<=1.19.0; # while flake8 5.x have issues with Python 3.12, flake8 6.x requires Python >= 3.8.1, # so 5.x should be kept in order to stay compatible with Python 3.7/3.8 flake8>=5.0.4,<8 diff --git a/scripts/format.sh b/scripts/format.sh index d4236258f..56ca68077 100755 --- a/scripts/format.sh +++ b/scripts/format.sh @@ -4,7 +4,10 @@ script_dir=`dirname $0` cd ${script_dir}/.. -pip install -U pip -pip install -U -r requirements/tools.txt +if [[ "$1" != "--no-install" ]]; then + export PIP_REQUIRE_VIRTUALENV=1 + pip install -U pip + pip install -U -r requirements/tools.txt +fi black slack/ slack_sdk/ tests/ integration_tests/ diff --git a/scripts/lint.sh b/scripts/lint.sh new file mode 100755 index 000000000..8fac67888 --- /dev/null +++ b/scripts/lint.sh @@ -0,0 +1,14 @@ + +#!/bin/bash +# ./scripts/lint.sh + +script_dir=`dirname $0` +cd ${script_dir}/.. + +if [[ "$1" != "--no-install" ]]; then + pip install -U pip + pip install -U -r requirements/tools.txt +fi + +black --check slack/ slack_sdk/ tests/ integration_tests/ +flake8 slack/ slack_sdk/ diff --git a/scripts/run_integration_tests.sh b/scripts/run_integration_tests.sh index a5d86801b..1a6f254cb 100755 --- a/scripts/run_integration_tests.sh +++ b/scripts/run_integration_tests.sh @@ -10,10 +10,11 @@ cd ${script_dir}/.. pip install -U pip pip install -U -r requirements/testing.txt \ - -U -r requirements/optional.txt + -U -r requirements/optional.txt \ + -U -r requirements/tools.txt echo "Generating code ..." && python scripts/codegen.py --path . -echo "Running black (code formatter) ..." && black slack_sdk/ +echo "Running black (code formatter) ..." && ./scripts/format.sh --no-install test_target="${1:-tests/integration_tests/}" PYTHONPATH=$PWD:$PYTHONPATH pytest $test_target diff --git a/scripts/run_mypy.sh b/scripts/run_mypy.sh index 0d27346bc..cc1146f15 100755 --- a/scripts/run_mypy.sh +++ b/scripts/run_mypy.sh @@ -8,6 +8,7 @@ cd ${script_dir}/.. pip install -U pip setuptools wheel pip install -U -r requirements/testing.txt \ - -U -r requirements/optional.txt + -U -r requirements/optional.txt \ + -U -r requirements/tools.txt mypy --config-file pyproject.toml diff --git a/scripts/run_unit_tests.sh b/scripts/run_unit_tests.sh index cec153388..c8ab0af78 100755 --- a/scripts/run_unit_tests.sh +++ b/scripts/run_unit_tests.sh @@ -10,10 +10,12 @@ cd ${script_dir}/.. pip install -U pip pip install -U -r requirements/testing.txt \ - -U -r requirements/optional.txt + -U -r requirements/optional.txt \ + -U -r requirements/tools.txt echo "Generating code ..." && python scripts/codegen.py --path . -echo "Running black (code formatter) ..." && black slack_sdk/ +echo "Running black (code formatter) ..." && ./scripts/format.sh --no-install +echo "Running tests ..." test_target="${1:-tests/}" PYTHONPATH=$PWD:$PYTHONPATH pytest $test_target diff --git a/scripts/run_validation.sh b/scripts/run_validation.sh index 8a61d03a6..366f0d321 100755 --- a/scripts/run_validation.sh +++ b/scripts/run_validation.sh @@ -8,13 +8,14 @@ script_dir=`dirname $0` cd ${script_dir}/.. pip install -U -r requirements/testing.txt \ - -U -r requirements/optional.txt + -U -r requirements/optional.txt \ + -U -r requirements/tools.txt echo "Generating code ..." && python scripts/codegen.py --path . -echo "Running black (code formatter) ..." && black slack_sdk/ +echo "Running black (code formatter) ..." && ./scripts/format.sh --no-install -black --check slack/ slack_sdk/ tests/ integration_tests/ -flake8 slack/ slack_sdk/ +echo "Running linting checks ..." && ./scripts/lint.sh --no-install +echo "Running tests with coverage reporting ..." test_target="${1:-tests/}" PYTHONPATH=$PWD:$PYTHONPATH pytest --cov-report=xml --cov=slack_sdk/ $test_target