Skip to content
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

skip_changelog(ci): unify and auto discover integration/molecule tests #131

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions .github/workflows/ansible-test-integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
name: Ansible Integration Test
on:

Check warning on line 3 in .github/workflows/ansible-test-integration.yml

View workflow job for this annotation

GitHub Actions / Perform Linting

3:1 [truthy] truthy value should be one of [false, true]
workflow_call:
inputs:
targets:
required: true
type: string
ansible-core-versions:
required: false
default: '["stable-2.14"]'
type: string
target-python-versions:
required: false
default: '["default"]'
type: string
coverage:
required: false
default: auto
type: string

jobs:
ansible-test-integration:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
targets: ${{ fromJson(inputs.targets) }}
ansible-core-versions: ${{ fromJson(inputs.ansible-core-versions) }}
target-python-versions: ${{ fromJson(inputs.target-python-versions) }}

name: "${{ matrix.targets.name }}-${{ matrix.ansible-core-versions }}-py-${{ matrix.target-python-versions }}"
steps:
- name: "Perform ${{ matrix.targets.test }} integration test with ansible-test"
uses: ansible-community/ansible-test-gh-action@release/v1
with:
ansible-core-version: ${{ matrix.ansible-core-versions }}
target-python-version: ${{ matrix.target-python-versions }}
controller-python-version: auto
docker-image: "--docker-privileged" # Workaround because ansible-test action doesn't support setting privileged flag
testing-type: integration
target: ${{ matrix.targets.test }}
coverage: ${{ inputs.coverage }}
pre-test-cmd: |-
echo -e "org_name: ${{ secrets.ANSIBLE_TEST_ORG_NAME }} \n\
grafana_cloud_api_key: ${{ secrets.ANSIBLE_TEST_CLOUD_API_KEY }} \n\
grafana_api_key: ${{ secrets.ANSIBLE_TEST_GRAFANA_API_KEY }} \n\
grafana_url: ${{ secrets.ANSIBLE_GRAFANA_URL }} \n\
test_stack_name: ${{ secrets.ANSIBLE_TEST_CI_STACK }}" > tests/integration/integration_config.yml
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
25 changes: 25 additions & 0 deletions .github/workflows/ansible-test-sanity.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
name: Ansible Sanity Test
on:

Check warning on line 3 in .github/workflows/ansible-test-sanity.yml

View workflow job for this annotation

GitHub Actions / Perform Linting

3:1 [truthy] truthy value should be one of [false, true]
workflow_call:
inputs:
ansible-core-versions:
required: false
default: '["stable-2.14"]'
type: string

jobs:
ansible-test-sanity:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
ansible-core-versions: ${{ fromJson(inputs.ansible-core-versions) }}

name: "sanity-${{ matrix.ansible-core-versions }}"
steps:
- name: "Perform sanity test with ansible-test"
uses: ansible-community/ansible-test-gh-action@release/v1
with:
ansible-core-version: ${{ matrix.ansible-core-versions }}
testing-type: sanity
94 changes: 43 additions & 51 deletions .github/workflows/full-integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,64 +6,56 @@
schedule:
- cron: '0 0 * * 0'
workflow_dispatch:
pull_request:
push:
branches:
- "main"
env:
NAMESPACE: grafana
COLLECTION_NAME: grafana

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
ansible-test-sanity:
uses: ./.github/workflows/ansible-test-sanity.yml
with:
ansible-core-versions: '["stable-2.14","stable-2.15","stable-2.16"]'

integration:
runs-on: ubuntu-20.04
name: ${{ matrix.ansible }}-py${{ matrix.python }}
strategy:
fail-fast: true
max-parallel: 1
matrix:
ansible:
- stable-2.11
- stable-2.12
- stable-2.13
- devel
python:
- '2.7'
- '3.5'
- '3.6'
- '3.7'
- '3.8'
- '3.9'
- '3.10'
exclude:
- ansible: stable-2.11
python: '3.10'
discover-ansible-tests:
runs-on: ubuntu-latest
outputs:
molecule-tests: ${{ steps.set-tests.outputs.ansible-test-molecule }}
integration-tests: ${{ steps.set-tests.outputs.ansible-test-integration }}

