Skip to content

Commit

Permalink
add test splitter job - the goal is to executed only changed targets …
Browse files Browse the repository at this point in the history
…when running integration tests
  • Loading branch information
abikouo committed Jul 6, 2023
1 parent 9349f65 commit f6d8b6b
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,75 @@ on:
pull_request_target:

jobs:
splitter:
runs-on: ubuntu-latest
env:
source_dir: "cloud_awsops"
outputs:
test_targets: ${{ steps.display.outputs.test_targets }}
steps:
- name: Checkout collection
uses: actions/checkout@v3
with:
path: ${{ env.source }}

- name: list changes for pull request
id: splitter
uses: ansible-network/github_actions/.github/actions/ansible_test_splitter@main
with:
total_jobs: 2
collections_to_test: ${{ env.source_dir }}

- name: display targets
id: display
run: echo "test_targets=${{ steps.splitter.outputs.test_targets }}" >> $GITHUB_OUTPUT
shell: bash
test:
runs-on: ubuntu-latest
needs:
- splitter
env:
test_targets: ${{ needs.splitter.outputs.test_targets }}
source: "./source"
aws_dir: "./amazon_aws"
crypto_dir: "./community.crypto"
ansible_version: "stable-2.14"
python_version: "3.9"
strategy:
fail-fast: false
matrix:
workflow-id: ['1', '2']
name: "Integration-cloud.aws_ops-py${{ env.python_version }}-${{ env.ansible_version }}-${{ matrix.workflow-id }}"
steps:
- name: Read ansible-test targets
id: read-targets
run: |
import os
workflow_test_prefix = "cloud.aws_ops-{0}:".format(os.environ.get('TEST_WORKFLOW_ID'))
for item in os.environ.get('TEST_TARGETS').split(';'):
if item.startswith(workflow_test_prefix):
targets=' '.join(item.split(':', maxsplit=1)[1].split(',')))
output_path = os.environ.get('GITHUB_OUTPUT')
with open(output_path, "a", encoding="utf-8") as fw:
fw.write(f"ansible_test_targets={targets}\n")
shell: python
env:
TEST_WORKFLOW_ID: "${{ matrix.workflow-id }}"
TEST_TARGETS: "${{ env.test_targets }}"

- name: Checkout collection
uses: actions/checkout@v3
with:
path: ${{ env.source }}
if: steps.read-targets.outputs.ansible_test_targets != ''

- name: Build and install collection
id: install-collection
uses: ansible-network/github_actions/.github/actions/build_install_collection@main
with:
install_python_dependencies: false
source_path: ${{ env.source }}
if: steps.read-targets.outputs.ansible_test_targets != ''

# checkout and install 'amazon.aws'
- name: checkout ansible-collections/amazon.aws
Expand All @@ -31,12 +80,14 @@ jobs:
repository: ansible-collections/amazon.aws
path: ${{ env.amazon_aws }}
ref: main
if: steps.read-targets.outputs.ansible_test_targets != ''

- name: install amazon.aws collection
uses: ansible-network/github_actions/.github/actions/build_install_collection@main
with:
install_python_dependencies: true
source_path: ${{ env.amazon_aws }}
if: steps.read-targets.outputs.ansible_test_targets != ''

# checkout and install 'community.crypto'
- name: checkout ansible-collections/community.crypto
Expand All @@ -45,18 +96,21 @@ jobs:
repository: ansible-collections/community.crypto
path: ${{ env.crypto_dir }}
ref: main
if: steps.read-targets.outputs.ansible_test_targets != ''

- name: install community.crypto collection
uses: ansible-network/github_actions/.github/actions/build_install_collection@main
with:
install_python_dependencies: false
source_path: ${{ env.crypto_dir }}
if: steps.read-targets.outputs.ansible_test_targets != ''

- name: Create AWS/sts session credentials
uses: ansible-network/github_actions/.github/actions/ansible_aws_test_provider@main
with:
collection_path: ${{ steps.install-collection.outputs.collection_path }}
ansible_core_ci_key: ${{ secrets.ANSIBLE_CORE_CI_KEY }}
if: steps.read-targets.outputs.ansible_test_targets != ''

# we use raw git to create a repository in the tests
# this fails if the committer doesn't have a name and an email set
Expand All @@ -65,6 +119,7 @@ jobs:
git config --global user.email gha@localhost
git config --global user.name "Github Actions"
shell: bash
if: steps.read-targets.outputs.ansible_test_targets != ''

- name: Run integration tests
uses: ansible-network/github_actions/.github/actions/ansible_test_integration@main
Expand All @@ -73,3 +128,4 @@ jobs:
python_version: ${{ env.python_version }}
ansible_version: ${{ env.ansible_version }}
ansible_test_requirement_files: 'test-requirements.txt'
if: steps.read-targets.outputs.ansible_test_targets != ''

0 comments on commit f6d8b6b

Please sign in to comment.