-
-
Notifications
You must be signed in to change notification settings - Fork 747
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pants CI: Run all unit and pack tests #6269
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
be4ce9f
pants: test w/ correct python and only test pants-plugins under py3.9
cognifloyd 3661a0b
correct order of pants args
cognifloyd 970aaaa
pants: run all pack and unit tests
cognifloyd c401e72
update changelog entry
cognifloyd 838b8e1
split test workflow into unit and pack test jobs
cognifloyd eb3868a
Prepare to make pants workflows required
cognifloyd 8f16a19
separate pants-plugins tests and shard unit tests
cognifloyd 9a532ad
CI: more unit test shards for faster feedback
cognifloyd 16b4899
pants: tell pants that some tests use rabbitmq, redis
cognifloyd 433cad5
Suggest ST2TESTS_REDIS_HOST/PORT in error/warning messages
cognifloyd df96ef0
add ST2TESTS_REDIS_HOST/PORT vars to pants CI workflow
cognifloyd 37125e7
Work around missing indexes error in a test
cognifloyd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,21 +23,17 @@ on: | |
# - cron: '0 0 * * *' | ||
|
||
jobs: | ||
test: | ||
name: '${{ matrix.name }} - 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: | ||
- name: 'Test (pants runs: pytest)' | ||
python-version-short: '3.8' | ||
python-version: '3.8.10' | ||
- name: 'Test (pants runs: pytest)' | ||
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: | ||
|
@@ -87,11 +83,109 @@ 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 | ||
|
||
- 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: Test pants-plugins | ||
env: | ||
# Github Actions uses the 'runner' user, so use that instead of stanley. | ||
ST2TESTS_SYSTEM_USER: 'runner' | ||
ST2TESTS_REDIS_HOST: '127.0.0.1' | ||
ST2TESTS_REDIS_PORT: '6379' | ||
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: '4'} | ||
- {k: '1', n: '4'} | ||
- {k: '2', n: '4'} | ||
- {k: '3', n: '4'} | ||
|
||
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 | ||
|
@@ -100,21 +194,154 @@ 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 | ||
- name: Unit Tests | ||
env: | ||
# Github Actions uses the 'runner' user, so use that instead of stanley. | ||
ST2TESTS_SYSTEM_USER: 'runner' | ||
# We do not support running pytest everywhere yet. When we do it will be simply: | ||
# pants test :: | ||
# Until then, we need to manually adjust this command line to test what we can. | ||
ST2TESTS_REDIS_HOST: '127.0.0.1' | ||
ST2TESTS_REDIS_PORT: '6379' | ||
run: > | ||
pants | ||
--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 }}-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 }}' | ||
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'} | ||
|
||
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: | | ||
pants test pylint_plugins/:: pants-plugins/:: | ||
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: Pack Tests | ||
env: | ||
# Github Actions uses the 'runner' user, so use that instead of stanley. | ||
ST2TESTS_SYSTEM_USER: 'runner' | ||
ST2TESTS_REDIS_HOST: '127.0.0.1' | ||
ST2TESTS_REDIS_PORT: '6379' | ||
run: > | ||
pants | ||
--python-bootstrap-search-path=[] | ||
--python-bootstrap-search-path=${{ steps.python.outputs.python-path }} | ||
--tag=pack | ||
test '::' | ||
Comment on lines
+305
to
+306
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
- 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. | ||
|
||
#integration-tests: TODO: run integration tests | ||
|
||
set_merge_ok: | ||
name: Set Merge OK (Tests) | ||
if: always() && !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') | ||
needs: | ||
- pants-plugins-tests | ||
- unit-tests | ||
- pack-tests | ||
#- integration-tests | ||
outputs: | ||
merge_ok: ${{ steps.set_merge_ok.outputs.merge_ok }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- id: set_merge_ok | ||
run: echo 'merge_ok=true' >> ${GITHUB_OUTPUT} | ||
|
||
merge_ok: | ||
name: Merge OK (Tests) | ||
if: always() | ||
needs: | ||
- set_merge_ok | ||
runs-on: ubuntu-latest | ||
steps: | ||
- run: | | ||
merge_ok="${{ needs.set_merge_ok.outputs.merge_ok }}" | ||
if [[ "${merge_ok}" == "true" ]]; then | ||
echo "Merge OK" | ||
exit 0 | ||
else | ||
echo "Merge NOT OK" | ||
exit 1 | ||
fi |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried turning this block into a local action, but checkout has to happen first, before using local actions, so that did not work.
There is hope for a less repetitive workflow, however. actions/runner#1182 says YAML anchor/alias support for GHA workflows is on the roadmap for 2025.