steps:
- name: Check out code
uses: actions/checkout@v2
with:
path: ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}
- name: Check out codebase
uses: actions/checkout@v3

- name: create integration_config
working-directory: ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}/tests/integration
- name: Discover tests
id: set-tests
run: |
cat <<EOF > integration_config.yml
stack_name: ${{ secrets.ANSIBLE_TEST_STACK_NAME }}
org_name: ${{ secrets.ANSIBLE_TEST_ORG_NAME }}
grafana_cloud_api_key: ${{ secrets.ANSIBLE_TEST_CLOUD_API_KEY }}
grafana_api_key: ${{ secrets.ANSIBLE_TEST_GRAFANA_API_KEY }}
test_stack_name: ${{ secrets.ANSIBLE_TEST_CI_STACK }}
EOF

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.10'

- name: Install ansible-base (${{ matrix.ansible }})
run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible }}.tar.gz --disable-pip-version-check

- name: Test Modules
run: ansible-test integration -v alert_contact_point alert_notification_policy cloud_api_key cloud_plugin cloud_stack dashboard datasource folder --color --retry-on-error --continue-on-error --diff --python ${{ matrix.python }} --coverage --docker
working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}

- name: Cooling Period
run: sleep 3m
echo ansible-test-molecule="[`for x in $(find tests/integration/targets -maxdepth 1 -mindepth 1 -type d -iname "molecule-*" -printf "%f\n");
do echo '{"test":\"'"${x}"'\","name":\"'"${x#*-}\"'"}'; done | tr '\n' ',' | sed '$s/,$//'`]" >> $GITHUB_OUTPUT
echo ansible-test-integration="[`for x in $(find tests/integration/targets -maxdepth 1 -mindepth 1 -type d -not -iname "molecule-*" -not -iname "*_cloud_stack" -printf "%f\n");

Check warning on line 42 in .github/workflows/full-integration-test.yml

View workflow job for this annotation

GitHub Actions / Perform Linting

42:151 [line-length] line too long (186 > 150 characters)
do echo '{"test":\"'"${x}"'\","name":\"'"${x}\"'"}'; done | tr '\n' ',' | sed '$s/,$//'`]" >> $GITHUB_OUTPUT

ansible-test-molecule:
uses: ./.github/workflows/ansible-test-integration.yml
needs: discover-ansible-tests
if: needs.discover-ansible-tests.outputs.molecule-tests != '[]'
with:
targets: ${{ needs.discover-ansible-tests.outputs.molecule-tests }}
ansible-core-versions: '["stable-2.14","stable-2.15","stable-2.16"]'

ansible-test-integration:
uses: ./.github/workflows/ansible-test-integration.yml
needs: discover-ansible-tests
if: needs.discover-ansible-tests.outputs.integration-tests != '[]'
secrets: inherit
with:
targets: ${{ needs.discover-ansible-tests.outputs.integration-tests }}
ansible-core-versions: '["stable-2.14","stable-2.15","stable-2.16"]'
target-python-versions: '["2.7","3.6","3.7","3.8","3.9","3.10","3.11"]'
98 changes: 0 additions & 98 deletions .github/workflows/modules-test.yml

This file was deleted.

90 changes: 0 additions & 90 deletions .github/workflows/roles-test.yml

This file was deleted.

3 changes: 3 additions & 0 deletions tests/integration/targets/alert_contact_point/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
dependencies:
- ../../create_cloud_stack
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
dependencies:
- ../../create_cloud_stack
3 changes: 3 additions & 0 deletions tests/integration/targets/cloud_api_key/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
dependencies:
- ../../create_cloud_stack
3 changes: 3 additions & 0 deletions tests/integration/targets/cloud_plugin/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
dependencies:
- ../../create_cloud_stack
3 changes: 3 additions & 0 deletions tests/integration/targets/dashboard/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
dependencies:
- ../../create_cloud_stack
3 changes: 3 additions & 0 deletions tests/integration/targets/datasource/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
dependencies:
- ../../create_cloud_stack
Loading
Loading