Skip to content

Commit

Permalink
CI: Add 'no-creds' test in CI, fix "only on forks" condition of full …
Browse files Browse the repository at this point in the history
…pytest suite, add pr check workflow (#145)
  • Loading branch information
aaronsteers authored Mar 28, 2024
1 parent 2e28882 commit 16df499
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 4 deletions.
39 changes: 35 additions & 4 deletions .github/workflows/python_pytest.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# This workflow will run pytest.
#
# There are two jobs which run in parallel:
# There are three jobs which run in parallel:
# 1. pytest-fast: Run fast tests only, and fail fast so the dev knows asap if they broke something.
# 2. pytest: Run all tests, across multiple python versions.
# 2. pytest-no-creds: Run tests only if they don't require creds. The main use case is to run tests
# on forks, where secrets are not available. We flush the GCP_GSM_CREDENTIALS env var to an
# invalid value to ensure that tests that require creds are not run.
# 3. pytest: Run all tests, across multiple python versions.
#
# Note that pytest-fast also skips tests that require credentials, allowing it to run on forks.
name: Run Tests
Expand Down Expand Up @@ -42,10 +45,38 @@ jobs:
GCP_GSM_CREDENTIALS: ${{ secrets.GCP_GSM_CREDENTIALS }}
run: poetry run pytest -m "not slow and not requires_creds" --durations=5 --exitfirst

pytest-no-creds:
name: Pytest (No Creds)
runs-on: ubuntu-latest
steps:
# Common steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Poetry
uses: Gr1N/setup-poetry@v8
with:
poetry-version: "1.7.1"
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
cache: 'poetry'
- name: Install dependencies
run: poetry install

# Job-specific step(s):
- name: Run Pytest (No-Creds)
env:
# Force this to an invalid value to ensure tests that no creds are required are run.
GCP_GSM_CREDENTIALS: "no-creds"
run: poetry run pytest -m "not requires_creds"

pytest:
name: Pytest (All, Python ${{ matrix.python-version }}, ${{ matrix.os }})
# Don't run on forks
if: github.repository_owner == 'airbytehq'
# Don't run on forks. Run on pushes to main, and on PRs that are not from forks.
if: >
(github.event_name == 'push' && github.ref == 'refs/heads/main') ||
(github.event.pull_request.head.repo.fork == false)
strategy:
matrix:
python-version: [
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/slash_command_dispatch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ jobs:
- name: Slash Command Dispatch
uses: peter-evans/slash-command-dispatch@v4
with:
repository: ${{ github.repository }}
token: ${{ secrets.GITHUB_TOKEN }}
issue-type: pr
commands: |
autofix
test-pr
static-args: |
pr=${{ github.event.issue.number }}
# Only run for users with 'write' permission on the main repository
permission: write
67 changes: 67 additions & 0 deletions .github/workflows/test-pr-command.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
on:
workflow_dispatch:
inputs:
pr:
description: 'PR Number'
type: number
required: true

jobs:
# This is copied from the `python_pytest.yml` file.
# Only the first two steps of the job are different, and they check out the PR's branch.
pytest-on-demand:
name: On-Demand PR Pytest (All, Python ${{ matrix.python-version }}, ${{ matrix.os }})
# Don't run on forks. Run on pushes to main, and on PRs that are not from forks.
strategy:
matrix:
python-version: [
'3.9',
'3.10',
'3.11',
]
os: [
Ubuntu,
Windows,
]
fail-fast: false

runs-on: "${{ matrix.os }}-latest"
steps:

# Custom steps to fetch the PR and checkout the code:

- name: Fetch PR
id: fetch-pr
uses: actions/github-script@v5
with:
script: |
const pr = await github.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: ${{ github.event.inputs.pr }}
});
return pr.data.head.sha;
result-encoding: string
- name: Checkout PR
uses: actions/checkout@v4
with:
ref: ${{ steps.fetch-pr.outputs.result }}

# Same as the `python_pytest.yml` file:

- name: Set up Poetry
uses: Gr1N/setup-poetry@v8
with:
poetry-version: "1.7.1"
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'poetry'
- name: Install dependencies
run: poetry install

- name: Run Pytest
env:
GCP_GSM_CREDENTIALS: ${{ secrets.GCP_GSM_CREDENTIALS }}
run: poetry run pytest

0 comments on commit 16df499

Please sign in to comment.