Skip to content

Commit

Permalink
feat: add Python workflows (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
vdusek authored Oct 15, 2024
1 parent 991a66a commit b648b85
Show file tree
Hide file tree
Showing 5 changed files with 218 additions and 0 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/python/docs_check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Docs check

on:
workflow_call:

jobs:
docs_check:
name: Docs check
runs-on: ubuntu-latest
env:
NODE_VERSION: 20
PYTHON_VERSION: 3.12

steps:
- name: Checkout source code
uses: actions/checkout@v4

- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}

- name: Enable corepack
run: |
corepack enable
corepack prepare yarn@stable --activate
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Install Python dependencies
run: |
pipx install --python ${{ env.PYTHON_VERSION }} poetry
make install-dev
- name: Build API reference
run: make build-api-reference

- name: Build docs website
run: make build-docs
88 changes: 88 additions & 0 deletions .github/workflows/python/integration_tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Integration tests

on:
workflow_call:
secrets:
APIFY_TEST_USER_PYTHON_SDK_API_TOKEN:
description: API token of the Python testing user on Apify
required: true

# Concurrency control to ensure only one instance of this workflow runs at a time.
# This avoids exceeding API usage limits on the test user account.
concurrency:
group: integration_tests

jobs:
# Job to run integration tests from the main repository.
integration_tests_on_main:
name: Integration tests (main repository)
runs-on: ubuntu-latest
# If PR is from the main repository or it is a push to master.
if: github.event.pull_request.head.repo.owner.login == 'apify' || github.ref == 'refs/heads/master'
strategy:
matrix:
python-version: ["3.9", "3.12"] # Oldest and newest supported Python versions.
max-parallel: 1 # No parallel tests to avoid exceeding API limits.

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install Python dependencies
run: |
pipx install --python ${{ matrix.python-version }} poetry
make install-dev
- name: Run integration tests
run: make INTEGRATION_TESTS_CONCURRENCY=8 integration-tests
env:
APIFY_TEST_USER_API_TOKEN: ${{ secrets.APIFY_TEST_USER_PYTHON_SDK_API_TOKEN }}

# Job to request approval before running integration tests for PRs from forks.
integration_tests_on_fork_approval:
name: Approve integration tests for fork PR
runs-on: ubuntu-latest
# If the PR is from a fork.
if: github.event.pull_request.head.repo.owner.login != 'apify'
environment:
name: fork-pr-integration-tests
url: ${{ github.event.pull_request.html_url }}
steps:
- name: Await approval
run: echo "Waiting for approval to run integration tests for fork PR."

# Job to run integration tests for PRs from forks, only after manual approval.
integration_tests_on_fork:
name: Integration tests (fork after approval)
needs: integration_tests_on_fork_approval
# If the PR is from a fork.
if: github.event.pull_request.head.repo.owner.login != 'apify'
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.12"] # Oldest and newest supported Python versions.
max-parallel: 1 # No parallel tests to avoid overshooting limits.

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install Python dependencies
run: |
pipx install --python ${{ matrix.python-version }} poetry
make install-dev
- name: Run integration tests
run: make INTEGRATION_TESTS_CONCURRENCY=8 integration-tests
env:
APIFY_TEST_USER_API_TOKEN: ${{ secrets.APIFY_TEST_USER_PYTHON_SDK_API_TOKEN }}
29 changes: 29 additions & 0 deletions .github/workflows/python/lint_check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Lint check

on:
workflow_call:

jobs:
lint_check:
name: Lint check
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install Python dependencies
run: |
pipx install --python ${{ matrix.python-version }} poetry
make install-dev
- name: Run lint check
run: make lint
29 changes: 29 additions & 0 deletions .github/workflows/python/type_check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Type check

on:
workflow_call:

jobs:
type_check:
name: Type check
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install Python dependencies
run: |
pipx install --python ${{ matrix.python-version }} poetry
make install-dev
- name: Run type check
run: make type-check
30 changes: 30 additions & 0 deletions .github/workflows/python/unit_tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Unit tests

on:
workflow_call:

jobs:
unit_tests:
name: Unit tests
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
python-version: ["3.9", "3.10", "3.11", "3.12"]
runs-on: ${{ matrix.os }}

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install Python dependencies
run: |
pipx install --python ${{ matrix.python-version }} poetry
make install-dev
- name: Run unit tests
run: make unit-tests

0 comments on commit b648b85

Please sign in to comment.