Skip to content

Commit

Permalink
separate pants-plugins tests and shard unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cognifloyd committed Oct 24, 2024
1 parent eb3868a commit 4491f12
Showing 1 changed file with 105 additions and 22 deletions.
127 changes: 105 additions & 22 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,17 @@ on:
# - cron: '0 0 * * *'

jobs:
unit-tests:
name: 'Unit Tests (pants runs: pytest) - Python ${{ matrix.python-version-short }}'
pants-plugins-tests:
name: 'Pants Plugins Tests (pants runs: pytest) - Python ${{ matrix.python.version-short }}'
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
# NOTE: We need to use full Python version as part of Python deps cache key otherwise
# setup virtualenv step will fail.
include:
- python-version-short: '3.8'
python-version: '3.8.10'
- python-version-short: '3.9'
python-version: '3.9.14'
python:
# Pants itself uses only 3.9
- {version-short: '3.9', version: '3.9.14'}

services:
mongo:
Expand Down Expand Up @@ -85,11 +83,11 @@ jobs:
git submodule foreach 'git fetch --all --tags'
git submodule foreach 'git tag'
- name: 'Set up Python (${{ matrix.python-version }})'
- name: 'Set up Python (${{ matrix.python.version }})'
id: python
uses: actions/setup-python@v5
with:
python-version: '${{ matrix.python-version }}'
python-version: '${{ matrix.python.version }}'

- name: Cache and Install APT Dependencies
uses: ./.github/actions/apt-packages
Expand All @@ -98,16 +96,102 @@ jobs:
uses: ./.github/actions/init-pants
with:
# To ignore a bad cache, bump the cache* integer.
gha-cache-key: cache0-py${{ matrix.python-version }}
gha-cache-key: cache0-py${{ matrix.python.version }}

- name: Test pants-plugins
if: ${{ matrix.python-version-short == '3.9' }}
env:
# Github Actions uses the 'runner' user, so use that instead of stanley.
ST2TESTS_SYSTEM_USER: 'runner'
run: |
pants test pants-plugins/::
- name: Upload pants log
uses: actions/upload-artifact@v4
with:
name: pants-log-py${{ matrix.python.version }}-pants-plugins-tests
path: .pants.d/pants.log
if: always() # We want the log even on failures.

unit-tests:
name: 'Unit Tests Shard ${{ matrix.shard.k }}/${{ matrix.shard.n }} (pants runs: pytest) - Python ${{ matrix.python.version-short }}'
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
# NOTE: We need to use full Python version as part of Python deps cache key otherwise
# setup virtualenv step will fail.
python:
- {version-short: '3.8', version: '3.8.10'}
- {version-short: '3.9', version: '3.9.14'}
shard:
# Sharding of tests is handled by pants:
# https://www.pantsbuild.org/stable/docs/using-pants/advanced-target-selection#sharding-the-input-targets
- {k: '0', n: '2'}
- {k: '1', n: '2'}

services:
mongo:
image: mongo:7.0
ports:
- 27017:27017

rabbitmq:
image: rabbitmq:3.8-management
options: >-
--name rabbitmq
ports:
- 5671:5671/tcp # AMQP SSL port
- 5672:5672/tcp # AMQP standard port
- 15672:15672/tcp # Management: HTTP, CLI

redis:
# Docker Hub image
image: redis
# Set health checks to wait until redis has started
options: >-
--name "redis"
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 6379:6379/tcp

env:
COLUMNS: '120'

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
# a test uses a submodule, and pants needs access to it to calculate deps.
submodules: 'recursive'
# sadly, the submodule will only have fetch-depth=1, which is what we want
# for st2.git, but not for the submodules. We still want actions/checkout
# to do the initial checkout, however, so that it adds auth for fetching
# in the submodule.

- name: Fetch repository submodules
run: |
git submodule status
git submodule foreach 'git fetch --all --tags'
git submodule foreach 'git tag'
- name: 'Set up Python (${{ matrix.python.version }})'
id: python
uses: actions/setup-python@v5
with:
python-version: '${{ matrix.python.version }}'

- name: Cache and Install APT Dependencies
uses: ./.github/actions/apt-packages

- name: Initialize Pants and its GHA caches
uses: ./.github/actions/init-pants
with:
# To ignore a bad cache, bump the cache* integer.
gha-cache-key: cache0-py${{ matrix.python.version }}

- name: Unit Tests
env:
# Github Actions uses the 'runner' user, so use that instead of stanley.
Expand All @@ -117,28 +201,27 @@ jobs:
--python-bootstrap-search-path=[]
--python-bootstrap-search-path=${{ steps.python.outputs.python-path }}
--tag=unit
--test-shard=${{ matrix.shard.k }}/${{ matrix.shard.n }}
test '::'
- name: Upload pants log
uses: actions/upload-artifact@v4
with:
name: pants-log-py${{ matrix.python-version }}
name: pants-log-py${{ matrix.python.version }}-unit-tests-shard-${{ matrix.shard.k }}_${{ matrix.shard.n }}
path: .pants.d/pants.log
if: always() # We want the log even on failures.

pack-tests:
name: 'Pack Tests (pants runs: pytest) - Python ${{ matrix.python-version-short }}'
name: 'Pack Tests (pants runs: pytest) - Python ${{ matrix.python.version-short }}'
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
# NOTE: We need to use full Python version as part of Python deps cache key otherwise
# setup virtualenv step will fail.
include:
- python-version-short: '3.8'
python-version: '3.8.10'
- python-version-short: '3.9'
python-version: '3.9.14'
python:
- {version-short: '3.8', version: '3.8.10'}
- {version-short: '3.9', version: '3.9.14'}

services:
mongo:
Expand Down Expand Up @@ -188,11 +271,11 @@ jobs:
git submodule foreach 'git fetch --all --tags'
git submodule foreach 'git tag'
- name: 'Set up Python (${{ matrix.python-version }})'
- name: 'Set up Python (${{ matrix.python.version }})'
id: python
uses: actions/setup-python@v5
with:
python-version: '${{ matrix.python-version }}'
python-version: '${{ matrix.python.version }}'

- name: Cache and Install APT Dependencies
uses: ./.github/actions/apt-packages
Expand All @@ -201,7 +284,7 @@ jobs:
uses: ./.github/actions/init-pants
with:
# To ignore a bad cache, bump the cache* integer.
gha-cache-key: cache0-py${{ matrix.python-version }}
gha-cache-key: cache0-py${{ matrix.python.version }}

- name: Pack Tests
env:
Expand All @@ -217,7 +300,7 @@ jobs:
- name: Upload pants log
uses: actions/upload-artifact@v4
with:
name: pants-log-py${{ matrix.python-version }}
name: pants-log-py${{ matrix.python.version }}-pack-tests
path: .pants.d/pants.log
if: always() # We want the log even on failures.

Expand Down

0 comments on commit 4491f12

Please sign in to comment.