Skip to content

Commit

Permalink
make integration test reusable
Browse files Browse the repository at this point in the history
  • Loading branch information
marius-baseten committed Aug 19, 2024
1 parent b194b39 commit d7a9528
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 45 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/_integration_test_shared.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Reusable Integration Tests

on:
workflow_call:
inputs:
test_directory:
description: 'The directory to run tests from.'
required: true
type: string
split_test_into_groups:
description: 'Use split matrix'
required: false
type: boolean

jobs:
run-integration-tests:
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
split_group: ${{ inputs.split_test_into_groups && [ "1", "2", "3", "4", "5" ] || [ "1" ] }}
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-python/
- run: poetry install
- run: |
if [ -n "${{ inputs.split_group }}" ]; then
poetry run pytest ${{ inputs.test_directory }} --durations=0 -m 'integration' --junitxml=report.xml --splits 5 --group ${{ matrix.split_group }} --junitxml=report-${{ matrix.split_group }}.xml
else
poetry run pytest ${{ inputs.test_directory }} --durations=0 -m 'integration' --junitxml=report.xml -s --log-cli-level=INFO --junitxml=report-1.xml
fi
- name: Publish Test Report
uses: mikepenz/action-junit-report@v4
if: always()
with:
commit: ${{github.event.workflow_run.head_sha}}
report_paths: "report*.xml"
27 changes: 9 additions & 18 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,16 @@ jobs:
integration-tests:
needs: [detect-version-changed, build-and-push-truss-base-images-if-needed]
if: ${{ !failure() && !cancelled() && (needs.build-and-push-truss-base-images-if-needed.result == 'success' || needs.build-and-push-truss-base-images-if-needed.result == 'skipped') }}
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
split_group: [ "1", "2", "3", "4", "5" ]
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-python/
- run: poetry install
- run: poetry run pytest truss/tests --durations=0 -m 'integration' --splits 5 --group ${{ matrix.split_group }}"
uses: ./.github/workflows/_integration_test_shared.yml@${{ github.ref }}
with:
test_directory: "truss/tests"
split_test_into_groups: true


chain-integration-tests:
needs: [detect-version-changed, build-and-push-truss-base-images-if-needed]
if: ${{ !failure() && !cancelled() && (needs.build-and-push-truss-base-images-if-needed.result == 'success' || needs.build-and-push-truss-base-images-if-needed.result == 'skipped') }}
runs-on: ubuntu-20.04
strategy:
fail-fast: false
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-python/
- run: poetry install
- run: poetry run pytest truss-chains/tests -s --log-cli-level=INFO --durations=0 -m 'integration'
uses: ./_integration_test_shared.yml@${{ github.ref }}
with:
test_directory: "truss-chains/tests"
split_test_into_groups: false
29 changes: 9 additions & 20 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: main - post-commit
name: Main - post-commit

on:
workflow_dispatch: # Allows running from actions tab
Expand Down Expand Up @@ -62,29 +62,18 @@ jobs:
integration-tests:
needs: [detect-version-changed, build-and-push-truss-base-images-if-needed]
if: ${{ !failure() && !cancelled() && (needs.build-and-push-truss-base-images-if-needed.result == 'success' || needs.build-and-push-truss-base-images-if-needed.result == 'skipped') }}
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
split_group: [ "1", "2", "3", "4", "5" ]
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-python/
- run: poetry install
- run: poetry run pytest truss/tests --durations=0 -m 'integration' --splits 5 --group ${{ matrix.split_group }}
uses: ./.github/workflows/_integration_test_shared.yml@${{ github.ref }}
with:
test_directory: "truss/tests"
split_test_into_groups: true

chain-integration-tests:
needs: [detect-version-changed, build-and-push-truss-base-images-if-needed]
if: ${{ !failure() && !cancelled() && (needs.build-and-push-truss-base-images-if-needed.result == 'success' || needs.build-and-push-truss-base-images-if-needed.result == 'skipped') }}
runs-on: ubuntu-20.04
strategy:
fail-fast: false
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-python/
- run: poetry install
- run: poetry run pytest truss-chains/tests -s --log-cli-level=INFO --durations=0 -m 'integration'

uses: ./_integration_test_shared.yml@${{ github.ref }}
with:
test_directory: "truss-chains/tests"
split_test_into_groups: false
publish-to-pypi:
needs: [detect-version-changed]
if: ${{ !failure() && !cancelled() && needs.detect-version-changed.outputs.release_version == 'true' && needs.detect-version-changed.outputs.is_prerelease_version == 'true' }}
Expand Down
7 changes: 0 additions & 7 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ jobs:
- run: poetry install
- name: run tests (poetry run pytest...)
run: poetry run pytest -v --cov=truss -m 'not integration' --junitxml=report.xml

- name: Store Test Report
uses: actions/upload-artifact@v4
with:
name: report.xml
path: report.xml

- name: Publish Test Report # Not sure how to display this in the UI for non PRs.
uses: mikepenz/action-junit-report@v4
if: always()
Expand Down

0 comments on commit d7a9528

Please sign in to comment.