From ca3060c862035918477ccc78480107df8ea34b50 Mon Sep 17 00:00:00 2001 From: abikouo Date: Fri, 21 Apr 2023 13:22:05 +0200 Subject: [PATCH 1/2] add integration tests in beta mode --- .github/workflows/integration.yaml | 186 +++++++++++++++++++++++++++++ 1 file changed, 186 insertions(+) create mode 100644 .github/workflows/integration.yaml diff --git a/.github/workflows/integration.yaml b/.github/workflows/integration.yaml new file mode 100644 index 00000000000..942f8f671e3 --- /dev/null +++ b/.github/workflows/integration.yaml @@ -0,0 +1,186 @@ +name: integration + +concurrency: + group: community-aws-integration-${{ github.sha }} + cancel-in-progress: true + +on: + pull_request_target: + +env: + AMAZON_PATH: "./amazon" + COMMUNITY_PATH: "./community" + +jobs: + splitter: + runs-on: ubuntu-latest + outputs: + test_targets: ${{ steps.display.outputs.test_targets }} + steps: + - name: Checkout repository + uses: ansible-network/github_actions/.github/actions/checkout_dependency@main + with: + path: ${{ env.COMMUNITY_PATH }} + ref: ${{ github.event.pull_request.head.sha }} + fetch-depth: "0" + + - name: Checkout dependency (amazon.aws) + uses: ansible-network/github_actions/.github/actions/checkout_dependency@main + with: + repository: ansible-collections/amazon.aws + path: ${{ env.AMAZON_PATH }} + ref: ${{ github.event.pull_request.base.ref }} + fetch-depth: "0" + + - name: list changes for pull request + id: splitter + uses: ansible-network/github_actions/.github/actions/ansible_test_splitter@main + with: + total_jobs: 22 + collections_to_test: | + ${{ env.AMAZON_PATH }} + ${{ env.COMMUNITY_PATH }} + + - name: display targets + id: display + run: echo "test_targets=${{ steps.splitter.outputs.test_targets }}" >> $GITHUB_OUTPUT + shell: bash + integration: + needs: + - splitter + env: + test_targets: ${{ needs.splitter.outputs.test_targets }} + if: ${{ contains(github.event.pull_request.labels.*.name, 'run-integration-beta') }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + ansible-version: + - milestone + python-version: + - "3.9" + collection: + - amazon.aws + - community.aws + workflow-id: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22'] + name: "integration-${{ matrix.collection }}-py${{ matrix.python-version }}-${{ matrix.ansible-version }}-${{ matrix.workflow-id }}" + steps: + - name: Read ansible-test targets + id: read-targets + run: | + python -c "import os; splitter_d={x.split(':', maxsplit=1)[0]:x.split(':', maxsplit=1)[1] for x in os.environ.get('TEST_TARGETS').split(';')}; context=os.environ.get('TEST_CONTEXT'); result=splitter_d.get(context); result and print(f'ansible_test_targets={result}')" >> $GITHUB_OUTPUT + shell: bash + env: + TEST_CONTEXT: "${{ matrix.collection }}-${{ matrix.workflow-id }}" + TEST_TARGETS: "${{ env.test_targets }}" + + - name: Install ansible-core (${{ matrix.ansible-version }}) + run: python3 -m pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible-version }}.tar.gz --disable-pip-version-check + if: steps.read-targets.outputs.ansible_test_targets != '' + + # install community.aws collection + - name: Checkout the collection repository + uses: ansible-network/github_actions/.github/actions/checkout_dependency@main + with: + path: ${{ env.COMMUNITY_PATH }} + ref: ${{ github.event.pull_request.head.sha }} + fetch-depth: "0" + if: steps.read-targets.outputs.ansible_test_targets != '' + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + if: steps.read-targets.outputs.ansible_test_targets != '' + + - name: Pre install collections dependencies first so the collection install does not + run: ansible-galaxy collection install --pre true -p /home/runner/collections/ + if: steps.read-targets.outputs.ansible_test_targets != '' + + - name: Read collection metadata from galaxy.yml + id: identify + uses: ansible-network/github_actions/.github/actions/identify_collection@main + with: + source_path: ${{ env.COMMUNITY_PATH }} + if: steps.read-targets.outputs.ansible_test_targets != '' + + - name: Build and install the collection + uses: ansible-network/github_actions/.github/actions/build_install_collection@main + with: + install_python_dependencies: true + source_path: ${{ env.COMMUNITY_PATH }} + collection_path: ${{ steps.identify.outputs.collection_path }} + tar_file: ${{ steps.identify.outputs.tar_file }} + ansible_version: ${{ matrix.ansible-version }} + if: steps.read-targets.outputs.ansible_test_targets != '' + + # install amazon.aws collection + - name: Checkout the collection repository + uses: ansible-network/github_actions/.github/actions/checkout_dependency@main + with: + repository: ansible-collections/amazon.aws + path: ${{ env.AMAZON_PATH }} + ref: ${{ github.event.pull_request.base.ref }} + fetch-depth: "0" + if: steps.read-targets.outputs.ansible_test_targets != '' + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + if: steps.read-targets.outputs.ansible_test_targets != '' + + - name: Pre install collections dependencies first so the collection install does not + run: ansible-galaxy collection install --pre true -p /home/runner/collections/ + if: steps.read-targets.outputs.ansible_test_targets != '' + + - name: Read collection metadata from galaxy.yml + id: identify + uses: ansible-network/github_actions/.github/actions/identify_collection@main + with: + source_path: ${{ env.AMAZON_PATH }} + if: steps.read-targets.outputs.ansible_test_targets != '' + + - name: Build and install the collection + uses: ansible-network/github_actions/.github/actions/build_install_collection@main + with: + install_python_dependencies: true + source_path: ${{ env.AMAZON_PATH }} + collection_path: ${{ steps.identify.outputs.collection_path }} + tar_file: ${{ steps.identify.outputs.tar_file }} + ansible_version: ${{ matrix.ansible-version }} + if: steps.read-targets.outputs.ansible_test_targets != '' + + - name: Determines path to the collection being tested + id: collection-path + run: | + if [ "${COLLECTION_TO_TEST}" == "amazon.aws" ]; then + echo "path=${AMAZON_COLLECTION_PATH}" >> $GITHUB_OUTPUT + else + echo "path=${COMMUNITY_COLLECTION_PATH}" >> $GITHUB_OUTPUT + fi + env: + COLLECTION_TO_TEST: ${{ matrix.collection }} + AMAZON_COLLECTION_PATH: ${{ steps.install-amazon.outputs.collection_path }} + COMMUNITY_COLLECTION_PATH: ${{ steps.install-community.outputs.collection_path }} + 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.collection-path.outputs.path }} + ansible_core_ci_key: ${{ secrets.ANSIBLE_CORE_CI_KEY }} + if: steps.read-targets.outputs.ansible_test_targets != '' + + - name: Run integration tests + uses: ansible-network/github_actions/.github/actions/ansible_test_integration@main + with: + collection_path: ${{ steps.collection-path.outputs.path }} + python_version: ${{ matrix.python-version }} + ansible_version: ${{ matrix.ansible-version }} + ansible_test_requirement_files: | + requirements.txt + test-requirements.txt + tests/integration/requirements.txt + ansible_test_constraint_files: tests/integration/constraints.txt + if: steps.read-targets.outputs.ansible_test_targets != '' From 590352974cde9e14eaa2e3c3131fa98a45603c8d Mon Sep 17 00:00:00 2001 From: abikouo Date: Fri, 7 Jul 2023 16:07:29 +0200 Subject: [PATCH 2/2] add safe-to-test workflow --- .github/workflows/integration.yaml | 88 ++++++++++++++++++------------ 1 file changed, 52 insertions(+), 36 deletions(-) diff --git a/.github/workflows/integration.yaml b/.github/workflows/integration.yaml index 942f8f671e3..ae5478dcd08 100644 --- a/.github/workflows/integration.yaml +++ b/.github/workflows/integration.yaml @@ -8,19 +8,26 @@ on: pull_request_target: env: - AMAZON_PATH: "./amazon" - COMMUNITY_PATH: "./community" + integration_jobs: 22 jobs: + safe-to-test: + if: ${{ github.event.label.name == 'safe to test' }} || ${{ github.event.action != 'labeled' }} + uses: abikouo/github_actions/.github/workflows/safe-to-test.yml@safe_to_test_v2 splitter: runs-on: ubuntu-latest + needs: + - safe-to-test + env: + amazon_dir: "./amazon" + community_dir: "./community" outputs: test_targets: ${{ steps.display.outputs.test_targets }} steps: - name: Checkout repository uses: ansible-network/github_actions/.github/actions/checkout_dependency@main with: - path: ${{ env.COMMUNITY_PATH }} + path: ${{ env.community_dir }} ref: ${{ github.event.pull_request.head.sha }} fetch-depth: "0" @@ -28,7 +35,7 @@ jobs: uses: ansible-network/github_actions/.github/actions/checkout_dependency@main with: repository: ansible-collections/amazon.aws - path: ${{ env.AMAZON_PATH }} + path: ${{ env.amazon_dir }} ref: ${{ github.event.pull_request.base.ref }} fetch-depth: "0" @@ -36,21 +43,48 @@ jobs: id: splitter uses: ansible-network/github_actions/.github/actions/ansible_test_splitter@main with: - total_jobs: 22 + total_jobs: ${{ integration_jobs }} collections_to_test: | - ${{ env.AMAZON_PATH }} - ${{ env.COMMUNITY_PATH }} + ${{ env.community_dir }} + ${{ env.amazon_dir }} - name: display targets id: display run: echo "test_targets=${{ steps.splitter.outputs.test_targets }}" >> $GITHUB_OUTPUT shell: bash - integration: + build_jobs: + runs-on: ubuntu-latest + if: ${{ needs.splitter.outputs.test_targets != '' }} needs: - splitter - env: + outputs: + test_matrix: ${{ steps.compute-matrix.outputs.test_matrix }} test_targets: ${{ needs.splitter.outputs.test_targets }} - if: ${{ contains(github.event.pull_request.labels.*.name, 'run-integration-beta') }} + steps: + - name: Compute matrix + id: compute-matrix + run: | + import os, json + ids=[ + item.split(":", maxsplit=1)[0].split('-', maxsplit=1)[1] + for item in os.environ.get('TEST_TARGETS').split(';') if item.split(':', maxsplit=1)[1] + ] + output_path = os.environ.get('GITHUB_OUTPUT') + with open(output_path, "a", encoding="utf-8") as fw: + fw.write(f'job_ids={json.dumps(ids)}\n') + shell: python + env: + TEST_TARGETS: ${{ needs.splitter.outputs.test_targets }} + integration: + needs: + - build_jobs + env: + test_targets: ${{ needs.build_jobs.outputs.test_targets }} + amazon_dir: "./amazon" + community_dir: "./community" + if: >- + contains(github.event.pull_request.labels.*.name, 'run-integration-beta') && + needs.build_jobs.outputs.test_matrix != '' runs-on: ubuntu-latest strategy: fail-fast: false @@ -62,7 +96,7 @@ jobs: collection: - amazon.aws - community.aws - workflow-id: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22'] + workflow-id: ${{ fromJson(needs.build_jobs.outputs.job_ids) }} name: "integration-${{ matrix.collection }}-py${{ matrix.python-version }}-${{ matrix.ansible-version }}-${{ matrix.workflow-id }}" steps: - name: Read ansible-test targets @@ -76,80 +110,64 @@ jobs: - name: Install ansible-core (${{ matrix.ansible-version }}) run: python3 -m pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible-version }}.tar.gz --disable-pip-version-check - if: steps.read-targets.outputs.ansible_test_targets != '' # install community.aws collection - name: Checkout the collection repository uses: ansible-network/github_actions/.github/actions/checkout_dependency@main with: - path: ${{ env.COMMUNITY_PATH }} + path: ${{ env.community_dir }} ref: ${{ github.event.pull_request.head.sha }} fetch-depth: "0" - if: steps.read-targets.outputs.ansible_test_targets != '' - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - if: steps.read-targets.outputs.ansible_test_targets != '' - name: Pre install collections dependencies first so the collection install does not run: ansible-galaxy collection install --pre true -p /home/runner/collections/ - if: steps.read-targets.outputs.ansible_test_targets != '' - name: Read collection metadata from galaxy.yml id: identify uses: ansible-network/github_actions/.github/actions/identify_collection@main with: - source_path: ${{ env.COMMUNITY_PATH }} - if: steps.read-targets.outputs.ansible_test_targets != '' + source_path: ${{ env.community_dir }} - name: Build and install the collection uses: ansible-network/github_actions/.github/actions/build_install_collection@main with: install_python_dependencies: true - source_path: ${{ env.COMMUNITY_PATH }} + source_path: ${{ env.community_dir }} collection_path: ${{ steps.identify.outputs.collection_path }} tar_file: ${{ steps.identify.outputs.tar_file }} ansible_version: ${{ matrix.ansible-version }} - if: steps.read-targets.outputs.ansible_test_targets != '' # install amazon.aws collection - name: Checkout the collection repository uses: ansible-network/github_actions/.github/actions/checkout_dependency@main with: repository: ansible-collections/amazon.aws - path: ${{ env.AMAZON_PATH }} + path: ${{ env.amazon_dir }} ref: ${{ github.event.pull_request.base.ref }} fetch-depth: "0" - if: steps.read-targets.outputs.ansible_test_targets != '' - - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python-version }} - if: steps.read-targets.outputs.ansible_test_targets != '' - name: Pre install collections dependencies first so the collection install does not run: ansible-galaxy collection install --pre true -p /home/runner/collections/ - if: steps.read-targets.outputs.ansible_test_targets != '' - name: Read collection metadata from galaxy.yml id: identify uses: ansible-network/github_actions/.github/actions/identify_collection@main with: - source_path: ${{ env.AMAZON_PATH }} - if: steps.read-targets.outputs.ansible_test_targets != '' + source_path: ${{ env.amazon_dir }} - name: Build and install the collection uses: ansible-network/github_actions/.github/actions/build_install_collection@main with: install_python_dependencies: true - source_path: ${{ env.AMAZON_PATH }} + source_path: ${{ env.amazon_dir }} collection_path: ${{ steps.identify.outputs.collection_path }} tar_file: ${{ steps.identify.outputs.tar_file }} ansible_version: ${{ matrix.ansible-version }} - if: steps.read-targets.outputs.ansible_test_targets != '' - name: Determines path to the collection being tested id: collection-path @@ -163,14 +181,12 @@ jobs: COLLECTION_TO_TEST: ${{ matrix.collection }} AMAZON_COLLECTION_PATH: ${{ steps.install-amazon.outputs.collection_path }} COMMUNITY_COLLECTION_PATH: ${{ steps.install-community.outputs.collection_path }} - 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.collection-path.outputs.path }} ansible_core_ci_key: ${{ secrets.ANSIBLE_CORE_CI_KEY }} - if: steps.read-targets.outputs.ansible_test_targets != '' - name: Run integration tests uses: ansible-network/github_actions/.github/actions/ansible_test_integration@main @@ -183,4 +199,4 @@ jobs: test-requirements.txt tests/integration/requirements.txt ansible_test_constraint_files: tests/integration/constraints.txt - if: steps.read-targets.outputs.ansible_test_targets != '' + ansible_test_targets: ${{ steps.read-targets.outputs.ansible_test_targets }} \ No newline at end of file